[PATCH vkd3d 2/5] vkd3d-shader: Watch for allocation failure from yyparse().

Matteo Bruni matteo.mystral at gmail.com
Fri Mar 5 10:46:14 CST 2021


On Fri, Mar 5, 2021 at 5:30 PM Zebediah Figura (she/her)
<zfigura at codeweavers.com> wrote:
>
> On 3/5/21 7:20 AM, Matteo Bruni wrote:
> > On Fri, Mar 5, 2021 at 12:33 AM Zebediah Figura <zfigura at codeweavers.com> wrote:
> >>
> >> Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
> >> ---
> >>   libs/vkd3d-shader/hlsl.c | 6 +++++-
> >>   1 file changed, 5 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/libs/vkd3d-shader/hlsl.c b/libs/vkd3d-shader/hlsl.c
> >> index 02fa4843..19bfc93a 100644
> >> --- a/libs/vkd3d-shader/hlsl.c
> >> +++ b/libs/vkd3d-shader/hlsl.c
> >> @@ -1646,7 +1646,11 @@ int hlsl_compile_shader(const char *text, const struct vkd3d_shader_compile_info
> >>       if (!hlsl_ctx_init(&ctx, message_context))
> >>           return VKD3D_ERROR_OUT_OF_MEMORY;
> >>
> >> -    hlsl_lexer_compile(&ctx, text);
> >> +    if (hlsl_lexer_compile(&ctx, text) == 2)
> >> +    {
> >> +        hlsl_ctx_cleanup(&ctx);
> >> +        return VKD3D_ERROR_OUT_OF_MEMORY;
> >> +    }
> >>
> >>       if (ctx.failed)
> >>       {
> >
> > Is this intended to catch memory allocation failures from the
> > bison-generated parser proper? It looks like for me that returns
> > YYENOMEM which is defined as -2.
> >
>
> YYENOMEM is intended to be returned by user callbacks [1]. yyparse()
> itself returns 2, not -2, for which there is not yet a symbolic constant
> [2].
>
> [1]
> https://www.gnu.org/software/bison/manual/html_node/Syntax-Error-Reporting-Function.html
>
> [2] https://www.gnu.org/software/bison/manual/html_node/Parser-Function.html

Indeed, the generated code is pretty clear if one looks in the correct place...



More information about the wine-devel mailing list