Skip to content

Commit 0465d4f

Browse files
committed
PHPC-1093: Bound checking on 32-bit platforms for APM's duration_micros
1 parent 86ac6ec commit 0465d4f

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

phongo_compat.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,22 +143,22 @@
143143
# define ADD_ASSOC_INT64(zval, key, value) add_assoc_long(zval, key, value)
144144
#elif SIZEOF_PHONGO_LONG == 4
145145
# define ADD_INDEX_INT64(zval, index, value) \
146-
if (value > INT32_MAX || value < INT32_MIN) { \
147-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Integer overflow detected on your platform: %lld", value); \
146+
if ((value) > INT32_MAX || (value) < INT32_MIN) { \
147+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Integer overflow detected on your platform: %lld", (value)); \
148148
} else { \
149-
add_index_long(zval, index, value); \
149+
add_index_long(zval, index, (value)); \
150150
}
151151
# define ADD_NEXT_INDEX_INT64(zval, value) \
152-
if (value > INT32_MAX || value < INT32_MIN) { \
153-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Integer overflow detected on your platform: %lld", value); \
152+
if ((value) > INT32_MAX || (value) < INT32_MIN) { \
153+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Integer overflow detected on your platform: %lld", (value)); \
154154
} else { \
155-
add_next_index_long(zval, value); \
155+
add_next_index_long(zval, (value)); \
156156
}
157157
# define ADD_ASSOC_INT64(zval, key, value) \
158-
if (value > INT32_MAX || value < INT32_MIN) { \
159-
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Integer overflow detected on your platform: %lld", value); \
158+
if ((value) > INT32_MAX || (value) < INT32_MIN) { \
159+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, "Integer overflow detected on your platform: %lld", (value)); \
160160
} else { \
161-
add_assoc_long(zval, key, value); \
161+
add_assoc_long(zval, key, (value)); \
162162
}
163163
#else
164164
# error Unsupported architecture (integers are neither 32-bit nor 64-bit)

src/MongoDB/Monitoring/CommandFailedEvent.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ static HashTable *php_phongo_commandfailedevent_get_debug_info(zval *object, int
214214
array_init_size(&retval, 6);
215215

216216
ADD_ASSOC_STRING(&retval, "commandName", intern->command_name);
217-
ADD_ASSOC_INT64(&retval, "durationMicros", intern->duration_micros);
217+
ADD_ASSOC_INT64(&retval, "durationMicros", (int64_t) intern->duration_micros);
218218

219219
#if PHP_VERSION_ID >= 70000
220220
ADD_ASSOC_ZVAL_EX(&retval, "error", &intern->z_error);

src/MongoDB/Monitoring/CommandSucceededEvent.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ static HashTable *php_phongo_commandsucceededevent_get_debug_info(zval *object,
216216
array_init_size(&retval, 6);
217217

218218
ADD_ASSOC_STRING(&retval, "commandName", intern->command_name);
219-
ADD_ASSOC_INT64(&retval, "durationMicros", intern->duration_micros);
219+
ADD_ASSOC_INT64(&retval, "durationMicros", (int64_t) intern->duration_micros);
220220

221221
sprintf(operation_id, "%" PHONGO_LONG_FORMAT, intern->operation_id);
222222
ADD_ASSOC_STRING(&retval, "operationId", operation_id);

0 commit comments

Comments
 (0)