OpenWrt Forum Archive

Topic: compile error: warning: iteration 2u invokes undefined behavior

The content of this topic has been archived on 4 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

When trying to compile atmoslog [1] (reads temperature and humidity from TEMPerHUM USB devices), I get the following error:

mips-openwrt-linux-uclibc-gcc atmoslog.c -O2 -Wall -lusb-1.0
cc1: note: someone does not honour COPTS correctly, passed 0 times
atmoslog.c: In function 'setup_device':
atmoslog.c:180:36: warning: iteration 2u invokes undefined behavior [-Waggressive-loop-optimizations]
             printf("%02x ",question[i] & 0xFF);
                                    ^
atmoslog.c:179:9: note: containing loop
         for (i = 0; i < reqIntLen; i++)
         ^
strip a.out
strip: Unable to recognise the format of the input file `a.out'
make[3]: *** [atmoslog] Error 1
make[3]: Leaving directory `/home/tmomas/openwrt/14.07/build_dir/target-mips_34kc_uClibc-0.9.33.2/temper7402'
make[2]: *** [/home/tmomas/openwrt/14.07/build_dir/target-mips_34kc_uClibc-0.9.33.2/temper7402/.built] Error 2
make[2]: Leaving directory `/home/tmomas/openwrt/14.07/package/utils/temper7402'
make[1]: *** [package/utils/temper7402/install] Error 2
make[1]: Leaving directory `/home/tmomas/openwrt/14.07'
make: *** [package/temper7402/install] Error 2

The section of atmoslog.c gcc is complaining about:

    if (debug) {
        for (i = 0; i < reqIntLen; i++)
            printf("%02x ",question[i] & 0xFF);

        printf("\n");
    }

I already googled "warning: iteration 2u invokes undefined behavior" and got some answers, however, since I'm not programming in C and not used to such compile erros, I don't know how to solve this.

Can someone point me in the right direction, please?

[1] https://github.com/joeyloman/atmoslog

The warning is "harmless" (as in: does not halt the compilation), the actual error is that a wrong "strip" is called later on. You need to patch the Makefile to not invoke "strip" manually.

Taking out the strip command did it.

Thanks! smile

The discussion might have continued from here.