Hi all,

I have the following issue here on aarch64-*-freebsd:

(sorry if the format is hardly readable)

......
/export/devel/net/src/gcc/head/gcc/gcc/config/aarch64/aarch64.c: In function 'void aarch64_elf_asm_destructor(rtx, int)': /export/devel/net/src/gcc/head/gcc/gcc/config/aarch64/aarch64.c:5760:1: error: %.5u' directive output may be truncated writing between 5 and 10 bytes into a region of size 6 [-Werror=format-truncation=]
 aarch64_elf_asm_destructor (rtx symbol, int priority)
 ^~~~~~~~~~~~~~~~~~~~~~~~~~
/export/devel/net/src/gcc/head/gcc/gcc/config/aarch64/aarch64.c:5760:1: note: using the range [1, 4294967295] for directive argument /export/devel/net/src/gcc/head/gcc/gcc/config/aarch64/aarch64.c:5768:65: note: format output between 18 and 23 bytes into a destination of size 18
       snprintf (buf, sizeof (buf), ".fini_array.%.5u", priority);

                                                                ^
.......

This is the code snippet, it does not only occur in aarch64, but also at least in pa and avr.

----
static void
aarch64_elf_asm_destructor (rtx symbol, unsigned short priority)
{
  if (priority == DEFAULT_INIT_PRIORITY)
    default_dtor_section_asm_out_destructor (symbol, priority);
  else
    {
      section *s;
      char buf[18];
      snprintf (buf, sizeof (buf), ".fini_array.%.5u", priority);
      s = get_section (buf, SECTION_WRITE, NULL);
      switch_to_section (s);
      assemble_align (POINTER_SIZE);
      assemble_aligned_integer (POINTER_BYTES, symbol);
    }
}
----

I have now four options to solve this, (a fifth one would be to remove format-truncation from -Wall/Wextra?)

1.) increase buf to 23
2.) use %.5hu in snprintf
3.) cast priority in snprintf to (unsigned int)
4.) make priority unsigned short.

Solution 1, 2 and 3 work, but with pros and cons.

The last option is the cleanest one, but it involves changing priority everywhere in the gcc/gcc sources. I started and saw how many places I have to change.... before I continue I would like to ask you guys, which one is the prefered solution?

Thanks for feedback.
Andreas

Reply via email to