resolve warnings?
Authored by
mfwolffe <wolffemf@dukes.jmu.edu>
- SHA
57c2bc76b0ae1f989fd1e470dabbcc19f628392a- Parents
-
2beb722 - Tree
0270f02
57c2bc7
57c2bc76b0ae1f989fd1e470dabbcc19f628392a2beb722
0270f02| Status | File | + | - |
|---|---|---|---|
| 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) { | ||
| 762 | 762 | } |
| 763 | 763 | |
| 764 | 764 | /* 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) { | |
| 767 | 767 | log_error("GPG command too long"); |
| 768 | 768 | return -1; |
| 769 | 769 | } |
src/config.cmodified@@ -171,7 +171,7 @@ int config_save(const gitswitch_ctx_t *ctx, const char *config_path) { | ||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /* 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) { | |
| 175 | 175 | set_error(ERR_INVALID_ARGS, "Temporary file path too long"); |
| 176 | 176 | return -1; |
| 177 | 177 | } |
@@ -504,8 +504,8 @@ int config_backup(const char *config_path) { | ||
| 504 | 504 | } |
| 505 | 505 | |
| 506 | 506 | /* 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) { | |
| 509 | 509 | set_error(ERR_INVALID_ARGS, "Backup path too long"); |
| 510 | 510 | return -1; |
| 511 | 511 | } |
@@ -773,7 +773,7 @@ static int save_accounts_to_toml(const gitswitch_ctx_t *ctx, toml_document_t *do | ||
| 773 | 773 | const account_t *account = &ctx->accounts[i]; |
| 774 | 774 | |
| 775 | 775 | /* 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) { | |
| 777 | 777 | set_error(ERR_ACCOUNT_INVALID, "Account ID too large: %u", account->id); |
| 778 | 778 | return -1; |
| 779 | 779 | } |
src/error.cmodified@@ -180,7 +180,7 @@ void set_system_error_context(error_code_t code, const char *file, int line, | ||
| 180 | 180 | "System error: %s (errno=%d)", strerror(saved_errno), saved_errno); |
| 181 | 181 | |
| 182 | 182 | /* 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)) { | |
| 184 | 184 | snprintf(g_last_error.message + msg_len, |
| 185 | 185 | sizeof(g_last_error.message) - msg_len, |
| 186 | 186 | " (%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) | ||
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | /* 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) { | |
| 345 | 345 | set_error(ERR_INVALID_ARGS, "Git config command too long"); |
| 346 | 346 | return -1; |
| 347 | 347 | } |
@@ -374,7 +374,7 @@ int git_get_config_value(const char *key, char *value, size_t value_size, git_sc | ||
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | /* 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) { | |
| 378 | 378 | set_error(ERR_INVALID_ARGS, "Git config command too long"); |
| 379 | 379 | return -1; |
| 380 | 380 | } |
@@ -410,8 +410,8 @@ int git_unset_config_value(const char *key, git_scope_t scope) { | ||
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | /* 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) { | |
| 415 | 415 | set_error(ERR_INVALID_ARGS, "Git config command too long"); |
| 416 | 416 | return -1; |
| 417 | 417 | } |
@@ -441,7 +441,7 @@ int git_list_config(git_scope_t scope, char *output, size_t output_size) { | ||
| 441 | 441 | } |
| 442 | 442 | |
| 443 | 443 | /* 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) { | |
| 445 | 445 | set_error(ERR_INVALID_ARGS, "Git config command too long"); |
| 446 | 446 | return -1; |
| 447 | 447 | } |
@@ -571,7 +571,7 @@ static int execute_git_command(const char *args, char *output, size_t output_siz | ||
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | /* 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) { | |
| 575 | 575 | set_error(ERR_INVALID_ARGS, "Git command too long"); |
| 576 | 576 | return -1; |
| 577 | 577 | } |
src/toml_parser.hmodified@@ -105,11 +105,6 @@ int toml_get_boolean(const toml_document_t *doc, const char *section, | ||
| 105 | 105 | int toml_set_string(toml_document_t *doc, const char *section, |
| 106 | 106 | const char *key, const char *value); |
| 107 | 107 | |
| 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); | |
| 113 | 108 | |
| 114 | 109 | /** |
| 115 | 110 | * Set boolean value in TOML document |
@@ -125,25 +120,12 @@ int toml_set_boolean(toml_document_t *doc, const char *section, | ||
| 125 | 120 | */ |
| 126 | 121 | int toml_write_file(const toml_document_t *doc, const char *file_path); |
| 127 | 122 | |
| 128 | -/** | |
| 129 | - * Generate TOML string from document | |
| 130 | - */ | |
| 131 | -int toml_generate_string(const toml_document_t *doc, char *buffer, size_t buffer_size); | |
| 132 | 123 | |
| 133 | 124 | /** |
| 134 | 125 | * Validate TOML document structure for our specific config schema |
| 135 | 126 | */ |
| 136 | 127 | int toml_validate_gitswitch_schema(const toml_document_t *doc); |
| 137 | 128 | |
| 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); | |
| 147 | 129 | |
| 148 | 130 | /** |
| 149 | 131 | * 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 | ||
| 151 | 133 | int toml_get_sections(const toml_document_t *doc, char sections[][TOML_MAX_SECTION_LEN], |
| 152 | 134 | size_t max_sections, size_t *section_count); |
| 153 | 135 | |
| 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); | |
| 159 | 136 | |
| 160 | 137 | /** |
| 161 | 138 | * Security validation functions |
src/utils.cmodified@@ -223,7 +223,7 @@ int create_directory_recursive(const char *path, mode_t mode) { | ||
| 223 | 223 | char *p = NULL; |
| 224 | 224 | size_t len; |
| 225 | 225 | |
| 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) { | |
| 227 | 227 | set_error(ERR_INVALID_ARGS, "Path too long"); |
| 228 | 228 | return -1; |
| 229 | 229 | } |
@@ -406,8 +406,8 @@ int backup_file(const char *file_path, const char *backup_suffix) { | ||
| 406 | 406 | return -1; |
| 407 | 407 | } |
| 408 | 408 | |
| 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) { | |
| 411 | 411 | set_error(ERR_INVALID_ARGS, "Backup path too long"); |
| 412 | 412 | return -1; |
| 413 | 413 | } |
@@ -520,8 +520,8 @@ bool command_exists(const char *command) { | ||
| 520 | 520 | |
| 521 | 521 | if (!command) return false; |
| 522 | 522 | |
| 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) { | |
| 525 | 525 | return false; |
| 526 | 526 | } |
| 527 | 527 | |
src/utils.hmodified@@ -20,12 +20,6 @@ | ||
| 20 | 20 | |
| 21 | 21 | /* Function prototypes */ |
| 22 | 22 | |
| 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 | -} | |
| 29 | 23 | |
| 30 | 24 | /** |
| 31 | 25 | * String utilities |