[Piglit] [PATCH 1/5] util: Wrapper to load exact hex patterns for ints
Alejandro Piñeiro
apinheiro at igalia.com
Wed Jun 29 14:28:13 UTC 2016
On 14/06/16 23:36, Andres Gomez wrote:
> 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 <agomez at igalia.com>
> ---
> 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 */
Nitpick: this code can be tricky, but curiously, the only comment is
about the simpler line to understand ;). I would just remove this comment.
> + 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;
With or without that nitpick solved:
Reviewed-by: Alejandro Piñeiro <apinheiro at igalia.com>
More information about the Piglit
mailing list