Defensive programming: Difference between revisions

Content deleted Content added
Secure programming: sizeof does not work on arrays, it just returns the size in bytes of the array element 0
Tag: Reverted
Secure programming: ^Missed some
Tag: Reverted
Line 37:
strncpy(str, input, strlen(str));
 
// If strlen(input) >= sizeofstrlen(str) then strncpy won't null terminate.
// We counter this by always setting the last character in the buffer to NUL,
// effectively cropping the string to the maximum length we can handle.
// One can also decide to explicitly abort the program if strlen(input) is
// too long.
str[sizeofstrlen(str) - 1] = '\0';
 
// ...