aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Krahl <me@robin-krahl.de>2016-03-09 00:54:04 +0100
committerRobin Krahl <me@robin-krahl.de>2016-03-09 00:54:04 +0100
commit0f93a7e3516b326b709b3f669f1ca68e306dd3e9 (patch)
treec7c9d591e746ce7a9ce1d41516d96b5949af36d9
parentbcc7dcdc05b0b3834787d7c730a750011e80b27b (diff)
downloaddbfp-0f93a7e3516b326b709b3f669f1ca68e306dd3e9.tar.gz
dbfp-0f93a7e3516b326b709b3f669f1ca68e306dd3e9.tar.bz2
dbfp: fix error handling in dbfp_query_location_name
The old code returned a successful status, but does not set the result values if there are no results. This patch changes the error handling so that the results are always set if no error occured.
-rw-r--r--dbfp.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/dbfp.c b/dbfp.c
index 41e8abc..2089f78 100644
--- a/dbfp.c
+++ b/dbfp.c
@@ -67,6 +67,7 @@ struct dbfp_status dbfp_query_location_name(struct dbfp *dbfp, char *input,
XML_Parser parser = NULL;
if (!dbfp || !input) {
+ status.error = 1;
status.run_error = EINVAL;
goto cleanup;
}
@@ -77,11 +78,13 @@ struct dbfp_status dbfp_query_location_name(struct dbfp *dbfp, char *input,
*/
query = malloc(DBFP_URL_LEN);
if (!query) {
+ status.error = 1;
status.run_error = ENOMEM;
goto cleanup;
}
len = snprintf(query, DBFP_URL_LEN, "input=%s", input);
if (len < 0 || len >= DBFP_URL_LEN) {
+ status.error = 1;
status.run_error = -1;
goto cleanup;
}
@@ -97,7 +100,7 @@ struct dbfp_status dbfp_query_location_name(struct dbfp *dbfp, char *input,
dbfp_request(dbfp, "location.name", query, parser, &status);
- if (ld.n && ld.locs) {
+ if (!status.error) {
if (n)
*n = ld.n;
if (out)
@@ -112,10 +115,6 @@ cleanup:
XML_ParserFree(parser);
free(query);
- if (status.run_error || status.parse_error || status.curl_error ||
- status.api_error)
- status.error = 1;
-
return status;
}
@@ -128,6 +127,7 @@ static int dbfp_parse(void *contents, size_t len, size_t n, void *data)
pd = (struct parse_data *)XML_GetUserData(parser);
if (!pd->status->parse_error && !XML_Parse(parser, contents, size, 0)) {
+ pd->status->error = 1;
pd->status->parse_error = XML_GetErrorCode(parser);
}
@@ -147,6 +147,7 @@ static void dbfp_request(struct dbfp *dbfp, char *service, char *query,
curl_global_init(CURL_GLOBAL_ALL ^ CURL_GLOBAL_SSL);
curl = curl_easy_init();
if (!curl) {
+ status->error = 1;
status->run_error = -1;
goto cleanup;
}