tenseleyflow/gitswitch / 57c2bc7

Browse files

resolve warnings?

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
57c2bc76b0ae1f989fd1e470dabbcc19f628392a
Parents
2beb722
Tree
0270f02

7 changed files

StatusFile+-
M src/accounts.c 2 2
M src/config.c 4 4
M src/error.c 1 1
M src/git_ops.c 7 7
M src/toml_parser.h 0 23
M src/utils.c 5 5
M src/utils.h 0 6
src/accounts.cmodified
@@ -762,8 +762,8 @@ static int validate_gpg_key_availability(const char *gpg_key_id) {
762762
     }
763763
     
764764
     /* Try to find the key in the GPG keyring */
765
-    if (snprintf(command, sizeof(command), "gpg --list-secret-keys %s >/dev/null 2>&1", 
766
-                gpg_key_id) >= sizeof(command)) {
765
+    if (SAFE_SNPRINTF(command, sizeof(command), "gpg --list-secret-keys %s >/dev/null 2>&1", 
766
+                     gpg_key_id) != 0) {
767767
         log_error("GPG command too long");
768768
         return -1;
769769
     }
src/config.cmodified
@@ -171,7 +171,7 @@ int config_save(const gitswitch_ctx_t *ctx, const char *config_path) {
171171
     }
172172
     
173173
     /* Create temporary file path for atomic write */
174
-    if (snprintf(temp_path, sizeof(temp_path), "%s.tmp", config_path) >= sizeof(temp_path)) {
174
+    if (SAFE_SNPRINTF(temp_path, sizeof(temp_path), "%s.tmp", config_path) != 0) {
175175
         set_error(ERR_INVALID_ARGS, "Temporary file path too long");
176176
         return -1;
177177
     }
@@ -504,8 +504,8 @@ int config_backup(const char *config_path) {
504504
     }
505505
     
506506
     /* Create backup path */
507
-    if (snprintf(backup_path, sizeof(backup_path), "%s.backup.%s", 
508
-                config_path, timestamp) >= sizeof(backup_path)) {
507
+    if (SAFE_SNPRINTF(backup_path, sizeof(backup_path), "%s.backup.%s", 
508
+                     config_path, timestamp) != 0) {
509509
         set_error(ERR_INVALID_ARGS, "Backup path too long");
510510
         return -1;
511511
     }
@@ -773,7 +773,7 @@ static int save_accounts_to_toml(const gitswitch_ctx_t *ctx, toml_document_t *do
773773
         const account_t *account = &ctx->accounts[i];
774774
         
775775
         /* Create section name */
776
-        if (snprintf(section_name, sizeof(section_name), "accounts.%u", account->id) >= sizeof(section_name)) {
776
+        if (SAFE_SNPRINTF(section_name, sizeof(section_name), "accounts.%u", account->id) != 0) {
777777
             set_error(ERR_ACCOUNT_INVALID, "Account ID too large: %u", account->id);
778778
             return -1;
779779
         }
src/error.cmodified
@@ -180,7 +180,7 @@ void set_system_error_context(error_code_t code, const char *file, int line,
180180
                  "System error: %s (errno=%d)", strerror(saved_errno), saved_errno);
181181
         
182182
         /* Append system error to message if there's room */
183
-        if (msg_len < sizeof(g_last_error.message) - 50) {
183
+        if (msg_len < (int)(sizeof(g_last_error.message) - 50)) {
184184
             snprintf(g_last_error.message + msg_len, 
185185
                     sizeof(g_last_error.message) - msg_len,
186186
                     " (%s)", strerror(saved_errno));
src/git_ops.cmodified
@@ -340,8 +340,8 @@ int git_set_config_value(const char *key, const char *value, git_scope_t scope)
340340
     }
341341
     
342342
     /* Build git config command */
343
-    if (snprintf(command, sizeof(command), "config %s '%s' '%s'", 
344
-                 scope_flag, key, value) >= sizeof(command)) {
343
+    if (SAFE_SNPRINTF(command, sizeof(command), "config %s '%s' '%s'", 
344
+                     scope_flag, key, value) != 0) {
345345
         set_error(ERR_INVALID_ARGS, "Git config command too long");
346346
         return -1;
347347
     }
@@ -374,7 +374,7 @@ int git_get_config_value(const char *key, char *value, size_t value_size, git_sc
374374
     }
375375
     
376376
     /* Build git config command */
377
-    if (snprintf(command, sizeof(command), "config %s '%s'", scope_flag, key) >= sizeof(command)) {
377
+    if (SAFE_SNPRINTF(command, sizeof(command), "config %s '%s'", scope_flag, key) != 0) {
378378
         set_error(ERR_INVALID_ARGS, "Git config command too long");
379379
         return -1;
380380
     }
@@ -410,8 +410,8 @@ int git_unset_config_value(const char *key, git_scope_t scope) {
410410
     }
411411
     
412412
     /* Build git config unset command */
413
-    if (snprintf(command, sizeof(command), "config %s --unset '%s'", 
414
-                 scope_flag, key) >= sizeof(command)) {
413
+    if (SAFE_SNPRINTF(command, sizeof(command), "config %s --unset '%s'", 
414
+                     scope_flag, key) != 0) {
415415
         set_error(ERR_INVALID_ARGS, "Git config command too long");
416416
         return -1;
417417
     }
@@ -441,7 +441,7 @@ int git_list_config(git_scope_t scope, char *output, size_t output_size) {
441441
     }
442442
     
443443
     /* Build git config list command */
444
-    if (snprintf(command, sizeof(command), "config %s --list", scope_flag) >= sizeof(command)) {
444
+    if (SAFE_SNPRINTF(command, sizeof(command), "config %s --list", scope_flag) != 0) {
445445
         set_error(ERR_INVALID_ARGS, "Git config command too long");
446446
         return -1;
447447
     }
@@ -571,7 +571,7 @@ static int execute_git_command(const char *args, char *output, size_t output_siz
571571
     }
572572
     
573573
     /* Build full git command */
574
-    if (snprintf(command, sizeof(command), "git %s 2>&1", args) >= sizeof(command)) {
574
+    if (SAFE_SNPRINTF(command, sizeof(command), "git %s 2>&1", args) != 0) {
575575
         set_error(ERR_INVALID_ARGS, "Git command too long");
576576
         return -1;
577577
     }
src/toml_parser.hmodified
@@ -105,11 +105,6 @@ int toml_get_boolean(const toml_document_t *doc, const char *section,
105105
 int toml_set_string(toml_document_t *doc, const char *section, 
106106
                     const char *key, const char *value);
107107
 
108
-/**
109
- * Set integer value in TOML document
110
- */
111
-int toml_set_integer(toml_document_t *doc, const char *section, 
112
-                     const char *key, int value);
113108
 
114109
 /**
115110
  * Set boolean value in TOML document  
@@ -125,25 +120,12 @@ int toml_set_boolean(toml_document_t *doc, const char *section,
125120
  */
126121
 int toml_write_file(const toml_document_t *doc, const char *file_path);
127122
 
128
-/**
129
- * Generate TOML string from document
130
- */
131
-int toml_generate_string(const toml_document_t *doc, char *buffer, size_t buffer_size);
132123
 
133124
 /**
134125
  * Validate TOML document structure for our specific config schema
135126
  */
136127
 int toml_validate_gitswitch_schema(const toml_document_t *doc);
137128
 
138
-/**
139
- * Check if section exists in document
140
- */
141
-bool toml_has_section(const toml_document_t *doc, const char *section);
142
-
143
-/**
144
- * Check if key exists in section
145
- */
146
-bool toml_has_key(const toml_document_t *doc, const char *section, const char *key);
147129
 
148130
 /**
149131
  * Get list of all sections in document
@@ -151,11 +133,6 @@ bool toml_has_key(const toml_document_t *doc, const char *section, const char *k
151133
 int toml_get_sections(const toml_document_t *doc, char sections[][TOML_MAX_SECTION_LEN], 
152134
                       size_t max_sections, size_t *section_count);
153135
 
154
-/**
155
- * Get list of all keys in a section
156
- */
157
-int toml_get_keys(const toml_document_t *doc, const char *section, 
158
-                  char keys[][TOML_MAX_KEY_LEN], size_t max_keys, size_t *key_count);
159136
 
160137
 /**
161138
  * Security validation functions
src/utils.cmodified
@@ -223,7 +223,7 @@ int create_directory_recursive(const char *path, mode_t mode) {
223223
     char *p = NULL;
224224
     size_t len;
225225
     
226
-    if (snprintf(temp_path, sizeof(temp_path), "%s", path) >= sizeof(temp_path)) {
226
+    if (SAFE_SNPRINTF(temp_path, sizeof(temp_path), "%s", path) != 0) {
227227
         set_error(ERR_INVALID_ARGS, "Path too long");
228228
         return -1;
229229
     }
@@ -406,8 +406,8 @@ int backup_file(const char *file_path, const char *backup_suffix) {
406406
         return -1;
407407
     }
408408
     
409
-    if (snprintf(backup_path, sizeof(backup_path), "%s%s", 
410
-                file_path, backup_suffix) >= sizeof(backup_path)) {
409
+    if (SAFE_SNPRINTF(backup_path, sizeof(backup_path), "%s%s", 
410
+                     file_path, backup_suffix) != 0) {
411411
         set_error(ERR_INVALID_ARGS, "Backup path too long");
412412
         return -1;
413413
     }
@@ -520,8 +520,8 @@ bool command_exists(const char *command) {
520520
     
521521
     if (!command) return false;
522522
     
523
-    if (snprintf(test_command, sizeof(test_command), 
524
-                "command -v %s >/dev/null 2>&1", command) >= sizeof(test_command)) {
523
+    if (SAFE_SNPRINTF(test_command, sizeof(test_command), 
524
+                     "command -v %s >/dev/null 2>&1", command) != 0) {
525525
         return false;
526526
     }
527527
     
src/utils.hmodified
@@ -20,12 +20,6 @@
2020
 
2121
 /* Function prototypes */
2222
 
23
-/**
24
- * Safe printf utilities - fixes signed/unsigned comparison warnings
25
- */
26
-static inline bool safe_snprintf_check(int result, size_t buffer_size) {
27
-    return (result >= 0 && (size_t)result < buffer_size);
28
-}
2923
 
3024
 /**
3125
  * String utilities