X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=src%2Ferror.c;h=a7c8cbb9e54078e63d9b4341fc69622096821c82;hb=c30e92603c0780040fa3a974d6234dedeb5cd266;hp=d113b8facee5fa9f5b52bc146a8236533d9f6dc2;hpb=50dc64a7af3664ca55ac74b393459a6d54e6958f;p=jansson.git diff --git a/src/error.c b/src/error.c index d113b8f..a7c8cbb 100644 --- a/src/error.c +++ b/src/error.c @@ -5,21 +5,31 @@ void jsonp_error_init(json_error_t *error, const char *source) { if(error) { - size_t length; - error->text[0] = '\0'; error->line = -1; error->column = -1; error->position = 0; + if(source) + jsonp_error_set_source(error, source); + else + error->source[0] = '\0'; + } +} + +void jsonp_error_set_source(json_error_t *error, const char *source) +{ + size_t length; + + if(!error || !source) + return; - length = strlen(source); - if(length < JSON_ERROR_SOURCE_LENGTH) - strcpy(error->source, source); - else { - size_t extra = length - JSON_ERROR_SOURCE_LENGTH + 4; - strcpy(error->source, "..."); - strcpy(error->source + 3, source + extra); - } + length = strlen(source); + if(length < JSON_ERROR_SOURCE_LENGTH) + strcpy(error->source, source); + else { + size_t extra = length - JSON_ERROR_SOURCE_LENGTH + 4; + strcpy(error->source, "..."); + strcpy(error->source + 3, source + extra); } }