On AIX with GCC 6.3.0, a "maybe-unitialized" variable generates an error.

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

On AIX with GCC 6.3.0, a "maybe-unitialized" variable generates an error.

REIX, Tony
Hi,

On AIX with GCC 6.3.0, a "maybe-unitialized" variable generates an error.


File: src/lib/krb5/os/localaddr.c

gcc -maix64 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGE_FILES -DHAVE_CONFIG_H -DLIBDIR=\"/opt/freeware/lib64\" -DBINDIR=\"/opt/freeware/bin\" -DSBINDIR=\"/opt/freeware/sbin\" -I../../../include -I../../../include -I../../../util/profile -DKRB5_DEPRECATED=1 -DKRB5_PRIVATE  -DSYSV -D_AIX -D_AIX32 -D_AIX41 -D_AIX43 -D_AIX51 -D_AIX53 -D_AIX61 -D_AIX71 -D_AIX72 -D_ALL_SOURCE -DFUNCPROTO=15 -O -I/opt/freeware/include -D_THREAD_SAFE  -Wall -Wcast-align -Wshadow -Wmissing-prototypes -pedantic -Wno-format-zero-length -Woverflow -Wstrict-overflow -Wmissing-format-attribute -Wmissing-prototypes -Wreturn-type -Wmissing-braces -Wparentheses -Wswitch -Wunused-function -Wunused-label -Wunused-variable -Wunused-value -Wunknown-pragmas -Wsign-compare -Werror=uninitialized -Werror=pointer-arith -Werror=int-conversion -Werror=incompatible-pointer-types -Werror=discarded-qualifiers -Werror=declaration-after-statement -Werror-implicit-function-declaration   -c localaddr.c



