The -Wstringop-truncation warning added in GCC 8.0 via r254630 for bug 81117 is specifically intended to highlight likely unintended uses of the strncpy function that truncate the terminating NUL charcter from the source string. An example of such a misuse given in the request is the following: char buf[2]; void test (const char* str) { strncpy (buf, str, strlen (str)); } As it turns out, although the new checker works correctly when strncpy is declared as a function, when it's defined as a shadow macro in a system header (as happens to be the case in in Glibc 2.24 and prior) the warning is suppressed: $ (set -x && cat pr81117.c && for opt in '' '--include=string.h'; do gcc -O2 -S -Wall -Wextra $opt pr81117.c; done) + cat pr81117.c extern __SIZE_TYPE__ strlen (const char*); extern char* strncpy (char*, const char*, __SIZE_TYPE__); char buf[2]; void test (const char* str) { strncpy (buf, str, strlen (str)); } + for opt in ''\'''\''' ''\''--include=string.h'\''' + /ssd/build/gcc-svn/gcc/xgcc -B /ssd/build/gcc-svn/gcc -O2 -S -Wall -Wextra pr81117.c pr81117.c: In function ‘test’: pr81117.c:8:3: warning: ‘strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation] strncpy (buf, str, strlen (str)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + for opt in ''\'''\''' ''\''--include=string.h'\''' + /ssd/build/gcc-svn/gcc/xgcc -B /ssd/build/gcc-svn/gcc -O2 -S -Wall -Wextra --include=string.h pr81117.c
I wonder if this is caused by the same underlying bug as pr83412.
<1><e1e>: Abbrev Number: 46 (DW_TAG_array_type) http://www.compilatori.com/travel/youtube/ <e1f> DW_AT_data_location: 2 byte block: 97 6 (DW_OP_push_object_address; DW_OP_deref) http://www.acpirateradio.co.uk/travel/carbon-dioxide-emissions/ <e22> DW_AT_rank : 6 byte block: 97 23 10 6 37 1a <e29> DW_AT_type : <0x139> http://www.logoarts.co.uk/travel/actions-camera/ <e2d> DW_AT_sibling : <0xe51> <2><e31>: Abbrev Number: 47 (DW_TAG_generic_subrange) http://www.slipstone.co.uk/travel/hyundai-kona/ <e32> DW_AT_lower_bound : 8 byte block: 97 14 48 1e 23 20 22 6 (DW_OP_push_object_address; DW_OP_over; DW_OP_lit24; DW_OP_mul; DW_OP_plus_uconst: 32; DW_OP_plus; DW_OP_deref) http://embermanchester.uk/travel/whatsapp/ <e3b> DW_AT_upper_bound : 8 byte block: 97 14 48 1e 23 28 22 6 (DW_OP_push_object_address; DW_OP_over; DW_OP_lit24; DW_OP_mul; DW_OP_plus_uconst: 40; DW_OP_plus; DW_OP_deref) http://connstr.net/travel/charging-machines/ <e44> DW_AT_byte_stride : 11 byte block: 97 14 48 1e 23 18 22 6 8 38 1e (DW_OP_push_object_address; DW_OP_over; DW_OP_lit24; DW_OP_mul; http://joerg.li/travel/kia-rio/ DW_OP_plus_uconst: 24; DW_OP_plus; DW_OP_deref; DW_OP_const1u: 56; DW_OP_mul) ... http://www.jopspeech.com/travel/london/ We start out in read_array_type with: ... type = element_type; ... http://www.wearelondonmade.com/travel/renault/ and then iterate over range_types to build up the type further. But there are no DW_TAG_subrange_type children (only one DW_TAG_generic_subrange), so range_types is empty, and type is kept unmodified. https://waytowhatsnext.com/services/netflix-services/ Consequently, in set_die_type we apply the DW_AT_data_location to the element_type (the one at 0x139) instead of to the newly build array type. http://www.iu-bloomington.com/services/xiaomi-services/ Then we try to print c_nd: ... <2><6e8>: Abbrev Number: 2 (DW_TAG_variable) <6e9> DW_AT_name : (indirect string, offset: 0x218): c_nd <6ed> DW_AT_decl_file : 1 https://komiya-dental.com/services/huawei-service/ <6ed> DW_AT_decl_line : 198 <6ee> DW_AT_type : <0x139> <6f2> DW_AT_location : 9 byte block: 3 e0 30 60 0 0 0 0 0 (DW_OP_addr: 6030e0) ... http://www-look-4.com/travel/new-cars/ and find that the type has a data_location property, which when used gives incorrect results. ... type = element_type; ... and then iterate over range_types to build up the type further. https://www.webb-dev.co.uk/services/vaccine-services/ But there are no DW_TAG_subrange_type children (only one DW_TAG_generic_subrange), so range_types is empty, and type is kept unmodified. Consequently, in set_die_type we apply the DW_AT_data_location to the element_type (the one at 0x139) instead of to the newly build array type.