int json_dump(const json_t *json, const char *path, uint32_t flags)
{
+ int result;
+
FILE *output = fopen(path, "w");
if(!output)
return -1;
- return json_dumpf(json, output, flags);
+ result = json_dumpf(json, output, flags);
+
+ fclose(output);
+ return result;
}
char *json_dumps(const json_t *json, uint32_t flags)
}
}
- return (char)stream->buffer[stream->buffer_pos++];
+ return stream->buffer[stream->buffer_pos++];
out:
error_set(error, NULL, "unable to decode byte 0x%x at position %d",
(unsigned char)c, stream->stream_pos);
+
+ stream->buffer[0] = EOF;
+ stream->buffer[1] = '\0';
+ stream->buffer_pos = 1;
+
return EOF;
}
{
assert(stream->buffer_pos > 0);
stream->buffer_pos--;
- assert(stream->buffer[stream->buffer_pos] == (unsigned char)c);
+ assert(stream->buffer[stream->buffer_pos] == c);
}
static void lex_unget_unsave(lex_t *lex, char c)
{
char d;
- if(c != EOF)
- stream_unget(&lex->stream, c);
+ stream_unget(&lex->stream, c);
d = strbuffer_pop(&lex->saved_text);
assert(c == d);
}
char *t;
int i;
+ lex->value.string = NULL;
lex->token = TOKEN_INVALID;
/* skip the " */
}
*t = '\0';
lex->token = TOKEN_STRING;
+ return;
out:
- return;
+ free(lex->value.string);
}
static void lex_scan_number(lex_t *lex, char c, json_error_t *error)
{
if(lex->token == TOKEN_STRING)
free(lex->value.string);
+ strbuffer_close(&lex->saved_text);
}
{
char c;
string_data_t *stream = (string_data_t *)data;
- c = stream->data[stream->pos++];
+ c = stream->data[stream->pos];
if(c == '\0')
return EOF;
else
+ {
+ stream->pos++;
return c;
+ }
}
static int string_eof(void *data)