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

Matteo Bruni matteo.mystral at gmail.com
Tue May 10 15:48:30 CDT 2022


On Tue, May 10, 2022 at 8:27 PM Zebediah Figura <zfigura at codeweavers.com> wrote:
>
> 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?

I'm not sure why I decided that I needed to copy the function over...
Now I moved the implementation to vkd3d_shader_private.h (so I made it
static inline), does that seem good or do you prefer it somewhere
else? I could e.g. move it back to preproc.y, it somehow didn't feel
great but I can surely get over it.



More information about the wine-devel mailing list