Skip to content
Snippets Groups Projects
Commit 9a27df3a authored by Giovanni Mascellani's avatar Giovanni Mascellani Committed by Alexandre Julliard
Browse files

tests: Read integer uniforms with strtol() and strtoul().

Because %i sscanf() converters are deprecated, and in practice
clamp to [-2^31, 2^31) on 32 bit.
parent eb71c5f2
No related branches found
No related tags found
1 merge request!129tests: Read integer uniforms with strtol() and strtoul().
Pipeline #9270 skipped
......@@ -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;
......@@ -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
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment