[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: PVS-Studio Warning
- From: Roberto Ierusalimschy <roberto@...>
- Date: Fri, 20 Apr 2012 16:17:54 -0300
> I am compiling Lua 5.1.5 using Visual Studio with PVS-Studio plugin.
> He is complaining about the use of fs pointer in the function close_func
> (lparser.c:358)
>
> The fs pointer is used before it was verified against nullptr.
>
> lparser.cpp
> 358 FuncState *fs = ls->fs;
> Proto *f = fs->f;
> removevars(ls, 0);
> luaK_ret(fs, 0, 0); /* final return */
> luaM_reallocvector(L, f->code, f->sizecode, fs->pc, Instruction);
> ...
> 378 if (fs) anchor_token(ls);
>
> I am not sure. But maybe anchor_token will always be reached.
> The if is useless.
Sure it is:
ls->fs = fs->prev; <<< would crash if fs == NULL
/* last token read was anchored in defunct function; must reanchor it */
if (fs) anchor_token(ls);
Probably the test should be 'if (ls->fs)', but it does not seem to
be necessary anyway.
Thank you for the report.
-- Roberto