From 76fd1576e296bd9f93309b2a6e16a3268ad9b8c8 Mon Sep 17 00:00:00 2001 From: Tom Huang Date: Fri, 19 Jul 2024 19:53:05 -0700 Subject: [PATCH] fix: remove strncpy output truncated before terminating nul errors # [footer] # ////////////////////////////////////////////////////////////////////////////// # [title.type] # Must be one of the following: # - fix: Commits that fix bugs # - feat: Commits that add new features # - refactor: Commits that change existing code without changing any behavior # - perf: Special refactor commits that improve performance # - style: Commits that do not affect meaning (white-space, formatting, etc.) # - test: Commits that add tests or fixing existing tests # - docs: Commits that affect documentation only # - build: Commits that change build components (scripts, CI pipeline, etc.) # - chore: Miscellaneous commits (modifying .gitignore, etc.) # - tag: Commits for adding tags # # [title.scope] # The scope should be the name of the npm package affected. The following is # the list of supported scopes: # - xa: XAgent (default) # - usi: Unified Storage Interface # - uls: Unified Log System # # [title.summary] # Use the summary field to provide a succinct description of the change: # - Use the imperative, present tense: "change" not "changed" nor "changes" # - Don't capitalize the first letter # - No period (.) at the end # # [body] # Just as in the summary, use the imperative, present tense: "fix" not "fixed" # nor "fixes". # # Explain the motivation for the change in the commit message body. This commit # message should explain why you are making the change. You can include a # comparison of the previous behavior with the new behavior in order to # illustrate the impact of the change. # # [footer] # The footer can contain information about breaking changes and deprecations # and is also the place to reference GitHub issues, JIRA tickets, and other PRs # that this commit closes or is related to. For example: # # Resolves XCAGENT-100 # Resolves XCAGENT-100, SEAL-1500, XCAGENT-512 # # BREAKING CHANGE: # # # # # Resolves # # DEPRECATED: # # # # # Resolves # --- tests/testarghashtable.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tests/testarghashtable.c b/tests/testarghashtable.c index 36e4a7d..256face 100644 --- a/tests/testarghashtable.c +++ b/tests/testarghashtable.c @@ -75,12 +75,12 @@ void test_arghashtable_basic_002(CuTest* tc) { char* key_1 = "k1"; char* k_1 = (char*)malloc(strlen(key_1) + 1); memset(k_1, 0, strlen(key_1) + 1); - strncpy(k_1, key_1, strlen(key_1)); + memcpy(k_1, key_1, strlen(key_1)); char* value_1 = "v1"; char* v_1 = (char*)malloc(strlen(value_1) + 1); memset(v_1, 0, strlen(value_1) + 1); - strncpy(v_1, value_1, strlen(value_1)); + memcpy(v_1, value_1, strlen(value_1)); arg_hashtable_insert(h, k_1, v_1); CuAssertIntEquals(tc, 1, arg_hashtable_count(h)); @@ -104,12 +104,12 @@ void test_arghashtable_basic_003(CuTest* tc) { char* key_1 = "k1"; char* k_1 = (char*)malloc(strlen(key_1) + 1); memset(k_1, 0, strlen(key_1) + 1); - strncpy(k_1, key_1, strlen(key_1)); + memcpy(k_1, key_1, strlen(key_1)); char* value_1 = "v1"; char* v_1 = (char*)malloc(strlen(value_1) + 1); memset(v_1, 0, strlen(value_1) + 1); - strncpy(v_1, value_1, strlen(value_1)); + memcpy(v_1, value_1, strlen(value_1)); arg_hashtable_insert(h, k_1, v_1); CuAssertIntEquals(tc, 1, arg_hashtable_count(h)); @@ -117,12 +117,12 @@ void test_arghashtable_basic_003(CuTest* tc) { char* key_2 = "k2"; char* k_2 = (char*)malloc(strlen(key_2) + 1); memset(k_2, 0, strlen(key_2) + 1); - strncpy(k_2, key_2, strlen(key_2)); + memcpy(k_2, key_2, strlen(key_2)); char* value_2 = "v2"; char* v_2 = (char*)malloc(strlen(value_2) + 1); memset(v_2, 0, strlen(value_2) + 1); - strncpy(v_2, value_2, strlen(value_2)); + memcpy(v_2, value_2, strlen(value_2)); arg_hashtable_insert(h, k_2, v_2); CuAssertIntEquals(tc, 2, arg_hashtable_count(h)); @@ -148,12 +148,12 @@ void test_arghashtable_basic_004(CuTest* tc) { char* key_1 = "k1"; char* k_1 = (char*)malloc(strlen(key_1) + 1); memset(k_1, 0, strlen(key_1) + 1); - strncpy(k_1, key_1, strlen(key_1)); + memcpy(k_1, key_1, strlen(key_1)); char* value_1 = "v1"; char* v_1 = (char*)malloc(strlen(value_1) + 1); memset(v_1, 0, strlen(value_1) + 1); - strncpy(v_1, value_1, strlen(value_1)); + memcpy(v_1, value_1, strlen(value_1)); arg_hashtable_insert(h, k_1, v_1); CuAssertTrue(tc, h != 0); @@ -176,12 +176,12 @@ void test_arghashtable_basic_005(CuTest* tc) { char* key_1 = "k1"; char* k_1 = (char*)malloc(strlen(key_1) + 1); memset(k_1, 0, strlen(key_1) + 1); - strncpy(k_1, key_1, strlen(key_1)); + memcpy(k_1, key_1, strlen(key_1)); char* value_1 = "v1"; char* v_1 = (char*)malloc(strlen(value_1) + 1); memset(v_1, 0, strlen(value_1) + 1); - strncpy(v_1, value_1, strlen(value_1)); + memcpy(v_1, value_1, strlen(value_1)); arg_hashtable_insert(h, k_1, v_1); CuAssertTrue(tc, h != 0); @@ -201,12 +201,12 @@ void test_arghashtable_basic_006(CuTest* tc) { char* key_1 = "k1"; char* k_1 = (char*)malloc(strlen(key_1) + 1); memset(k_1, 0, strlen(key_1) + 1); - strncpy(k_1, key_1, strlen(key_1)); + memcpy(k_1, key_1, strlen(key_1)); char* value_1 = "v1"; char* v_1 = (char*)malloc(strlen(value_1) + 1); memset(v_1, 0, strlen(value_1) + 1); - strncpy(v_1, value_1, strlen(value_1)); + memcpy(v_1, value_1, strlen(value_1)); arg_hashtable_insert(h, k_1, v_1); CuAssertTrue(tc, arg_hashtable_count(h) == 1); @@ -225,12 +225,12 @@ void test_arghashtable_basic_007(CuTest* tc) { char* key_1 = "k1"; char* k_1 = (char*)malloc(strlen(key_1) + 1); memset(k_1, 0, strlen(key_1) + 1); - strncpy(k_1, key_1, strlen(key_1)); + memcpy(k_1, key_1, strlen(key_1)); char* value_1 = "v1"; char* v_1 = (char*)malloc(strlen(value_1) + 1); memset(v_1, 0, strlen(value_1) + 1); - strncpy(v_1, value_1, strlen(value_1)); + memcpy(v_1, value_1, strlen(value_1)); arg_hashtable_insert(h, k_1, v_1); CuAssertIntEquals(tc, 1, arg_hashtable_count(h)); @@ -238,12 +238,12 @@ void test_arghashtable_basic_007(CuTest* tc) { char* key_2 = "k2"; char* k_2 = (char*)malloc(strlen(key_2) + 1); memset(k_2, 0, strlen(key_2) + 1); - strncpy(k_2, key_2, strlen(key_2)); + memcpy(k_2, key_2, strlen(key_2)); char* value_2 = "v2"; char* v_2 = (char*)malloc(strlen(value_2) + 1); memset(v_2, 0, strlen(value_2) + 1); - strncpy(v_2, value_2, strlen(value_2)); + memcpy(v_2, value_2, strlen(value_2)); arg_hashtable_insert(h, k_2, v_2); CuAssertIntEquals(tc, 2, arg_hashtable_count(h));