Possible variable used uninitialized in Lua 5.3

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Possible variable used uninitialized in Lua 5.3

Steven Degutis
In ldebug.c at line 518 the variable "name" (declared at line 509)
might have been uninitialized if the condition at line 512 was
non-truthy.

-Steven

Reply | Threaded
Open this post in threaded view
|

Re: Possible variable used uninitialized in Lua 5.3

Philipp Janda
Am 11.11.2014 um 15:25 schröbte Steven Degutis:
> In ldebug.c at line 518 the variable "name" (declared at line 509)
> might have been uninitialized if the condition at line 512 was
> non-truthy.

`name` is only used if `kind` is set to a non-NULL value, and every
statement that could set `kind` to a non-NULL value (`getupvalname` and
`getobjname`) also initializes `name`.
Do you have a compiler that complains?

>
> -Steven
>

Philipp



Reply | Threaded
Open this post in threaded view
|

Re: Possible variable used uninitialized in Lua 5.3

Steven Degutis
Quoth Philipp Janda:

> Am 11.11.2014 um 15:25 schröbte Steven Degutis:
>>
>> In ldebug.c at line 518 the variable "name" (declared at line 509)
>> might have been uninitialized if the condition at line 512 was
>> non-truthy.
>
>
> `name` is only used if `kind` is set to a non-NULL value, and every
> statement that could set `kind` to a non-NULL value (`getupvalname` and
> `getobjname`) also initializes `name`.
> Do you have a compiler that complains?

Yep, Xcode (which is to say, clang &| llvm).

-Steven

Reply | Threaded
Open this post in threaded view
|

Re: Possible variable used uninitialized in Lua 5.3

Tim Hill

> On Nov 11, 2014, at 7:25 AM, Steven Degutis <[hidden email]> wrote:
>
> Quoth Philipp Janda:
>> Am 11.11.2014 um 15:25 schröbte Steven Degutis:
>>>
>>> In ldebug.c at line 518 the variable "name" (declared at line 509)
>>> might have been uninitialized if the condition at line 512 was
>>> non-truthy.
>>
>>
>> `name` is only used if `kind` is set to a non-NULL value, and every
>> statement that could set `kind` to a non-NULL value (`getupvalname` and
>> `getobjname`) also initializes `name`.
>> Do you have a compiler that complains?
>
> Yep, Xcode (which is to say, clang &| llvm).
>
> -Steven
>

Almost certainly a false-positive by the static analyzer (there are quite a few others in Lua). Assuming there really is no path that would use it uninitialized, you can silence the warning with an appropriate assert().

—Tim