考虑以下功能:
int get_timestamp(json_object *json_obj, double *timestamp) {
json_object *value_obj;
int status;
if (json_object_object_get_ex(json_obj, "timestamp", &value_obj)) {
if (json_object_is_type(value_obj, json_type_double)) {
*timestamp = json_object_get_double(value_obj);
status = JSONPARSER_OK;
}
else
status = JSONPARSER_EBADTYPE;
} else
status = JSONPARSER_ENODENOTFOUND;
free(value_obj);
return status;
}
int get_display_name(json_object *json_obj, char **display_name) {
json_object *value_obj;
int status;
const char* holder;
if (json_object_object_get_ex(json_obj, "display_name", &value_obj)) {
if (json_object_is_type(value_obj, json_type_string)) {
// The returned string memory is managed by the json_object and will
// be freed when the reference count of the json_object drops to zero.
holder = json_object_get_string(value_obj);
strcpy(*display_name, holder);
status = JSONPARSER_OK;
}
else
status = JSONPARSER_EBADTYPE;
} else
status = JSONPARSER_ENODENOTFOUND;
free(value_obj);
return status;
}
int get_organization(json_object *json_obj, char **organization) {
json_object *value_obj;
int status;
const char* holder;
if (json_object_object_get_ex(json_obj, "organization", &value_obj)) {
if (json_object_is_type(value_obj, json_type_string)) {
// The returned string memory is managed by the json_object and will
// be freed when the reference count of the json_object drops to zero.
holder = json_object_get_string(value_obj);
strcpy(*organization, holder);
status = JSONPARSER_OK;
}
else
status = JSONPARSER_EBADTYPE;
} else
status = JSONPARSER_ENODENOTFOUND;
free(value_obj);
return status;
}
用作:
json_object *response_obj, *idp_obj;
int status;
char *display_name;
char *organization;
response_obj = json_tokener_parse(raw_data);
json_object_object_get_ex(response_obj, "idp", &idp_obj);
get_timestamp(response_obj, timestamp);
get_display_name(idp_obj, &display_name);
get_organization(idp_obj, &organization);
free(idp_obj);
free(response_obj);
return status;
怎么了:
1)通过删除get_organization(idp_obj, &organization);
一切似乎工作正常;
2)通过删除get_display_name(idp_obj, &display_name);
一切似乎又可以正常工作了;
3)使用“原样”代码,strcpy
方法内部使用的错误get_organization
:
No source available for "__strcpy_sse2_unaligned() at 0x7ffff763f001"
我真的很想了解这种行为,以提高我对这种令人惊叹但难懂的语言的了解。