Message ID | 20200210140749.GN17695@tucnak |
---|---|
State | New |
Headers | show |
Series | [committed] i386: Fix strncmp last arguments in x86_64_elf_section_type_flags [PR93641] | expand |
On Mon, Feb 10, 2020 at 03:07:49PM +0100, Jakub Jelinek wrote:
> + || strncmp (name, ".lbss.", sizeof (".lbss.") - 1) == 0
You can just use strlen (".lbss.") which is nicer to read and compiles
to the same thing?
Segher
On Mon, Feb 10, 2020 at 12:00:28PM -0600, Segher Boessenkool wrote: > On Mon, Feb 10, 2020 at 03:07:49PM +0100, Jakub Jelinek wrote: > > + || strncmp (name, ".lbss.", sizeof (".lbss.") - 1) == 0 > > You can just use strlen (".lbss.") which is nicer to read and compiles > to the same thing? By GCC yes, non-GCC compilers might not. Though admittedly, we probably don't care. We use sizeof ("...") - 1 or sizeof "..." - 1 in a lot of places though. gcc.c: && (p1[sizeof "%include" - 1] == ' ' gcc.c: || p1[sizeof "%include" - 1] == '\t')) gcc.c: else if (!strncmp (p1, "%include_noerr", sizeof "%include_noerr" - 1) gcc.c: && (p1[sizeof "%include_noerr" - 1] == ' ' gcc.c: || p1[sizeof "%include_noerr" - 1] == '\t')) gcc.c: else if (!strncmp (p1, "%rename", sizeof "%rename" - 1) gcc.c: && (p1[sizeof "%rename" - 1] == ' ' gcc.c: || p1[sizeof "%rename" - 1] == '\t')) gcc.c: if (sl->name_len == sizeof "self_spec" - 1 c-family/c-format.c: if (!strncmp (format_chars, "__attribute", sizeof "__attribute" - 1)) c-family/c-format.c: unsigned nchars = sizeof "__attribute" - 1; c-family/c-format.c: && (!strncmp (format_chars + 2, "atomic", sizeof "atomic" - 1) c-family/c-format.c: || !strncmp (format_chars + 2, "builtin", sizeof "builtin" - 1) c-family/c-format.c: || !strncmp (format_chars + 2, "sync", sizeof "sync" - 1))) [jakub@tucnak gcc]$ grep 'sizeof ("[^"]*") - 1' *.[ch] */*.[ch] */*/*.[ch] asan.c: name[sizeof ("__odr_asan") - 1] = '.'; asan.c: name[sizeof ("__odr_asan") - 1] = '$'; collect2.c: if (strncmp (name, "not found", sizeof ("not found") - 1) == 0) gcc.c: if (!strncmp (p1, "%include", sizeof ("%include") - 1) gcc.c: if (len > (int) sizeof ("/lib/gcc/") - 1 gcc.c: len -= sizeof ("/lib/gcc/") - 1; gcc.c: sizeof ("COLLECT_GCC_OPTIONS=") - 1); gcc.c: obstack_grow (&collect_obstack, "COLLECT_GCC=", sizeof ("COLLECT_GCC=") - 1); gcc.c: sizeof ("COLLECT_LTO_WRAPPER=") - 1); gcc.c: sizeof ("OFFLOAD_TARGET_NAMES=") - 1); lto-wrapper.c: sizeof ("-foffload-objects=") - 1) == 0) lto-wrapper.c: = argv[i] + sizeof ("-foffload-objects=") - 1; c/c-parser.c: + sizeof ("omp declare reduction ") - 1, fortran/module.c: const char *p = name + sizeof ("operator ") - 1; fortran/trans-io.c: memcpy (name + sizeof ("__st_parameter_") - 1, st_parameter[ptype].name, config/arm/driver-arm.c: if (strncmp (buf, "CPU implementer", sizeof ("CPU implementer") - 1) == 0) config/arm/driver-arm.c: if (strncmp (buf, "CPU part", sizeof ("CPU part") - 1) == 0) config/frv/frv.h: sizeof ("__trampoline_setup bad size\n") - 1); \ config/frv/frv.h: sizeof ("__trampoline_setup bad size\n") - 1); \ config/i386/i386.c: || strncmp (name, ".lbss.", sizeof (".lbss.") - 1) == 0 config/i386/i386.c: sizeof (".gnu.linkonce.lb.") - 1) == 0) config/mips/driver-native.c: if (strncmp (buf, "cpu model", sizeof ("cpu model") - 1) == 0) config/msp430/msp430.c: sizeof ("__mspabi_mpy") - 1) == 0; config/msp430/msp430-devices.c: if (len > (int) sizeof ("/lib/gcc/") - 1 config/msp430/msp430-devices.c: len -= sizeof ("/lib/gcc/") - 1; config/pa/som.h: sizeof ("shared library list:") - 1) == 0) \ config/pa/som.h: sizeof ("shared library binding:") - 1) == 0)\ config/pa/som.h: sizeof ("static branch prediction disabled") - 1) == 0)\ config/pa/som.h: && strncmp (PTR, "dynamic", sizeof ("dynamic") - 1) == 0) \ config/pa/som.h: PTR += sizeof ("dynamic") - 1; \ config/pa/som.h: && strncmp (PTR, "static", sizeof ("static") - 1) == 0) \ config/pa/som.h: PTR += sizeof ("static") - 1; \ config/rs6000/rs6000.c: spaces += sizeof (" Reload=sl") - 1; config/rs6000/rs6000.c: spaces += sizeof (" Upper=y") - 1; config/rs6000/rs6000.c: strcpy (name, bname + sizeof ("__builtin_") - 1); config/rs6000/rs6000.c: len += sizeof ("no-") - 1; config/rs6000/rs6000.c: len += sizeof ("no-") - 1; config/rs6000/rs6000.c: comma_len = sizeof (", ") - 1; config/sparc/driver-sparc.c: if (strncmp (buf, "cpu\t\t:", sizeof ("cpu\t\t:") - 1) == 0) Jakub
On Mon, Feb 10, 2020 at 07:07:46PM +0100, Jakub Jelinek wrote: > We use sizeof ("...") - 1 or sizeof "..." - 1 in a lot of places though. [...] > config/rs6000/rs6000.c: spaces += sizeof (" Reload=sl") - 1; > config/rs6000/rs6000.c: spaces += sizeof (" Upper=y") - 1; > config/rs6000/rs6000.c: strcpy (name, bname + sizeof ("__builtin_") - 1); > config/rs6000/rs6000.c: len += sizeof ("no-") - 1; > config/rs6000/rs6000.c: len += sizeof ("no-") - 1; > config/rs6000/rs6000.c: comma_len = sizeof (", ") - 1; Okay, I fixed those :-) Segher
--- gcc/config/i386/i386.c.jj 2020-02-07 19:11:57.378982855 +0100 +++ gcc/config/i386/i386.c 2020-02-10 09:24:18.247860282 +0100 @@ -751,8 +751,9 @@ x86_64_elf_section_type_flags (tree decl flags |= SECTION_RELRO; if (strcmp (name, ".lbss") == 0 - || strncmp (name, ".lbss.", 5) == 0 - || strncmp (name, ".gnu.linkonce.lb.", 16) == 0) + || strncmp (name, ".lbss.", sizeof (".lbss.") - 1) == 0 + || strncmp (name, ".gnu.linkonce.lb.", + sizeof (".gnu.linkonce.lb.") - 1) == 0) flags |= SECTION_BSS; return flags;