* Fix error in error.c
* Fix error in load.c
length = strlen(source);
if(length < JSON_ERROR_SOURCE_LENGTH)
length = strlen(source);
if(length < JSON_ERROR_SOURCE_LENGTH)
- strncpy(error->source, source, length + 1);
+ strncpy(error->source, source, JSON_ERROR_SOURCE_LENGTH);
else {
size_t extra = length - JSON_ERROR_SOURCE_LENGTH + 4;
else {
size_t extra = length - JSON_ERROR_SOURCE_LENGTH + 4;
- strncpy(error->source, "...", 3);
+ memcpy(error->source, "...", 3);
strncpy(error->source + 3, source + extra, length - extra + 1);
}
}
strncpy(error->source + 3, source + extra, length - extra + 1);
}
}
{
va_list ap;
char msg_text[JSON_ERROR_TEXT_LENGTH];
{
va_list ap;
char msg_text[JSON_ERROR_TEXT_LENGTH];
- char msg_with_context[JSON_ERROR_TEXT_LENGTH];
+ char msg_with_context[JSON_ERROR_TEXT_LENGTH + 28];
int line = -1, col = -1;
size_t pos = 0;
int line = -1, col = -1;
size_t pos = 0;
if(saved_text && saved_text[0])
{
if(lex->saved_text.length <= 20) {
if(saved_text && saved_text[0])
{
if(lex->saved_text.length <= 20) {
- snprintf(msg_with_context, JSON_ERROR_TEXT_LENGTH,
+ snprintf(msg_with_context, JSON_ERROR_TEXT_LENGTH + 28,
"%s near '%s'", msg_text, saved_text);
msg_with_context[JSON_ERROR_TEXT_LENGTH - 1] = '\0';
result = msg_with_context;
"%s near '%s'", msg_text, saved_text);
msg_with_context[JSON_ERROR_TEXT_LENGTH - 1] = '\0';
result = msg_with_context;
result = msg_text;
}
else {
result = msg_text;
}
else {
- snprintf(msg_with_context, JSON_ERROR_TEXT_LENGTH,
+ snprintf(msg_with_context, JSON_ERROR_TEXT_LENGTH + 17,
"%s near end of file", msg_text);
msg_with_context[JSON_ERROR_TEXT_LENGTH - 1] = '\0';
result = msg_with_context;
"%s near end of file", msg_text);
msg_with_context[JSON_ERROR_TEXT_LENGTH - 1] = '\0';
result = msg_with_context;