Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning of uninitialised variables in tcp.c and udp.c #398

Closed
vanc opened this issue Oct 9, 2019 · 0 comments · Fixed by #402
Closed

Warning of uninitialised variables in tcp.c and udp.c #398

vanc opened this issue Oct 9, 2019 · 0 comments · Fixed by #402
Labels

Comments

@vanc
Copy link

vanc commented Oct 9, 2019

The issues were introduced in 4573edf.

src/tcp.c:39:14: warning: variable 'flags' is used uninitialized whenever 'if' condition is
      false [-Wsometimes-uninitialized]
    else if (lua_isstring(L, 1)) {
             ^~~~~~~~~~~~~~~~~~
src/tcp.c:49:45: note: uninitialized use occurs here
    ret = uv_tcp_init_ex(ctx->loop, handle, flags);
                                            ^~~~~
src/tcp.c:39:10: note: remove the 'if' if its condition is always true
    else if (lua_isstring(L, 1)) {
         ^~~~~~~~~~~~~~~~~~~~~~~~
src/tcp.c:35:23: note: initialize the variable 'flags' to silence this warning
    unsigned int flags;
                      ^
                       = 0

src/udp.c:38:14: warning: variable 'flags' is used uninitialized whenever 'if' condition is
      false [-Wsometimes-uninitialized]
    else if (lua_isstring(L, 1)) {
             ^~~~~~~~~~~~~~~~~~
src/udp.c:48:45: note: uninitialized use occurs here
    ret = uv_udp_init_ex(ctx->loop, handle, flags);
                                            ^~~~~
src/udp.c:38:10: note: remove the 'if' if its condition is always true
    else if (lua_isstring(L, 1)) {
         ^~~~~~~~~~~~~~~~~~~~~~~~
src/udp.c:34:23: note: initialize the variable 'flags' to silence this warning
    unsigned int flags;
                      ^
                       = 0

Compilers don't know that after luaL_argerror(), the remaining code is unreachable. But it's better to initialize the flags to zero.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants