[Piglit] [PATCH] shader_runner: fix parsing float/double hex values

Ilia Mirkin imirkin at alum.mit.edu
Mon Feb 9 14:50:20 PST 2015


It seems like when parsing a value like 0xc0d1cbdd371d381f with strtoll,
it returns 0x7fffffffffffffff, presumably because it goes out of bounds.
I guess this issue didn't happen with float, but seems safe to fix it as
well.

Signed-off-by: Ilia Mirkin <imirkin at alum.mit.edu>
---
 tests/shaders/shader_runner.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tests/shaders/shader_runner.c b/tests/shaders/shader_runner.c
index 8da0984..baccd35 100644
--- a/tests/shaders/shader_runner.c
+++ b/tests/shaders/shader_runner.c
@@ -1143,11 +1143,11 @@ get_floats(const char *line, float *f, unsigned count)
 
 		if (strncmp(line, "0x", 2) == 0) {
 			union {
-				int32_t i;
+				uint32_t u;
 				float f;
 			} x;
 
-			x.i = strtol(line, (char **) &line, 16);
+			x.u = strtoul(line, (char **) &line, 16);
 			f[i] = x.f;
 		} else {
 			f[i] = strtod_inf(line, (char **) &line);
@@ -1165,11 +1165,11 @@ get_doubles(const char *line, double *d, unsigned count)
 
 		if (strncmp(line, "0x", 2) == 0) {
 			union {
-				int64_t i64;
+				uint64_t u64;
 				double d;
 			} x;
 
-			x.i64 = strtoll(line, (char **) &line, 16);
+			x.u64 = strtoull(line, (char **) &line, 16);
 			d[i] = x.d;
 		} else {
 			d[i] = strtod_inf(line, (char **) &line);
-- 
2.0.5



More information about the Piglit mailing list