[PATCH 2/3] Remove XML parsing special case temperature code

Linus Torvalds torvalds at linux-foundation.org
Wed Jan 23 12:44:35 PST 2013


From: Linus Torvalds <torvalds at linux-foundation.org>
Date: Wed, 23 Jan 2013 12:09:29 -0800
Subject: [PATCH 2/3] Remove XML parsing special case temperature code

We had various hacky historical artifacts in our XML parsing, partly
from our legacy of parsing integer and floating point data separately
(we used to recognize certain import format differences based on whether
the data was in a floating point or integer format).  And partly from
trying to do a good job of importing crap from other dive log software.

Anyway, that actually meant that we refused to parse negative numbers,
and we ignored temperatures of zero because some diving log would do
that for missing values.

Both of these actually bit us when parsing our native XML.  Of course,
only crazy ice divers would ever notice.

Noticed by Henrik Brautaset Aronsen.

Reported-acked-and-tested-by: Henrik Brautaset Aronsen <subsurface at henrik.synth.no>
Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
---

This fixes the negative value parsing and the 0C temperature issue noticed 
by Henrik.

 parse-xml.c | 26 ++++++--------------------
 1 file changed, 6 insertions(+), 20 deletions(-)

diff --git a/parse-xml.c b/parse-xml.c
index 0aa4b7bf0d8b..85b1c530658f 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -234,26 +234,16 @@ enum number_type {
 static enum number_type integer_or_float(char *buffer, union int_or_float *res)
 {
 	char *end;
-	long val;
 	double fp;
 
-	/* Integer or floating point? */
-	val = strtol(buffer, &end, 10);
-	if (val < 0 || end == buffer)
-		return NEITHER;
-
-	/* Looks like it might be floating point? */
-	if (*end == '.') {
-		errno = 0;
-		fp = g_ascii_strtod(buffer, &end);
-		if (!errno) {
-			res->fp = fp;
-			return FLOAT;
-		}
+	errno = 0;
+	fp = g_ascii_strtod(buffer, &end);
+	if (!errno && end != buffer) {
+		res->fp = fp;
+		return FLOAT;
 	}
 
-	res->fp = val;
-	return FLOAT;
+	return NEITHER;
 }
 
 static void pressure(char *buffer, void *_press)
@@ -353,10 +343,6 @@ static void temperature(char *buffer, void *_temperature)
 
 	switch (integer_or_float(buffer, &val)) {
 	case FLOAT:
-		/* Ignore zero. It means "none" */
-		if (!val.fp)
-			break;
-		/* Celsius */
 		switch (xml_parsing_units.temperature) {
 		case KELVIN:
 			temperature->mkelvin = val.fp * 1000;
-- 
1.8.1.1.271.g02f55e6



More information about the subsurface mailing list