File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -52,7 +52,7 @@ static char* lskip(const char* s)
5252}
5353
5454/* Return pointer to first char (of chars) or inline comment in given string,
55- or pointer to null at end of string if neither found. Inline comment must
55+ or pointer to NUL at end of string if neither found. Inline comment must
5656 be prefixed by a whitespace character to register as a comment. */
5757static char * find_chars_or_comment (const char * s , const char * chars )
5858{
@@ -71,12 +71,15 @@ static char* find_chars_or_comment(const char* s, const char* chars)
7171 return (char * )s ;
7272}
7373
74- /* Version of strncpy that ensures dest (size bytes) is null-terminated. */
74+ /* Similar to strncpy, but ensures dest (size bytes) is
75+ NUL-terminated, and doesn't pad with NULs. */
7576static char * strncpy0 (char * dest , const char * src , size_t size )
7677{
77- /* Use memcpy instead of strncpy to avoid gcc warnings (see issue #91) */
78- memcpy (dest , src , size - 1 );
79- dest [size - 1 ] = '\0' ;
78+ /* Could use strncpy internally, but it causes gcc warnings (see issue #91) */
79+ size_t i ;
80+ for (i = 0 ; i < size - 1 && src [i ]; i ++ )
81+ dest [i ] = src [i ];
82+ dest [i ] = '\0' ;
8083 return dest ;
8184}
8285
You can’t perform that action at this time.
0 commit comments