From 15e84fa7c3a83c097aee855cd39b066d8ede37a5 Mon Sep 17 00:00:00 2001 From: Paolo Stivanin Date: Tue, 16 Nov 2021 14:34:51 +0100 Subject: [PATCH] Small code optimizations --- CMakeLists.txt | 2 +- data/com.github.paolostivanin.OTPClient.appdata.xml | 9 +++++++++ src/add-common.c | 2 +- src/parse-data.c | 6 ++++-- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c0af049..cdabd6a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.5) -project(OTPClient VERSION "2.4.4" LANGUAGES "C") +project(OTPClient VERSION "2.4.7" LANGUAGES "C") configure_file("src/common/version.h.in" "version.h") include_directories(${PROJECT_BINARY_DIR}) diff --git a/data/com.github.paolostivanin.OTPClient.appdata.xml b/data/com.github.paolostivanin.OTPClient.appdata.xml index c3779b5..54c2d7a 100644 --- a/data/com.github.paolostivanin.OTPClient.appdata.xml +++ b/data/com.github.paolostivanin.OTPClient.appdata.xml @@ -83,6 +83,15 @@ It's also possible to import/export backups from/to andOTP and import backups fr + + +

OTPClient 2.4.7 implements some small code optimization

+
    +
  • do not use strlen in for loop
  • +
  • do not use strlen to check for empty string
  • +
+
+

OTPClient 2.4.6 fixes some small issues

diff --git a/src/add-common.c b/src/add-common.c index 1d8cf33..b81c846 100644 --- a/src/add-common.c +++ b/src/add-common.c @@ -40,7 +40,7 @@ check_params (GSList *otps) return g_strdup ("Label can not be empty, otp not imported"); } - if (strlen (otp->secret) == 0) { + if (otp->secret[0] == '\0') { return g_strdup ("Secret can not be empty, otp not imported"); } diff --git a/src/parse-data.c b/src/parse-data.c index 40cbbe5..c0c1570 100644 --- a/src/parse-data.c +++ b/src/parse-data.c @@ -124,7 +124,8 @@ is_input_valid (GtkWidget *dialog, static gboolean str_is_only_num_or_alpha (const gchar *string) { - for (gint i = 0; i < strlen (string); i++) { + size_t s_len = strlen (string); + for (gint i = 0; i < s_len; i++) { if (!g_ascii_isalnum (string[i])) { return FALSE; } @@ -136,7 +137,8 @@ str_is_only_num_or_alpha (const gchar *string) static gboolean str_is_only_num (const gchar *string) { - for (gint i = 0; i < strlen (string); i++) { + size_t s_len = strlen (string); + for (gint i = 0; i < s_len; i++) { if (!g_ascii_isdigit (string[i])) { return FALSE; }