From 6eb3481855bde7d097274f73f998ddf12d41aeae Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Tue, 28 Apr 2026 17:24:44 -0600 Subject: [PATCH] Fix GCC warning for strncpy --- samples/fun_call_performance.cpp | 3 +-- src/libfuzzer_client.cpp | 3 +-- src/main.cpp | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/samples/fun_call_performance.cpp b/samples/fun_call_performance.cpp index 1c11b6ba..0a992679 100644 --- a/samples/fun_call_performance.cpp +++ b/samples/fun_call_performance.cpp @@ -30,9 +30,8 @@ char *mystrdup(const char *s) { #ifdef CHAISCRIPT_MSVC strcpy_s(d, len + 1, s); // Copy the characters #else - strncpy(d, s, len); // Copy the characters + strncpy(d, s, len + 1); // Copy the characters #endif - *std::next(d, static_cast(len)) = '\0'; return d; // Return the new string } diff --git a/src/libfuzzer_client.cpp b/src/libfuzzer_client.cpp index 39ebe2f4..25726611 100644 --- a/src/libfuzzer_client.cpp +++ b/src/libfuzzer_client.cpp @@ -35,9 +35,8 @@ char *mystrdup(const char *s) { #ifdef CHAISCRIPT_MSVC strcpy_s(d, len + 1, s); // Copy the characters #else - strncpy(d, s, len); // Copy the characters + strncpy(d, s, len + 1); // Copy the characters #endif - d[len] = '\0'; return d; // Return the new string } diff --git a/src/main.cpp b/src/main.cpp index d8fdb062..52db4b1d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -35,9 +35,8 @@ char *mystrdup(const char *s) { #ifdef CHAISCRIPT_MSVC strcpy_s(d, len + 1, s); // Copy the characters #else - strncpy(d, s, len); // Copy the characters + strncpy(d, s, len + 1); // Copy the characters #endif - *std::next(d, static_cast(len)) = '\0'; return d; // Return the new string }