[PATCH vkd3d 1/6] vkd3d-shader/hlsl: Handle over/underflow when parsing integer literals.

Zebediah Figura zfigura at codeweavers.com
Tue May 10 13:27:04 CDT 2022


On 5/10/22 13:21, Matteo Bruni wrote:
> Signed-off-by: Matteo Bruni <mbruni at codeweavers.com>
> ---
> This fixes arithmetic-int.shader_test on 32-bit Linux for
> me.
> 
>   libs/vkd3d-shader/hlsl.l | 38 +++++++++++++++++++++++++++++++++++---
>   1 file changed, 35 insertions(+), 3 deletions(-)
> 
> diff --git a/libs/vkd3d-shader/hlsl.l b/libs/vkd3d-shader/hlsl.l
> index 267c8c30..2c398bc8 100644
> --- a/libs/vkd3d-shader/hlsl.l
> +++ b/libs/vkd3d-shader/hlsl.l
> @@ -31,6 +31,38 @@ static void update_location(struct hlsl_ctx *ctx, YYLTYPE *loc);
>   
>   #define YY_USER_ACTION update_location(yyget_extra(yyscanner), yyget_lloc(yyscanner));
>   
> +static int char_to_int(char c)
> +{
> +    if ('0' <= c && c <= '9')
> +        return c - '0';
> +    if ('A' <= c && c <= 'F')
> +        return c - 'A' + 10;
> +    if ('a' <= c && c <= 'f')
> +        return c - 'a' + 10;
> +    return -1;
> +}
> +
> +static uint32_t parse_integer(const char *s)
> +{
> +    uint32_t base = 10, ret = 0;
> +    int digit;
> +
> +    if (*s == '0')
> +    {
> +        base = 8;
> +        ++s;
> +        if (*s == 'x' || *s == 'X')
> +        {
> +            base = 16;
> +            ++s;
> +        }
> +    }
> +
> +    while ((digit = char_to_int(*s++)) >= 0)
> +        ret = ret * base + (uint32_t)digit;
> +    return ret;
> +}
> +

This is an exact copy of preproc_parse_integer(); could we just link to 
that (and rename + move it) instead?



More information about the wine-devel mailing list