Skip to content

Commit

Permalink
#341 Fixed excess elements testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed Sep 23, 2015
1 parent 7479818 commit 498167a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion packages/corto/lang/src/cx_string_deser.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ static cx_string cx_string_deserParse(cx_string str, struct cx_string_deserIndex
cx_char ch;
cx_char *ptr, *bptr, *nonWs;
cx_char buffer[CX_STRING_DESER_TOKEN_MAX];
cx_bool proceed;
cx_bool proceed, excess;
struct cx_string_deserIndexInfo* memberInfo;

CX_UNUSED(info);
Expand All @@ -431,6 +431,7 @@ static cx_string cx_string_deserParse(cx_string str, struct cx_string_deserIndex
bptr = buffer;
nonWs = bptr;
proceed = TRUE;
excess = FALSE;
memberInfo = NULL;

if (info) {
Expand All @@ -443,6 +444,7 @@ static cx_string cx_string_deserParse(cx_string str, struct cx_string_deserIndex
while(ptr && (ch = *ptr) && proceed) {
switch(ch) {
case '=': /* Explicit member assignment */
excess = FALSE;
if (buffer == bptr) {
cx_seterr("missing member identifier");
goto error;
Expand Down Expand Up @@ -542,6 +544,9 @@ static cx_string cx_string_deserParse(cx_string str, struct cx_string_deserIndex
* once in the index. */
if (memberInfo->m) {
memberInfo = cx_string_deserIndexNext(data);
if (!memberInfo) {
excess = TRUE;
}
}
data->current++;
break;
Expand All @@ -565,6 +570,11 @@ static cx_string cx_string_deserParse(cx_string str, struct cx_string_deserIndex
}
}

if (excess) {
cx_seterr("excess elements in string");
goto error;
}

return ptr;
error:
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion packages/corto/lang/test/src/test_StringDeserializer.c
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ cx_void _test_StringDeserializer_tc_errExcessElements(test_StringDeserializer th
test_assert(o == NULL);
test_assert(ret != 0);
test_assert((err = cx_lasterr()) != NULL);
test_assert(!strcmp(err, "excess elements"));
test_assert(!strcmp(err, "excess elements in string"));

/* $end */
}
Expand Down

0 comments on commit 498167a

Please sign in to comment.