Bug#808861: clang: Recommends bad format specifier for USHRT_MAX constant

David McMackins contact at mcmackins.org
Wed Dec 23 21:11:54 UTC 2015


Package: clang
Version: 1:3.6-32
Severity: minor

Dear Maintainer,

Consider the following program:

```
#include <limits.h>
#include <stdio.h>

int
main (void)
{
  printf ("%hu\n", USHRT_MAX);
  return 0;
}
```

If I compile this with clang (tested with -std=c11 but might be present
with other standards), I will get a warning about using the %hu format
specifier, since the definition of USHRT_MAX is identified as an int
(from a quick check of the header file, it uses arithmetic to determine it).

However, the minimum size of an int is 16 bits, as is an unsigned short.
That being the case, using a %d specifier as the warning recommends
could cause bad output. If both int and unsigned short are of the same
length on an implementation, then that format specifier would read an
unsigned 16-bit integer value as a signed 16-bit integer value,
resulting in incorrect output.

On implementations like mine where int is 32 bits wide, this wouldn't be
harmful, but the standard says that this could technically be a problem.

-- System Information:
Debian Release: stretch/sid
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: amd64 (x86_64)

Kernel: Linux 4.3.0-1-amd64 (SMP w/4 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages clang depends on:
ii  clang-3.6  1:3.6.2-3

clang recommends no packages.

clang suggests no packages.

-- no debconf information


Happy Hacking,

David E. McMackins II
Associate, Free Software Foundation (#12889)

www.mcmackins.org www.delwink.com
www.gnu.org www.fsf.org



More information about the Pkg-llvm-team mailing list