From 50a07e5c04ad99dfcd03128c42f6c994dde2bbd2 Mon Sep 17 00:00:00 2001 From: Rot127 Date: Wed, 10 Jul 2024 05:34:26 -0500 Subject: [PATCH] Fix several logic issues --- suite/cstest/src/test_case.c | 4 ++-- utils.c | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/suite/cstest/src/test_case.c b/suite/cstest/src/test_case.c index 8c39ff8a6c..035149fb05 100644 --- a/suite/cstest/src/test_case.c +++ b/suite/cstest/src/test_case.c @@ -163,12 +163,12 @@ static bool compare_asm_text(const char *asm_text, const char *expected) { replace_negative(asm_copy, sizeof(asm_copy)); char expected_copy[MAX_ASM_TXT_MEM] = { 0 }; - strncpy(asm_copy, expected, sizeof(expected_copy)); + strncpy(expected_copy, expected, sizeof(expected_copy)); trim_str(expected_copy); replace_hex(expected_copy, sizeof(expected_copy)); replace_negative(expected_copy, sizeof(expected_copy)); - if (strcmp(asm_copy, expected) == 0) { + if (strcmp(asm_copy, expected_copy) == 0) { return true; } diff --git a/utils.c b/utils.c index 8b1a5d9438..798ba1608c 100644 --- a/utils.c +++ b/utils.c @@ -129,20 +129,20 @@ void append_to_str_lower(char *str, size_t str_size, const char *src) { /// @brief Appends the string @p src to the string @p str. @p src is put to lower case. /// @param str The string to append to. -/// @param str_size The length of @p str +/// @param str_buf_size Size of buffer @p str. /// @param src The string to append. -void append_to_str(char *str, size_t str_size, const char *src) { +void append_to_str(char *str, size_t str_buf_size, const char *src) { char *dest = strchr(str, '\0'); - if (dest - str >= str_size) { + if (dest - str >= str_buf_size) { assert("str_size does not match actual string length." && 0); return; } int i = dest - str; - for (int j = 0; (i < str_size) && (j < strlen(src)); ++i, ++j) { + for (int j = 0; (i < str_buf_size) && (j < strlen(src)); ++i, ++j) { str[i] = src[j]; } - str[i-1] = '\0'; + str[str_buf_size-1] = '\0'; } /// Returns the given byte sequence @bytes as a string of the