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 }