This commit is contained in:
Luke Street 2018-05-14 23:10:18 +00:00 committed by GitHub
commit 9ec75d29c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 30 deletions

View file

@ -67,14 +67,6 @@ static char* find_chars_or_comment(const char* s, const char* chars)
return (char*)s;
}
/* Version of strncpy that ensures dest (size bytes) is null-terminated. */
static char* strncpy0(char* dest, const char* src, size_t size)
{
strncpy(dest, src, size);
dest[size - 1] = '\0';
return dest;
}
/* See documentation in header file. */
int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
void* user)
@ -164,7 +156,7 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
end = find_chars_or_comment(start + 1, "]");
if (*end == ']') {
*end = '\0';
strncpy0(section, start + 1, sizeof(section));
strlcpy(section, start + 1, sizeof(section));
*prev_name = '\0';
}
else if (!error) {
@ -188,7 +180,7 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
rstrip(value);
/* Valid name[=:]value pair found, call handler */
strncpy0(prev_name, name, sizeof(prev_name));
strlcpy(prev_name, name, sizeof(prev_name));
if (!HANDLER(user, section, name, value) && !error)
error = lineno;
}

View file

@ -67,14 +67,6 @@ static char* find_chars_or_comment(const char* s, const char* chars)
return (char*)s;
}
/* Version of strncpy that ensures dest (size bytes) is null-terminated. */
static char* strncpy0(char* dest, const char* src, size_t size)
{
strncpy(dest, src, size);
dest[size - 1] = '\0';
return dest;
}
/* See documentation in header file. */
int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
void* user)
@ -164,7 +156,7 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
end = find_chars_or_comment(start + 1, "]");
if (*end == ']') {
*end = '\0';
strncpy0(section, start + 1, sizeof(section));
strlcpy(section, start + 1, sizeof(section));
*prev_name = '\0';
}
else if (!error) {
@ -188,7 +180,7 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
rstrip(value);
/* Valid name[=:]value pair found, call handler */
strncpy0(prev_name, name, sizeof(prev_name));
strlcpy(prev_name, name, sizeof(prev_name));
if (!HANDLER(user, section, name, value) && !error)
error = lineno;
}

View file

@ -67,14 +67,6 @@ static char* find_chars_or_comment(const char* s, const char* chars)
return (char*)s;
}
/* Version of strncpy that ensures dest (size bytes) is null-terminated. */
static char* strncpy0(char* dest, const char* src, size_t size)
{
strncpy(dest, src, size);
dest[size - 1] = '\0';
return dest;
}
/* See documentation in header file. */
int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
void* user)
@ -164,7 +156,7 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
end = find_chars_or_comment(start + 1, "]");
if (*end == ']') {
*end = '\0';
strncpy0(section, start + 1, sizeof(section));
strlcpy(section, start + 1, sizeof(section));
*prev_name = '\0';
}
else if (!error) {
@ -188,7 +180,7 @@ int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
rstrip(value);
/* Valid name[=:]value pair found, call handler */
strncpy0(prev_name, name, sizeof(prev_name));
strlcpy(prev_name, name, sizeof(prev_name));
if (!HANDLER(user, section, name, value) && !error)
error = lineno;
}