diff --git a/README.md b/README.md index 6b9fb8c..54205a1 100644 --- a/README.md +++ b/README.md @@ -31,14 +31,15 @@ void print_commits_info(const char *username, const char *repo) { char output_filename[] = "commits.json"; /* it ain't pretty, but it's not a libcurl tutorial */ - sprintf(curl_command, "curl -s \"https://api.github.com/repos/%s/%s/commits\"\ - > %s", username, repo, output_filename); + sprintf(curl_command, + "curl -s \"https://api.github.com/repos/%s/%s/commits\" > %s", + username, repo, output_filename); sprintf(cleanup_command, "rm -f %s", output_filename); system(curl_command); /* parsing json and validating output */ root_value = json_parse_file(output_filename); - if (root_value == NULL || json_value_get_type(root_value) != JSONArray) { + if (json_value_get_type(root_value) != JSONArray) { system(cleanup_command); return; } diff --git a/parson.c b/parson.c index 1769a77..2596023 100644 --- a/parson.c +++ b/parson.c @@ -511,11 +511,8 @@ JSON_Value * json_parse_file(const char *filename) { } JSON_Value * json_parse_string(const char *string) { - if (string && (*string == '{' || *string == '[')) { - return parse_value((const char**)&string, 0); - } else { - return NULL; - } + if (!string || (*string != '{' && *string != '[')) { return NULL; } + return parse_value((const char**)&string, 0); } /* JSON Object API */ diff --git a/tests.c b/tests.c index 53bf0a5..a65b709 100644 --- a/tests.c +++ b/tests.c @@ -180,14 +180,15 @@ void print_commits_info(const char *username, const char *repo) { char output_filename[] = "commits.json"; /* it ain't pretty, but it's not a libcurl tutorial */ - sprintf(curl_command, "curl -s \"https://api.github.com/repos/%s/%s/commits\"\ - > %s", username, repo, output_filename); + sprintf(curl_command, + "curl -s \"https://api.github.com/repos/%s/%s/commits\" > %s", + username, repo, output_filename); sprintf(cleanup_command, "rm -f %s", output_filename); system(curl_command); /* parsing json and validating output */ root_value = json_parse_file(output_filename); - if (root_value == NULL || json_value_get_type(root_value) != JSONArray) { + if (json_value_get_type(root_value) != JSONArray) { system(cleanup_command); return; }