diff --git a/tests/d3d12.c b/tests/d3d12.c
index 890a65d53cf96b07b43c69dd9ec6026db0fbdac5..7e2e7fa4f2768eac4c64cffbf4dd6a8fa4ce4cbe 100644
--- a/tests/d3d12.c
+++ b/tests/d3d12.c
@@ -28,11 +28,6 @@ struct test_options test_options = {0};
 static PFN_D3D12_CREATE_VERSIONED_ROOT_SIGNATURE_DESERIALIZER pfn_D3D12CreateVersionedRootSignatureDeserializer;
 static PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE pfn_D3D12SerializeVersionedRootSignature;
 
-struct ivec4
-{
-    int x, y, z, w;
-};
-
 struct dvec2
 {
     double x, y;
diff --git a/tests/shader_runner.c b/tests/shader_runner.c
index 10c6dd21ab03ccda4ea2908dc3ad8335ec6362cc..0912c60b42291a2465158e98f70b49b93edf9e11 100644
--- a/tests/shader_runner.c
+++ b/tests/shader_runner.c
@@ -371,6 +371,58 @@ static void set_uniforms(struct shader_runner *runner, size_t offset, size_t cou
     memcpy(runner->uniforms + offset, uniforms, count * sizeof(*runner->uniforms));
 }
 
+static void read_int(const char **line, int *i)
+{
+    char *rest;
+    long val;
+
+    errno = 0;
+    val = strtol(*line, &rest, 0);
+
+    if (errno != 0 || (*rest != '\0' && !isspace((unsigned char)*rest)))
+        fatal_error("Malformed int constant '%s'.\n", *line);
+
+    *i = val;
+    if (*i != val)
+        fatal_error("Out of range int constant '%.*s'.\n", (int)(rest - *line), *line);
+
+    *line = rest;
+}
+
+static void read_uint(const char **line, unsigned int *u)
+{
+    char *rest;
+    unsigned long val;
+
+    errno = 0;
+    val = strtoul(*line, &rest, 0);
+
+    if (errno != 0 || (*rest != '\0' && !isspace((unsigned char)*rest)))
+        fatal_error("Malformed uint constant '%s'.\n", *line);
+
+    *u = val;
+    if (*u != val)
+        fatal_error("Out of range uint constant '%.*s'.\n", (int)(rest - *line), *line);
+
+    *line = rest;
+}
+
+static void read_int4(const char **line, struct ivec4 *v)
+{
+    read_int(line, &v->x);
+    read_int(line, &v->y);
+    read_int(line, &v->z);
+    read_int(line, &v->w);
+}
+
+static void read_uint4(const char **line, struct uvec4 *v)
+{
+    read_uint(line, &v->x);
+    read_uint(line, &v->y);
+    read_uint(line, &v->z);
+    read_uint(line, &v->w);
+}
+
 static void parse_test_directive(struct shader_runner *runner, const char *line)
 {
     char *rest;
@@ -590,28 +642,32 @@ static void parse_test_directive(struct shader_runner *runner, const char *line)
                 fatal_error("Malformed float constant '%s'.\n", line);
             set_uniforms(runner, offset, 1, &f);
         }
-        else if (match_string(line, "int4", &line) || match_string(line, "uint4", &line))
+        else if (match_string(line, "int4", &line))
+        {
+            struct ivec4 v;
+
+            read_int4(&line, &v);
+            set_uniforms(runner, offset, 4, &v);
+        }
+        else if (match_string(line, "uint4", &line))
         {
-            int v[4];
+            struct uvec4 v;
 
-            if (sscanf(line, "%i %i %i %i", &v[0], &v[1], &v[2], &v[3]) < 4)
-                fatal_error("Malformed (u)int4 constant '%s'.\n", line);
-            set_uniforms(runner, offset, 4, v);
+            read_uint4(&line, &v);
+            set_uniforms(runner, offset, 4, &v);
         }
         else if (match_string(line, "int", &line))
         {
             int i;
 
-            if (sscanf(line, "%i", &i) < 1)
-                fatal_error("Malformed int constant '%s'.\n", line);
+            read_int(&line, &i);
             set_uniforms(runner, offset, 1, &i);
         }
         else if (match_string(line, "uint", &line))
         {
             unsigned int u;
 
-            if (sscanf(line, "%u", &u) < 1)
-                fatal_error("Malformed uint constant '%s'.\n", line);
+            read_uint(&line, &u);
             set_uniforms(runner, offset, 1, &u);
         }
         else
diff --git a/tests/utils.h b/tests/utils.h
index 99f1d3a3e49d2fb05002734d96d9a60d556e682a..5fd7b086e0fde6622b391efa1fc2a6c48cbf2f09 100644
--- a/tests/utils.h
+++ b/tests/utils.h
@@ -35,6 +35,11 @@ struct vec4
     float x, y, z, w;
 };
 
+struct ivec4
+{
+    int x, y, z, w;
+};
+
 struct uvec4
 {
     unsigned int x, y, z, w;