Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void jsonp_error_set_source(json_error_t *error, const char *source) {

length = strlen(source);
if (length < JSON_ERROR_SOURCE_LENGTH)
strncpy(error->source, source, length + 1);
strncpy(error->source, source, JSON_ERROR_SOURCE_LENGTH);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing JSON_ERROR_SOURCE_LENGTH here seems unnecessary as the length has just been checked. We already know the length of source and have checked it will fit in the output buffer, therefore I think this is better:

         memcpy(error->source, source, length + 1);

else {
size_t extra = length - JSON_ERROR_SOURCE_LENGTH + 4;
memcpy(error->source, "...", 3);
Expand Down