@@ -129,7 +129,9 @@ static PHP_METHOD(MongoDB_BSON_PackedArray, fromJSON)
129
129
// Check if BSON contains only numeric keys
130
130
if (!bson_empty (bson )) {
131
131
bson_iter_t iter ;
132
- uint64_t expected_key = 0 ;
132
+ uint32_t expected_key = 0 ;
133
+ char expected_key_str [11 ];
134
+ const char * key_str ;
133
135
134
136
if (!bson_iter_init (& iter , bson )) {
135
137
phongo_throw_exception (PHONGO_ERROR_UNEXPECTED_VALUE , "Received invalid JSON array" );
@@ -138,12 +140,11 @@ static PHP_METHOD(MongoDB_BSON_PackedArray, fromJSON)
138
140
}
139
141
140
142
while (bson_iter_next (& iter )) {
141
- const char * string_key = bson_iter_key (& iter );
142
- char * string_key_end ;
143
- uint64_t int_key = strtoll (string_key , & string_key_end , 10 );
143
+ key_str = bson_iter_key (& iter );
144
+ snprintf (expected_key_str , sizeof (expected_key_str ), "%" PRIu32 , expected_key );
144
145
145
- if (* string_key_end != '\0' || int_key != expected_key ) {
146
- phongo_throw_exception (PHONGO_ERROR_UNEXPECTED_VALUE , "Received invalid JSON array: expected key %" PRId64 ", but found \"%s\"" , expected_key , string_key );
146
+ if (strcmp ( key_str , expected_key_str ) ) {
147
+ phongo_throw_exception (PHONGO_ERROR_UNEXPECTED_VALUE , "Received invalid JSON array: expected key %" PRIu32 ", but found \"%s\"" , expected_key , key_str );
147
148
bson_destroy (bson );
148
149
return ;
149
150
}
0 commit comments