[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#864500: cpp-4.9: warnings from assert(strncmp(...) == 0) when using -O



Package: cpp-4.9
Version: 4.9.2-10
Severity: minor

The following program, 

    #include <string.h>
    #include <assert.h>
    int main() {
        const char *a = "xyz", *b = a;
        assert(strncmp(a, b, 3) == 0);
        return 0;
    }

compiles fine with
        "gcc -Wall -ansi -pedantic -W    program.c",
but emits a warning when compiled with
        "gcc -Wall -ansi -pedantic -W -O program.c",
namely

program.c: In function 'main':
program.c:6:5: warning: string length '2172' is greater than the length '509' ISO C90 compilers are required to support [-Woverlength-strings]
     assert(strncmp(a, b, 3) == 0);
     ^

The reason is that the -O option makes cpp expand "strncmp(a, b, 3)" into an
inline monster.

Best regards,
        g.

-- System Information:
Debian Release: 8.8
  APT prefers stable
  APT policy: (500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 3.16.0-4-amd64 (SMP w/2 CPU cores)
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968)
Shell: /bin/sh linked to /bin/dash
Init: sysvinit (via /sbin/init)

Versions of packages cpp-4.9 depends on:
ii  gcc-4.9-base   4.9.2-10
ii  libc6          2.19-18+deb8u9
ii  libcloog-isl4  0.18.2-1+b2
ii  libgmp10       2:6.0.0+dfsg-6
ii  libisl10       0.12.2-2
ii  libmpc3        1.0.2-1
ii  libmpfr4       3.1.2-2
ii  zlib1g         1:1.2.8.dfsg-2+b1

cpp-4.9 recommends no packages.

Versions of packages cpp-4.9 suggests:
pn  gcc-4.9-locales  <none>

-- no debconf information


Reply to: