#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
-#include <unistd.h>
#include <assert.h>
#include <jansson.h>
c = stream->buffer[0];
- if(c < 0 && c != EOF)
+ if((unsigned char)c >= 0x80 && c != (char)EOF)
{
/* multi-byte UTF-8 sequence */
int i, count;
c = lex_get_save(lex, error);
while(c != '"') {
- if(c == EOF) {
+ if(c == (char)EOF) {
lex_unget_unsave(lex, c);
if(lex_eof(lex))
error_set(error, lex, "premature end of input");
goto out;
}
- else if(0 <= c && c <= 0x1F) {
+ else if((unsigned char)c <= 0x1F) {
/* control character */
lex_unget_unsave(lex, c);
if(c == '\n')
if(0xDC00 <= value2 && value2 <= 0xDFFF) {
/* valid second surrogate */
- value = ((value - 0xD800) << 10) +
- (value2 - 0xDC00) +
- 0x10000;
+ value =
+ ((value - 0xD800) << 10) +
+ (value2 - 0xDC00) +
+ 0x10000;
}
else {
/* invalid second surrogate */
strbuffer_clear(&lex->saved_text);
if(lex->token == TOKEN_STRING) {
- free(lex->value.string);
- lex->value.string = NULL;
+ free(lex->value.string);
+ lex->value.string = NULL;
}
c = lex_get(lex, error);
c = lex_get(lex, error);
}
- if(c == EOF) {
+ if(c == (char)EOF) {
if(lex_eof(lex))
lex->token = TOKEN_EOF;
else
return lex->token;
}
+static char *lex_steal_string(lex_t *lex)
+{
+ char *result = NULL;
+ if(lex->token == TOKEN_STRING)
+ {
+ result = lex->value.string;
+ lex->value.string = NULL;
+ }
+ return result;
+}
+
static int lex_init(lex_t *lex, get_func get, eof_func eof, void *data)
{
stream_init(&lex->stream, get, eof, data);
goto error;
}
- key = strdup(lex->value.string);
+ key = lex_steal_string(lex);
if(!key)
return NULL;
break;
case '{':
- json = parse_object(lex, error);
+ json = parse_object(lex, error);
break;
case '[':