Skip to content

Commit

Permalink
cleanup: Use hex numerals; use UINT64_C for uint64_t constant.
Browse files Browse the repository at this point in the history
Hex numerals in these contexts are much clearer and less prone to
off-by-one errors.
  • Loading branch information
iphydf committed Nov 4, 2024
1 parent 0905d58 commit e8f5297
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions cmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1963,7 +1963,7 @@ bool cmp_read_short(cmp_ctx_t *ctx, int16_t *s) {
return true;
}
case CMP_TYPE_UINT16: {
if (obj.as.u16 <= 32767) {
if (obj.as.u16 <= 0x7fff) {
*s = (int16_t)obj.as.u16;
return true;
}
Expand Down Expand Up @@ -2007,7 +2007,7 @@ bool cmp_read_int(cmp_ctx_t *ctx, int32_t *i) {
return true;
}
case CMP_TYPE_UINT32: {
if (obj.as.u32 <= 2147483647) {
if (obj.as.u32 <= 0x7fffffff) {
*i = (int32_t)obj.as.u32;
return true;
}
Expand Down Expand Up @@ -2059,7 +2059,7 @@ bool cmp_read_long(cmp_ctx_t *ctx, int64_t *d) {
return true;
}
case CMP_TYPE_UINT64: {
if (obj.as.u64 <= 9223372036854775807) {
if (obj.as.u64 <= UINT64_C(0x7fffffffffffffff)) {
*d = (int64_t)obj.as.u64;
return true;
}
Expand Down Expand Up @@ -3288,7 +3288,7 @@ bool cmp_object_as_short(const cmp_object_t *obj, int16_t *s) {
return true;
}
case CMP_TYPE_UINT16: {
if (obj->as.u16 <= 32767) {
if (obj->as.u16 <= 0x7fff) {
*s = (int16_t)obj->as.u16;
return true;
}
Expand Down Expand Up @@ -3326,7 +3326,7 @@ bool cmp_object_as_int(const cmp_object_t *obj, int32_t *i) {
return true;
}
case CMP_TYPE_UINT32: {
if (obj->as.u32 <= 2147483647) {
if (obj->as.u32 <= 0x7fffffff) {
*i = (int32_t)obj->as.u32;
return true;
}
Expand Down Expand Up @@ -3372,7 +3372,7 @@ bool cmp_object_as_long(const cmp_object_t *obj, int64_t *d) {
return true;
}
case CMP_TYPE_UINT64: {
if (obj->as.u64 <= 9223372036854775807) {
if (obj->as.u64 <= UINT64_C(0x7fffffffffffffff)) {
*d = (int64_t)obj->as.u64;
return true;
}
Expand Down

0 comments on commit e8f5297

Please sign in to comment.