For some cases we want to have shaders where we load an exact bit
pattern into a signed int.

This fixes the errno-based range validation that was broken when the
integer vbo attribute parsing on 32-bit systems was recently fixed.

Signed-off-by: Andres Gomez <[email protected]>
---
 tests/shaders/shader_runner.c |  2 +-
 tests/util/piglit-util.h      | 24 ++++++++++++++++++++++++
 tests/util/piglit-vbo.cpp     |  2 +-
 3 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/tests/shaders/shader_runner.c b/tests/shaders/shader_runner.c
index 564ae63..d6b6100 100644
--- a/tests/shaders/shader_runner.c
+++ b/tests/shaders/shader_runner.c
@@ -1403,7 +1403,7 @@ get_ints(const char *line, int *ints, unsigned count)
        unsigned i;
 
        for (i = 0; i < count; i++)
-               ints[i] = strtoll(line, (char **) &line, 0);
+               ints[i] = strtol_hex(line, (char **) &line);
 }
 
 
diff --git a/tests/util/piglit-util.h b/tests/util/piglit-util.h
index 1e57215..4328863 100644
--- a/tests/util/piglit-util.h
+++ b/tests/util/piglit-util.h
@@ -269,6 +269,30 @@ strtod_hex(const char *nptr, char **endptr)
        }
 }
 
+/**
+ * Wrapper for strtol() which allows using an exact hex bit pattern to
+ * generate a signed int value.
+ */
+static inline int
+strtol_hex(const char *nptr, char **endptr)
+{
+       /* skip spaces and tabs */
+       while (*nptr == ' ' || *nptr == '\t')
+               nptr++;
+
+       if (strncmp(nptr, "0x", 2) == 0) {
+               union {
+                       uint32_t u;
+                       int32_t i;
+               } x;
+
+               x.u = strtoul(nptr, endptr, 16);
+               return x.i;
+       } else {
+               return strtol(nptr, endptr, 0);
+       }
+}
+
 #ifndef HAVE_STRCHRNUL
 static inline char *
 strchrnul(const char *s, int c)
diff --git a/tests/util/piglit-vbo.cpp b/tests/util/piglit-vbo.cpp
index b8f2d48..274779f 100644
--- a/tests/util/piglit-vbo.cpp
+++ b/tests/util/piglit-vbo.cpp
@@ -387,7 +387,7 @@ vertex_attrib_description::parse_datum(const char **text, 
void *data) const
                break;
        }
        case GL_INT: {
-               long long value = strtoll(*text, &endptr, 0);
+               long value = strtol_hex(*text, &endptr);
                if (errno == ERANGE) {
                        printf("Could not parse as signed integer\n");
                        return false;
-- 
2.8.1

_______________________________________________
Piglit mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/piglit

Reply via email to