Fix GCC warning for strncpy

This commit is contained in:
Jason Turner 2026-04-28 17:24:44 -06:00
parent 1b80804c4a
commit 6eb3481855
3 changed files with 3 additions and 6 deletions

View File

@ -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<std::ptrdiff_t>(len)) = '\0';
return d; // Return the new string
}

View File

@ -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
}

View File

@ -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<std::ptrdiff_t>(len)) = '\0';
return d; // Return the new string
}