Skip to content

Commit

Permalink
reduce message by 20 to make room for context and prevent truncation …
Browse files Browse the repository at this point in the history
  • Loading branch information
Panometric committed Sep 27, 2023
1 parent 60097f0 commit 72722d7
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/load.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,11 @@ typedef struct {

/*** error reporting ***/

#define JSON_ERROR_CONTEXT_LENGTH 20
static void error_set(json_error_t *error, const lex_t *lex, enum json_error_code code,
const char *msg, ...) {
va_list ap;
char msg_text[JSON_ERROR_TEXT_LENGTH];
char msg_text[JSON_ERROR_TEXT_LENGTH-JSON_ERROR_CONTEXT_LENGTH];
char msg_with_context[JSON_ERROR_TEXT_LENGTH];

int line = -1, col = -1;
Expand All @@ -96,8 +97,8 @@ static void error_set(json_error_t *error, const lex_t *lex, enum json_error_cod
return;

va_start(ap, msg);
vsnprintf(msg_text, JSON_ERROR_TEXT_LENGTH, msg, ap);
msg_text[JSON_ERROR_TEXT_LENGTH - 1] = '\0';
vsnprintf(msg_text, JSON_ERROR_TEXT_LENGTH-JSON_ERROR_CONTEXT_LENGTH, msg, ap);
msg_text[JSON_ERROR_TEXT_LENGTH - (JSON_ERROR_CONTEXT_LENGTH+1)] = '\0';
va_end(ap);

if (lex) {
Expand Down

0 comments on commit 72722d7

Please sign in to comment.