You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fixes warnings for possible string truncation with strncpy()
All of these fixes handles strncpy(), and the compiler warning have been
silenced by checking the length before copying the string, we check with
'>=' which means that the string must be one smaller and therefore have
room for at least one NULL terminating character, if this fails the
function provides a error message and/or return.
Some of the buffer lengths had a '+ 1' appended, some of these have been
removed. I'm also using sizeof() operator, in case we later want to
change the buffer size.
Most of the previous solutions also checked for NULL terminated strings
but the compiler wasn't satisfied with it happening *after* the command
to strncpy().
if (context->progName[sizeof(context->progName) - 1] != '\0') {
1175
-
fprintf(stderr, "linuxcncrsh: 'set open' filename too long for context (got %lu bytes, max %lu)", (unsignedlong)strlen(pch), (unsignedlong)sizeof(context->progName));
1166
+
if (strlen(pch) >= sizeof(context->progName)) {
1167
+
fprintf(stderr, "linuxcncrsh: 'set open' filename too long for context (got %lu bytes, max %lu)",
0 commit comments