in parson.c [444:482]
static JSON_Status json_object_resize(_Ptr<JSON_Object> object, size_t new_capacity) {
if ((object->names == NULL && object->values != NULL) ||
(object->names != NULL && object->values == NULL) ||
new_capacity == 0) {
return JSONFailure; /* Shouldn't happen */
}
_Unchecked {
char** temp_names = (char**)parson_malloc(char*, new_capacity * sizeof(char*));
if (temp_names == NULL) {
return JSONFailure;
}
JSON_Value** temp_values = (JSON_Value**)parson_malloc(JSON_Value*, new_capacity * sizeof(JSON_Value*));
if (temp_values == NULL) {
parson_free_unchecked(temp_names);
return JSONFailure;
}
/* TODO: Memcpy functions below warn "cannot prove argument meets declared
* bounds" 1st arg truly won't prove unless new_capacity > object->count,
* which isn't checked here! It isn't exactly determined in the caller either.
* This sort of means we can't prove the second arg either, since we
* can't really know that count <= capacity. (Even if we could,
* the compiler would have trouble with "<")
* This reasoning applies to both memcpy functions below. */
if (object->names != NULL && object->values != NULL && object->count > 0) {
memcpy(temp_names, object->names, object->count * sizeof(char*));
memcpy(temp_values, object->values, object->count * sizeof(JSON_Value*));
}
parson_free(_Nt_array_ptr<char>, object->names);
parson_free(_Ptr<JSON_Value>, object->values);
// TODO: The three statements below need to be changed atomically
object->capacity = new_capacity;
object->names = temp_names;
object->values = temp_values;
} // end _Unchecked
return JSONSuccess;
}