mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-05-28 15:14:11 +02:00
Fixed C unpack return code.
This commit is contained in:
parent
2674e34769
commit
9a113bb0ca
@ -109,14 +109,17 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
|
||||
int ret;
|
||||
|
||||
#define push_simple_value(func) \
|
||||
if(msgpack_unpack_callback(func)(user, &obj) < 0) { goto _failed; } \
|
||||
ret = msgpack_unpack_callback(func)(user, &obj); \
|
||||
if(ret < 0) { goto _failed; } \
|
||||
goto _push
|
||||
#define push_fixed_value(func, arg) \
|
||||
if(msgpack_unpack_callback(func)(user, arg, &obj) < 0) { goto _failed; } \
|
||||
ret = msgpack_unpack_callback(func)(user, arg, &obj); \
|
||||
if(ret < 0) { goto _failed; } \
|
||||
goto _push
|
||||
#define push_variable_value(func, base, pos, len) \
|
||||
if(msgpack_unpack_callback(func)(user, \
|
||||
(const char*)base, (const char*)pos, len, &obj) < 0) { goto _failed; } \
|
||||
ret = msgpack_unpack_callback(func)(user, \
|
||||
(const char*)base, (const char*)pos, len, &obj); \
|
||||
if(ret < 0) { goto _failed; } \
|
||||
goto _push
|
||||
|
||||
#define again_fixed_trail(_cs, trail_len) \
|
||||
@ -130,33 +133,16 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
|
||||
goto _fixed_trail_again
|
||||
|
||||
#define start_container(func, count_, ct_) \
|
||||
if(top >= MSGPACK_EMBED_STACK_SIZE) { goto _failed; } /* FIXME */ \
|
||||
if(msgpack_unpack_callback(func)(user, count_, &stack[top].obj) < 0) { goto _failed; } \
|
||||
if(top >= MSGPACK_EMBED_STACK_SIZE) { \
|
||||
ret = MSGPACK_UNPACK_NOMEM_ERROR; \
|
||||
goto _failed; \
|
||||
} /* FIXME */ \
|
||||
ret = msgpack_unpack_callback(func)(user, count_, &stack[top].obj); \
|
||||
if(ret < 0) { goto _failed; } \
|
||||
if((count_) == 0) { obj = stack[top].obj; goto _push; } \
|
||||
stack[top].ct = ct_; \
|
||||
stack[top].count = count_; \
|
||||
++top; \
|
||||
/*printf("container %d count %d stack %d\n",stack[top].obj,count_,top);*/ \
|
||||
/*printf("stack push %d\n", top);*/ \
|
||||
/* FIXME \
|
||||
if(top >= stack_size) { \
|
||||
if(stack_size == MSGPACK_EMBED_STACK_SIZE) { \
|
||||
size_t csize = sizeof(msgpack_unpack_struct(_stack)) * MSGPACK_EMBED_STACK_SIZE; \
|
||||
size_t nsize = csize * 2; \
|
||||
msgpack_unpack_struct(_stack)* tmp = (msgpack_unpack_struct(_stack)*)malloc(nsize); \
|
||||
if(tmp == NULL) { goto _failed; } \
|
||||
memcpy(tmp, ctx->stack, csize); \
|
||||
ctx->stack = stack = tmp; \
|
||||
ctx->stack_size = stack_size = MSGPACK_EMBED_STACK_SIZE * 2; \
|
||||
} else { \
|
||||
size_t nsize = sizeof(msgpack_unpack_struct(_stack)) * ctx->stack_size * 2; \
|
||||
msgpack_unpack_struct(_stack)* tmp = (msgpack_unpack_struct(_stack)*)realloc(ctx->stack, nsize); \
|
||||
if(tmp == NULL) { goto _failed; } \
|
||||
ctx->stack = stack = tmp; \
|
||||
ctx->stack_size = stack_size = stack_size * 2; \
|
||||
} \
|
||||
} \
|
||||
*/ \
|
||||
goto _header_again
|
||||
|
||||
#define NEXT_CS(p) \
|
||||
@ -231,6 +217,7 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
|
||||
case 0xdf: // map 32
|
||||
again_fixed_trail(NEXT_CS(p), 2u << (((unsigned int)*p) & 0x01));
|
||||
default:
|
||||
ret = MSGPACK_UNPACK_PARSE_ERROR;
|
||||
goto _failed;
|
||||
}
|
||||
SWITCH_RANGE(0xa0, 0xbf) // FixStr
|
||||
@ -241,6 +228,7 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
|
||||
start_container(_map, ((unsigned int)*p) & 0x0f, MSGPACK_CT_MAP_KEY);
|
||||
|
||||
SWITCH_RANGE_DEFAULT
|
||||
ret = MSGPACK_UNPACK_PARSE_ERROR;
|
||||
goto _failed;
|
||||
SWITCH_RANGE_END
|
||||
// end MSGPACK_CS_HEADER
|
||||
@ -384,6 +372,7 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
|
||||
}
|
||||
|
||||
default:
|
||||
ret = MSGPACK_UNPACK_PARSE_ERROR;
|
||||
goto _failed;
|
||||
}
|
||||
}
|
||||
@ -393,7 +382,8 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
|
||||
c = &stack[top-1];
|
||||
switch(c->ct) {
|
||||
case MSGPACK_CT_ARRAY_ITEM:
|
||||
if(msgpack_unpack_callback(_array_item)(user, &c->obj, obj) < 0) { goto _failed; }
|
||||
ret = msgpack_unpack_callback(_array_item)(user, &c->obj, obj); \
|
||||
if(ret < 0) { goto _failed; }
|
||||
if(--c->count == 0) {
|
||||
obj = c->obj;
|
||||
--top;
|
||||
@ -406,7 +396,8 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
|
||||
c->ct = MSGPACK_CT_MAP_VALUE;
|
||||
goto _header_again;
|
||||
case MSGPACK_CT_MAP_VALUE:
|
||||
if(msgpack_unpack_callback(_map_item)(user, &c->obj, c->map_key, obj) < 0) { goto _failed; }
|
||||
ret = msgpack_unpack_callback(_map_item)(user, &c->obj, c->map_key, obj); \
|
||||
if(ret < 0) { goto _failed; }
|
||||
if(--c->count == 0) {
|
||||
obj = c->obj;
|
||||
--top;
|
||||
@ -417,6 +408,7 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
|
||||
goto _header_again;
|
||||
|
||||
default:
|
||||
ret = MSGPACK_UNPACK_PARSE_ERROR;
|
||||
goto _failed;
|
||||
}
|
||||
|
||||
@ -436,7 +428,6 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
|
||||
|
||||
_failed:
|
||||
/*printf("** FAILED **\n"); */
|
||||
ret = -1;
|
||||
goto _end;
|
||||
|
||||
_out:
|
||||
|
14
src/unpack.c
14
src/unpack.c
@ -195,10 +195,10 @@ static inline int template_callback_array(unpack_user* u, unsigned int n, msgpac
|
||||
size = n*sizeof(msgpack_object);
|
||||
if (size / sizeof(msgpack_object) != n) {
|
||||
// integer overflow
|
||||
return -1;
|
||||
return MSGPACK_UNPACK_NOMEM_ERROR;
|
||||
}
|
||||
o->via.array.ptr = (msgpack_object*)msgpack_zone_malloc(u->z, n*sizeof(msgpack_object));
|
||||
if(o->via.array.ptr == NULL) { return -1; }
|
||||
if(o->via.array.ptr == NULL) { return MSGPACK_UNPACK_NOMEM_ERROR; }
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -222,10 +222,10 @@ static inline int template_callback_map(unpack_user* u, unsigned int n, msgpack_
|
||||
size = n*sizeof(msgpack_object_kv);
|
||||
if (size / sizeof(msgpack_object_kv) != n) {
|
||||
// integer overflow
|
||||
return -1;
|
||||
return MSGPACK_UNPACK_NOMEM_ERROR;
|
||||
}
|
||||
o->via.map.ptr = (msgpack_object_kv*)msgpack_zone_malloc(u->z, size);
|
||||
if(o->via.map.ptr == NULL) { return -1; }
|
||||
if(o->via.map.ptr == NULL) { return MSGPACK_UNPACK_NOMEM_ERROR; }
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -537,7 +537,7 @@ static inline msgpack_unpack_return unpacker_next(msgpack_unpacker* mpac,
|
||||
if(ret < 0) {
|
||||
result->zone = NULL;
|
||||
memset(&result->data, 0, sizeof(msgpack_object));
|
||||
return MSGPACK_UNPACK_PARSE_ERROR;
|
||||
return ret;
|
||||
}
|
||||
|
||||
if(ret == 0) {
|
||||
@ -601,7 +601,7 @@ msgpack_unpack(const char* data, size_t len, size_t* off,
|
||||
|
||||
e = template_execute(&ctx, data, len, &noff);
|
||||
if(e < 0) {
|
||||
return MSGPACK_UNPACK_PARSE_ERROR;
|
||||
return e;
|
||||
}
|
||||
|
||||
if(off != NULL) { *off = noff; }
|
||||
@ -652,7 +652,7 @@ msgpack_unpack_next(msgpack_unpacked* result,
|
||||
if(e < 0) {
|
||||
msgpack_zone_free(result->zone);
|
||||
result->zone = NULL;
|
||||
return MSGPACK_UNPACK_PARSE_ERROR;
|
||||
return e;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user