"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "jv_parse.c" between
jq-1.5.tar.gz and jq-1.6.tar.gz

About: jq is a lightweight and flexible command-line JSON processor.

jv_parse.c  (jq-1.5):jv_parse.c  (jq-1.6)
skipping to change at line 13 skipping to change at line 13
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include "jv.h" #include "jv.h"
#include "jv_dtoa.h" #include "jv_dtoa.h"
#include "jv_unicode.h" #include "jv_unicode.h"
#include "jv_alloc.h" #include "jv_alloc.h"
#include "jv_dtoa.h" #include "jv_dtoa.h"
typedef const char* presult; typedef const char* presult;
#ifndef MAX_PARSING_DEPTH
#define MAX_PARSING_DEPTH (256)
#endif
#define TRY(x) do {presult msg__ = (x); if (msg__) return msg__; } while(0) #define TRY(x) do {presult msg__ = (x); if (msg__) return msg__; } while(0)
#ifdef __GNUC__ #ifdef __GNUC__
#define pfunc __attribute__((warn_unused_result)) presult #define pfunc __attribute__((warn_unused_result)) presult
#else #else
#define pfunc presult #define pfunc presult
#endif #endif
enum last_seen { enum last_seen {
JV_LAST_NONE = 0, JV_LAST_NONE = 0,
JV_LAST_OPEN_ARRAY = '[', JV_LAST_OPEN_ARRAY = '[',
skipping to change at line 149 skipping to change at line 153
p->stacklen = p->stacklen * 2 + 10; p->stacklen = p->stacklen * 2 + 10;
p->stack = jv_mem_realloc(p->stack, p->stacklen * sizeof(jv)); p->stack = jv_mem_realloc(p->stack, p->stacklen * sizeof(jv));
} }
assert(p->stackpos < p->stacklen); assert(p->stackpos < p->stacklen);
p->stack[p->stackpos++] = v; p->stack[p->stackpos++] = v;
} }
static pfunc parse_token(struct jv_parser* p, char ch) { static pfunc parse_token(struct jv_parser* p, char ch) {
switch (ch) { switch (ch) {
case '[': case '[':
if (p->stackpos >= MAX_PARSING_DEPTH) return "Exceeds depth limit for parsin g";
if (jv_is_valid(p->next)) return "Expected separator between values"; if (jv_is_valid(p->next)) return "Expected separator between values";
push(p, jv_array()); push(p, jv_array());
break; break;
case '{': case '{':
if (p->stackpos >= MAX_PARSING_DEPTH) return "Exceeds depth limit for parsin g";
if (jv_is_valid(p->next)) return "Expected separator between values"; if (jv_is_valid(p->next)) return "Expected separator between values";
push(p, jv_object()); push(p, jv_object());
break; break;
case ':': case ':':
if (!jv_is_valid(p->next)) if (!jv_is_valid(p->next))
return "Expected string key before ':'"; return "Expected string key before ':'";
if (p->stackpos == 0 || jv_get_kind(p->stack[p->stackpos-1]) != JV_KIND_OBJE CT) if (p->stackpos == 0 || jv_get_kind(p->stack[p->stackpos-1]) != JV_KIND_OBJE CT)
return "':' not as part of an object"; return "':' not as part of an object";
if (jv_get_kind(p->next) != JV_KIND_STRING) if (jv_get_kind(p->next) != JV_KIND_STRING)
skipping to change at line 385 skipping to change at line 391
p->last_seen = JV_LAST_NONE; p->last_seen = JV_LAST_NONE;
else else
p->last_seen = JV_LAST_VALUE; p->last_seen = JV_LAST_VALUE;
break; break;
} }
return 0; return 0;
} }
static void tokenadd(struct jv_parser* p, char c) { static void tokenadd(struct jv_parser* p, char c) {
assert(p->tokenpos <= p->tokenlen); assert(p->tokenpos <= p->tokenlen);
if (p->tokenpos == p->tokenlen) { if (p->tokenpos >= (p->tokenlen - 1)) {
p->tokenlen = p->tokenlen*2 + 256; p->tokenlen = p->tokenlen*2 + 256;
p->tokenbuf = jv_mem_realloc(p->tokenbuf, p->tokenlen); p->tokenbuf = jv_mem_realloc(p->tokenbuf, p->tokenlen);
} }
assert(p->tokenpos < p->tokenlen); assert(p->tokenpos < p->tokenlen);
p->tokenbuf[p->tokenpos++] = c; p->tokenbuf[p->tokenpos++] = c;
} }
static int unhex4(char* hex) { static int unhex4(char* hex) {
int r = 0; int r = 0;
for (int i=0; i<4; i++) { for (int i=0; i<4; i++) {
skipping to change at line 487 skipping to change at line 493
case 'n': pattern = "null"; plen = 4; v = jv_null(); break; case 'n': pattern = "null"; plen = 4; v = jv_null(); break;
} }
if (pattern) { if (pattern) {
if (p->tokenpos != plen) return "Invalid literal"; if (p->tokenpos != plen) return "Invalid literal";
for (int i=0; i<plen; i++) for (int i=0; i<plen; i++)
if (p->tokenbuf[i] != pattern[i]) if (p->tokenbuf[i] != pattern[i])
return "Invalid literal"; return "Invalid literal";
TRY(value(p, v)); TRY(value(p, v));
} else { } else {
// FIXME: better parser // FIXME: better parser
p->tokenbuf[p->tokenpos] = 0; // FIXME: invalid p->tokenbuf[p->tokenpos] = 0;
char* end = 0; char* end = 0;
double d = jvp_strtod(&p->dtoa, p->tokenbuf, &end); double d = jvp_strtod(&p->dtoa, p->tokenbuf, &end);
if (end == 0 || *end != 0) if (end == 0 || *end != 0)
return "Invalid numeric literal"; return "Invalid numeric literal";
TRY(value(p, jv_number(d))); TRY(value(p, jv_number(d)));
} }
p->tokenpos = 0; p->tokenpos = 0;
return 0; return 0;
} }
 End of changes. 5 change blocks. 
2 lines changed or deleted 8 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)