Pacify gcc 14 -Wanalyzer-infinite-loop
* gnulib.modules: Add stddef, for ‘unreachable’. * src/compare.c (dumpdir_cmp): Tell GCC that the default case is unreachable. Make just one pass through the string, instead of two passes (one via strcmp, another via strlen).
This commit is contained in:
@@ -92,6 +92,7 @@ setenv
|
||||
snprintf
|
||||
stat-time
|
||||
stdbool
|
||||
stddef
|
||||
stdint
|
||||
stpcpy
|
||||
stdopen
|
||||
|
||||
@@ -334,34 +334,37 @@ diff_special (void)
|
||||
static int
|
||||
dumpdir_cmp (const char *a, const char *b)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
while (*a)
|
||||
switch (*a)
|
||||
{
|
||||
case 'Y':
|
||||
case 'N':
|
||||
if (!strchr ("YN", *b))
|
||||
/* If the null-terminated strings A and B are equal, other
|
||||
than possibly A's first byte being 'Y' where B's is 'N' or
|
||||
vice versa, advance A and B past the strings.
|
||||
Otherwise, return 1. */
|
||||
if (! (*b == 'Y' || *b == 'N'))
|
||||
return 1;
|
||||
if (strcmp(a + 1, b + 1))
|
||||
return 1;
|
||||
len = strlen (a) + 1;
|
||||
a += len;
|
||||
b += len;
|
||||
break;
|
||||
|
||||
a++, b++;
|
||||
FALLTHROUGH;
|
||||
case 'D':
|
||||
if (strcmp(a, b))
|
||||
/* If the null-terminated strings A and B are equal, advance A
|
||||
and B past them. Otherwise, return 1. */
|
||||
while (*a)
|
||||
if (*a++ != *b++)
|
||||
return 1;
|
||||
if (*b)
|
||||
return 1;
|
||||
len = strlen (a) + 1;
|
||||
a += len;
|
||||
b += len;
|
||||
a++, b++;
|
||||
break;
|
||||
|
||||
case 'R':
|
||||
case 'T':
|
||||
case 'X':
|
||||
return *b;
|
||||
|
||||
default:
|
||||
unreachable ();
|
||||
}
|
||||
return *b;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user