Skip to content

Commit fcf89fe

Browse files
author
David LeBlanc
committed
Fix tabs, also attempt work-around for compile time constant conditional
warning
1 parent a2f3689 commit fcf89fe

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/unpack.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,12 @@ static inline int template_callback_false(unpack_user* u, msgpack_object* o)
189189

190190
static inline int template_callback_array(unpack_user* u, unsigned int n, msgpack_object* o)
191191
{
192-
size_t size;
192+
size_t size;
193193
// Let's leverage the fact that sizeof(msgpack_object) is a compile time constant
194194
// to check for int overflows.
195195
// Note - while n is constrained to 32-bit, the product of n * sizeof(msgpack_object)
196196
// might not be constrained to 4GB on 64-bit systems
197-
if( n > SIZE_MAX/sizeof(msgpack_object))
197+
if( (size_t)n > SIZE_MAX/sizeof(msgpack_object))
198198
return MSGPACK_UNPACK_NOMEM_ERROR;
199199

200200
o->type = MSGPACK_OBJECT_ARRAY;
@@ -229,13 +229,14 @@ static inline int template_callback_array_item(unpack_user* u, msgpack_object* c
229229

230230
static inline int template_callback_map(unpack_user* u, unsigned int n, msgpack_object* o)
231231
{
232-
size_t size;
232+
size_t size;
233233
// Let's leverage the fact that sizeof(msgpack_object_kv) is a compile time constant
234234
// to check for int overflows
235235
// Note - while n is constrained to 32-bit, the product of n * sizeof(msgpack_object)
236236
// might not be constrained to 4GB on 64-bit systems
237237

238-
if(n > SIZE_MAX/sizeof(msgpack_object_kv))
238+
// Note - this will always be false on 64-bit systems
239+
if((size_t)n > SIZE_MAX/sizeof(msgpack_object_kv))
239240
return MSGPACK_UNPACK_NOMEM_ERROR;
240241

241242
o->type = MSGPACK_OBJECT_MAP;

0 commit comments

Comments
 (0)