Skip to content

Commit 7a70d74

Browse files
author
David LeBlanc
committed
Use a #define to only check for integer overflow when it is actually
possible
1 parent fcf89fe commit 7a70d74

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/unpack.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,10 @@ static inline int template_callback_array(unpack_user* u, unsigned int n, msgpac
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( (size_t)n > SIZE_MAX/sizeof(msgpack_object))
197+
#if SIZE_MAX == UINT_MAX
198+
if (n > SIZE_MAX/sizeof(msgpack_object))
198199
return MSGPACK_UNPACK_NOMEM_ERROR;
200+
#endif
199201

200202
o->type = MSGPACK_OBJECT_ARRAY;
201203
o->via.array.size = 0;
@@ -236,8 +238,10 @@ static inline int template_callback_map(unpack_user* u, unsigned int n, msgpack_
236238
// might not be constrained to 4GB on 64-bit systems
237239

238240
// Note - this will always be false on 64-bit systems
239-
if((size_t)n > SIZE_MAX/sizeof(msgpack_object_kv))
241+
#if SIZE_MAX == UINT_MAX
242+
if (n > SIZE_MAX/sizeof(msgpack_object_kv))
240243
return MSGPACK_UNPACK_NOMEM_ERROR;
244+
#endif
241245

242246
o->type = MSGPACK_OBJECT_MAP;
243247
o->via.map.size = 0;

0 commit comments

Comments
 (0)