[Pkg-wmaker-commits] [wmforecast] 01/14: Improve error handling.

Doug Torrance dtorrance-guest at moszumanska.debian.org
Sun Apr 3 19:39:21 UTC 2016


This is an automated email from the git hooks/post-receive script.

dtorrance-guest pushed a commit to branch master
in repository wmforecast.

commit f19e666b8e8e238db3edb188d3944e192f55d61f
Author: Doug Torrance <dtorrance at piedmont.edu>
Date:   Fri Apr 1 01:07:34 2016 -0400

    Improve error handling.
    
    Sometimes (still need to investigate when and how this happens), the xml
    file we get doesn't have the expected format.  Then we could end up
    with a NULL xmlNodePtr, which causes a segfault when trying to access
    its children.
---
 wmforecast.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/wmforecast.c b/wmforecast.c
index adba35d..272edcf 100755
--- a/wmforecast.c
+++ b/wmforecast.c
@@ -382,6 +382,7 @@ Weather *getWeather(WMScreen *screen, Preferences *prefs)
 	Weather *weather;
 	xmlDocPtr doc;
 	xmlNodePtr cur;
+	int i;
 
 	url = wstrdup("https://query.yahooapis.com/v1/public/yql?q="
 		      "select%20*%20from%20weather.forecast%20where%20woeid");
@@ -433,10 +434,15 @@ Weather *getWeather(WMScreen *screen, Preferences *prefs)
 		return weather;
 	}
 
-	/* cur at "query" */
-	cur = cur->children; /* down to "results" */
-	cur = cur->children; /* down to "channel" */
-	cur = cur->children; /* down one more -- this is where we want to be */
+	for (i = 0; i < 3; i++) {
+		cur = cur->children;
+		if (cur == NULL) {
+			setError(weather, screen,
+				 "Document not parsed successfully");
+			xmlFreeDoc(doc);
+			return weather;
+		}
+	}
 
 	while (cur != NULL) {
 		if ((!xmlStrcmp(cur->name, (const xmlChar *)"item"))) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-wmaker/wmforecast.git



More information about the Pkg-wmaker-commits mailing list