NetBSD-Bugs archive

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

toolchain/53618: bogus warnings from printf %u and ntohs with -O1



>Number:         53618
>Category:       toolchain
>Synopsis:       bogus warnings from printf %u and ntohs with -O1
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    toolchain-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Sep 19 03:40:00 +0000 2018
>Originator:     Hal Murray
>Release:        8.0
>Organization:
>Environment:
NetBSD bob3.example.com 8.0 NetBSD 8.0 (GENERIC) #0: Tue Jul 17 14:59:51 UTC 2018  mkrepro%mkrepro.NetBSD.org@localhost:/usr/src/sys/arch/amd64/compile/GENERIC amd64

>Description:
The test case below gets warnings like the following:

foo.c:17:10: warning: format '%u' expects argument of type 'unsigned int', but argument 2 has type 'int' [-Wformat=]
   printf("Foo %u\n", ntohs(x));

ntohs is unsigned, so I don't expect any problems.

It needs -Wformat -Wformat-signedness to correctly generate the warnings.  Adding -O1 generates the bogus warnings.

>How-To-Repeat:
/*
  save this as foo.c
  Gets bogus warnings from ntohs/htons when built with
    gcc -Wformat -Wformat-signedness -O1 foo.c
  Works OK with
    gcc -Wformat -Wformat-signedness foo.c
*/

#include <stdio.h>
#include <arpa/inet.h>

int main (int argc, char *argv[])
{
  uint16_t x = 13;
  int y = 13;
  printf("Yyy %u\n", y);        /* I expect this to get an error */
  printf("Y13 %u\n", 13);
  printf("Foo %u\n", ntohs(x));
  printf("Bar %u\n", htons(x));
}

>Fix:



Home | Main Index | Thread Index | Old Index