about summary refs log tree commit diff
path: root/src/internal
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2012-04-11 00:18:57 -0400
committerRich Felker <dalias@aerifal.cx>2012-04-11 00:18:57 -0400
commit48bb81adf80a439133c376d50ea814687fb5169f (patch)
tree9433f1bb1fd66dbb3a964740e1140c069ece9455 /src/internal
parent38b3f1fea8fe4f2c590c1a9438d219291a7bfcd2 (diff)
downloadmusl-48bb81adf80a439133c376d50ea814687fb5169f.tar.gz
musl-48bb81adf80a439133c376d50ea814687fb5169f.tar.xz
musl-48bb81adf80a439133c376d50ea814687fb5169f.zip
fix bug parsing lone zero followed by junk, and hex float over-reading
Diffstat (limited to 'src/internal')
-rw-r--r--src/internal/floatscan.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/internal/floatscan.c b/src/internal/floatscan.c
index 000706d7..3aa54082 100644
--- a/src/internal/floatscan.c
+++ b/src/internal/floatscan.c
@@ -52,7 +52,7 @@ static long long scanexp(FILE *f, int pok)
 }
 
 
-static long double decfloat(FILE *f, int bits, int emin, int sign, int pok)
+static long double decfloat(FILE *f, int c, int bits, int emin, int sign, int pok)
 {
 	uint32_t x[KMAX];
 	static const uint32_t th[] = { LD_B1B_MAX };
@@ -65,13 +65,10 @@ static long double decfloat(FILE *f, int bits, int emin, int sign, int pok)
 	long double y;
 	long double frac=0;
 	long double bias=0;
-	int c;
 
 	j=0;
 	k=0;
 
-	c = shgetc(f);
-
 	/* Don't let leading zeros consume buffer space */
 	for (; c=='0'; c = shgetc(f)) gotdig=1;
 
@@ -338,6 +335,8 @@ static long double hexfloat(FILE *f, int bits, int emin, int sign, int pok)
 			}
 			e2 = 0;
 		}
+	} else {
+		shunget(f);
 	}
 	e2 += 4*rp - 32;
 
@@ -436,9 +435,9 @@ long double __floatscan(FILE *f, int c, int prec, int pok)
 		c = shgetc(f);
 		if ((c|32) == 'x')
 			return hexfloat(f, bits, emin, sign, pok);
+		shunget(f);
 		c = '0';
 	}
 
-	shunget(f);
-	return decfloat(f, bits, emin, sign, pok);
+	return decfloat(f, c, bits, emin, sign, pok);
 }