From 0f93a7e3516b326b709b3f669f1ca68e306dd3e9 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Wed, 9 Mar 2016 00:54:04 +0100 Subject: 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. --- dbfp.c | 11 ++++++----- 1 file 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; } -- cgit v1.2.1