@@ -109,14 +109,17 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
109109 int ret ;
110110
111111#define push_simple_value (func ) \
112- if(msgpack_unpack_callback(func)(user, &obj) < 0) { goto _failed; } \
112+ ret = msgpack_unpack_callback(func)(user, &obj); \
113+ if(ret < 0) { goto _failed; } \
113114 goto _push
114115#define push_fixed_value (func , arg ) \
115- if(msgpack_unpack_callback(func)(user, arg, &obj) < 0) { goto _failed; } \
116+ ret = msgpack_unpack_callback(func)(user, arg, &obj); \
117+ if(ret < 0) { goto _failed; } \
116118 goto _push
117119#define push_variable_value (func , base , pos , len ) \
118- if(msgpack_unpack_callback(func)(user, \
119- (const char*)base, (const char*)pos, len, &obj) < 0) { goto _failed; } \
120+ ret = msgpack_unpack_callback(func)(user, \
121+ (const char*)base, (const char*)pos, len, &obj); \
122+ if(ret < 0) { goto _failed; } \
120123 goto _push
121124
122125#define again_fixed_trail (_cs , trail_len ) \
@@ -130,33 +133,16 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
130133 goto _fixed_trail_again
131134
132135#define start_container (func , count_ , ct_ ) \
133- if(top >= MSGPACK_EMBED_STACK_SIZE) { goto _failed; } /* FIXME */ \
134- if (msgpack_unpack_callback (func )(user , count_ , & stack [top ].obj ) < 0 ) { goto _failed ; } \
136+ if(top >= MSGPACK_EMBED_STACK_SIZE) { \
137+ ret = MSGPACK_UNPACK_NOMEM_ERROR; \
138+ goto _failed; \
139+ } /* FIXME */ \
140+ ret = msgpack_unpack_callback (func )(user , count_ , & stack [top ].obj ); \
141+ if (ret < 0 ) { goto _failed ; } \
135142 if ((count_ ) == 0 ) { obj = stack [top ].obj ; goto _push ; } \
136143 stack [top ].ct = ct_ ; \
137144 stack [top ].count = count_ ; \
138145 ++ top ; \
139- /*printf("container %d count %d stack %d\n",stack[top].obj,count_,top);*/ \
140- /*printf("stack push %d\n", top);*/ \
141- /* FIXME \
142- if(top >= stack_size) { \
143- if(stack_size == MSGPACK_EMBED_STACK_SIZE) { \
144- size_t csize = sizeof(msgpack_unpack_struct(_stack)) * MSGPACK_EMBED_STACK_SIZE; \
145- size_t nsize = csize * 2; \
146- msgpack_unpack_struct(_stack)* tmp = (msgpack_unpack_struct(_stack)*)malloc(nsize); \
147- if(tmp == NULL) { goto _failed; } \
148- memcpy(tmp, ctx->stack, csize); \
149- ctx->stack = stack = tmp; \
150- ctx->stack_size = stack_size = MSGPACK_EMBED_STACK_SIZE * 2; \
151- } else { \
152- size_t nsize = sizeof(msgpack_unpack_struct(_stack)) * ctx->stack_size * 2; \
153- msgpack_unpack_struct(_stack)* tmp = (msgpack_unpack_struct(_stack)*)realloc(ctx->stack, nsize); \
154- if(tmp == NULL) { goto _failed; } \
155- ctx->stack = stack = tmp; \
156- ctx->stack_size = stack_size = stack_size * 2; \
157- } \
158- } \
159- */ \
160146 goto _header_again
161147
162148#define NEXT_CS (p ) \
@@ -231,6 +217,7 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
231217 case 0xdf : // map 32
232218 again_fixed_trail (NEXT_CS (p ), 2u << (((unsigned int )* p ) & 0x01 ));
233219 default :
220+ ret = MSGPACK_UNPACK_PARSE_ERROR ;
234221 goto _failed ;
235222 }
236223 SWITCH_RANGE (0xa0 , 0xbf ) // FixStr
@@ -241,6 +228,7 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
241228 start_container (_map , ((unsigned int )* p ) & 0x0f , MSGPACK_CT_MAP_KEY );
242229
243230 SWITCH_RANGE_DEFAULT
231+ ret = MSGPACK_UNPACK_PARSE_ERROR ;
244232 goto _failed ;
245233 SWITCH_RANGE_END
246234 // end MSGPACK_CS_HEADER
@@ -384,6 +372,7 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
384372 }
385373
386374 default :
375+ ret = MSGPACK_UNPACK_PARSE_ERROR ;
387376 goto _failed ;
388377 }
389378 }
@@ -393,7 +382,8 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
393382 c = & stack [top - 1 ];
394383 switch (c -> ct ) {
395384 case MSGPACK_CT_ARRAY_ITEM :
396- if (msgpack_unpack_callback (_array_item )(user , & c -> obj , obj ) < 0 ) { goto _failed ; }
385+ ret = msgpack_unpack_callback (_array_item )(user , & c -> obj , obj ); \
386+ if (ret < 0 ) { goto _failed ; }
397387 if (-- c -> count == 0 ) {
398388 obj = c -> obj ;
399389 -- top ;
@@ -406,7 +396,8 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
406396 c -> ct = MSGPACK_CT_MAP_VALUE ;
407397 goto _header_again ;
408398 case MSGPACK_CT_MAP_VALUE :
409- if (msgpack_unpack_callback (_map_item )(user , & c -> obj , c -> map_key , obj ) < 0 ) { goto _failed ; }
399+ ret = msgpack_unpack_callback (_map_item )(user , & c -> obj , c -> map_key , obj ); \
400+ if (ret < 0 ) { goto _failed ; }
410401 if (-- c -> count == 0 ) {
411402 obj = c -> obj ;
412403 -- top ;
@@ -417,6 +408,7 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
417408 goto _header_again ;
418409
419410 default :
411+ ret = MSGPACK_UNPACK_PARSE_ERROR ;
420412 goto _failed ;
421413 }
422414
@@ -436,7 +428,6 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
436428
437429 _failed :
438430 /*printf("** FAILED **\n"); */
439- ret = -1 ;
440431 goto _end ;
441432
442433 _out :
0 commit comments