localaddr.c: In function 'krb5int_foreach_localaddr':
...
localaddr.c:1033:9: error: 'n' may be used uninitialized in this function [-Werror=maybe-uninitialized]
        for (i = 0; i + sizeof(struct ifreq) <= n; i+= ifreq_size(*ifr) ) {
        ^~~

I've attached to this email a simple patch that fixes this issue.
     if (pass2fn) {
+#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
         for (i = 0; i + sizeof(struct ifreq) <= n; i+= ifreq_size(*ifr) ) {

Maybe that a better solution could be found.

Regards

Cordialement,

Tony Reix

Bull - ATOS
IBM Coop Architect & Technical Leader
Office : +33 (0) 4 76 29 72 67
1 rue de Provence - 38432 Échirolles - France
www.atos.net<http://www.atos.net/>

_______________________________________________
krbdev mailing list             [hidden email]
https://mailman.mit.edu/mailman/listinfo/krbdev

krb5-1.15.1-maybe-uninitialized.patch (522 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: On AIX with GCC 6.3.0, a "maybe-unitialized" variable generates an error.

Greg Hudson
On 08/23/2017 09:28 AM, REIX, Tony wrote:
> On AIX with GCC 6.3.0, a "maybe-unitialized" variable generates an error.

> localaddr.c:1033:9: error: 'n' may be used uninitialized in this function [-Werror=maybe-uninitialized]
>         for (i = 0; i + sizeof(struct ifreq) <= n; i+= ifreq_size(*ifr) ) {

It looks like n is supposed to be set by get_ifreq_array(), but this
particular version of gcc isn't smart enough to determine that
get_ifreq_array() always either sets *np or returns nonzero, perhaps
because of the case at line 892 where errno is used as a return value.
My preferred fix for this sort of problem is to make get_ifreq_array()
begin with:

    *bufp = NULL;
    *np = 0;

Does that make the error go away?

Thanks.

(As a side note, if you are comfortable using github, you could file
these patches as pull requests against https://github.com/krb5/krb5 .
Otherwise I will take care of filing PRs.)
_______________________________________________
krbdev mailing list             [hidden email]
https://mailman.mit.edu/mailman/listinfo/krbdev
Reply | Threaded
Open this post in threaded view
|

RE:On AIX with GCC 6.3.0, a "maybe-unitialized" variable generates an error.

REIX, Tony
Hi Greg,

Thanks for the alternative patch.
I've tested it. That's perfect.
I've attached the new patch to this email.

I was comfortable with github. No more. So please fill PRs.

BTW, here are the warnings I see still with localaddr.c .
That does not block me. However that may show some hidden issue. But I have very very small knowledge of krb5. Just porting it.

gcc -maix64 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGE_FILES -DHAVE_CONFIG_H -DLIBDIR=\"/opt/freeware/lib64\" -DBINDIR=\"/opt/freeware/bin\" -DSBINDIR=\"/opt/freeware/sbin\" -I../../../include -I../../../include -I../../../util/profile -DKRB5_DEPRECATED=1 -DKRB5_PRIVATE  -DSYSV -D_AIX -D_AIX32 -D_AIX41 -D_AIX43 -D_AIX51 -D_AIX53 -D_AIX61 -D_AIX71 -D_AIX72 -D_ALL_SOURCE -DFUNCPROTO=15 -O -I/opt/freeware/include -D_THREAD_SAFE  -Wall -Wcast-align -Wshadow -Wmissing-prototypes -pedantic -Wno-format-zero-length -Woverflow -Wstrict-overflow -Wmissing-format-attribute -Wmissing-prototypes -Wreturn-type -Wmissing-braces -Wparentheses -Wswitch -Wunused-function -Wunused-label -Wunused-variable -Wunused-value -Wunknown-pragmas -Wsign-compare -Werror=uninitialized -Werror=pointer-arith -Werror=int-conversion -Werror=incompatible-pointer-types -Werror=discarded-qualifiers -Werror=declaration-after-statement -Werror-implicit-function-declaration   -c localaddr.c
localaddr.c: In function 'krb5int_foreach_localaddr':
localaddr.c:978:35: warning: left-hand operand of comma expression has no effect [-Wunused-value]
         Tprintf (("interface %s\n", ifreq.ifr_name));
                                   ^
localaddr.c:83:28: note: in definition of macro 'Tprintf'
 # define Tprintf(X) (void) X
                            ^
localaddr.c:945:12: warning: unused variable 'size' [-Wunused-variable]
     size_t size, n, i, j;
            ^~~~
localaddr.c:943:12: warning: unused variable 'code' [-Wunused-variable]
     int s, code;
            ^~~~

Regards,

Cordialement,

Tony Reix

Bull - ATOS
IBM Coop Architect & Technical Leader
Office : +33 (0) 4 76 29 72 67
1 rue de Provence - 38432 Échirolles - France
www.atos.net

________________________________________
De : Greg Hudson [[hidden email]]
Envoyé : mercredi 23 août 2017 17:14
À : REIX, Tony; [hidden email]
Objet : Re: On AIX with GCC 6.3.0, a "maybe-unitialized" variable generates an error.

On 08/23/2017 09:28 AM, REIX, Tony wrote:
> On AIX with GCC 6.3.0, a "maybe-unitialized" variable generates an error.

> localaddr.c:1033:9: error: 'n' may be used uninitialized in this function [-Werror=maybe-uninitialized]
>         for (i = 0; i + sizeof(struct ifreq) <= n; i+= ifreq_size(*ifr) ) {

It looks like n is supposed to be set by get_ifreq_array(), but this
particular version of gcc isn't smart enough to determine that
get_ifreq_array() always either sets *np or returns nonzero, perhaps
because of the case at line 892 where errno is used as a return value.
My preferred fix for this sort of problem is to make get_ifreq_array()
begin with:

    *bufp = NULL;
    *np = 0;

Does that make the error go away?

Thanks.

(As a side note, if you are comfortable using github, you could file
these patches as pull requests against https://github.com/krb5/krb5 .
Otherwise I will take care of filing PRs.)

_______________________________________________
krbdev mailing list             [hidden email]
https://mailman.mit.edu/mailman/listinfo/krbdev

krb5-1.15.1-maybe-uninitialized-for-krb5-community.patch (522 bytes) Download Attachment