| 1 |
/* Reduced from haproxy-2.7.1's cfgparse.c. */ |
| 2 |
|
| 3 |
/* { dg-additional-options "-Wno-analyzer-too-complex -Wno-analyzer-symbol-too-complex" } */ |
| 4 |
|
| 5 |
typedef __SIZE_TYPE__ size_t; |
| 6 |
|
| 7 |
extern int |
| 8 |
strcmp(const char* __s1, const char* __s2) |
| 9 |
__attribute__((__nothrow__, __leaf__)) __attribute__((__pure__)) |
| 10 |
__attribute__((__nonnull__(1, 2))); |
| 11 |
|
| 12 |
extern int |
| 13 |
strncmp(const char* __s1, const char* __s2, size_t __n) |
| 14 |
__attribute__((__nothrow__, __leaf__)) __attribute__((__pure__)) |
| 15 |
__attribute__((__nonnull__(1, 2))); |
| 16 |
|
| 17 |
enum |
| 18 |
{ |
| 19 |
/* [...snip...] */ |
| 20 |
_ISdigit = ((3) < 8 ? ((1 << (3)) << 8) : ((1 << (3)) >> 8)), |
| 21 |
/* [...snip...] */ |
| 22 |
}; |
| 23 |
|
| 24 |
extern const unsigned short int** |
| 25 |
__ctype_b_loc(void) __attribute__((__nothrow__, __leaf__)) |
| 26 |
__attribute__((__const__)); |
| 27 |
|
| 28 |
unsigned int str2uic(const char* s); |
| 29 |
|
| 30 |
char* |
| 31 |
memprintf(char** out, const char* format, ...) |
| 32 |
__attribute__((format(printf, 2, 3))); |
| 33 |
|
| 34 |
int |
| 35 |
parse_process_number(const char* arg, |
| 36 |
unsigned long* proc, |
| 37 |
int max, |
| 38 |
int* autoinc, |
| 39 |
char** err) |
| 40 |
{ |
| 41 |
if (autoinc) { |
| 42 |
*autoinc = 0; |
| 43 |
if (strncmp(arg, "auto:", 5) == 0) { |
| 44 |
arg += 5; |
| 45 |
*autoinc = 1; |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
if (strcmp(arg, "all") == 0) /* { dg-bogus "pointer 'dash' is dereferenced here" } */ |
| 50 |
*proc |= ~0UL; |
| 51 |
else if (strcmp(arg, "odd") == 0) |
| 52 |
*proc |= ~0UL / 3UL; |
| 53 |
else if (strcmp(arg, "even") == 0) |
| 54 |
*proc |= (~0UL / 3UL) << 1; |
| 55 |
else { |
| 56 |
const char *p, *dash = (const char *) ((void*)0); |
| 57 |
unsigned int low, high; |
| 58 |
|
| 59 |
for (p = arg; *p; p++) { |
| 60 |
if (*p == '-' && !dash) /* { dg-bogus "check of 'dash' for NULL after already dereferencing it" } */ |
| 61 |
dash = p; |
| 62 |
else if (!((*__ctype_b_loc())[(int)(((unsigned char)*p))] & |
| 63 |
(unsigned short int)_ISdigit)) { |
| 64 |
memprintf(err, "'%s' is not a valid number/range.", arg); |
| 65 |
return -1; |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
low = high = str2uic(arg); |
| 70 |
if (dash) /* { dg-bogus "check of 'dash' for NULL after already dereferencing it" } */ |
| 71 |
high = ((!*(dash + 1)) ? max : str2uic(dash + 1)); |
| 72 |
|
| 73 |
if (high < low) { |
| 74 |
unsigned int swap = low; |
| 75 |
low = high; |
| 76 |
high = swap; |
| 77 |
} |
| 78 |
|
| 79 |
if (low < 1 || low > max || high > max) { |
| 80 |
memprintf(err, |
| 81 |
"'%s' is not a valid number/range." |
| 82 |
" It supports numbers from 1 to %d.\n", |
| 83 |
arg, |
| 84 |
max); |
| 85 |
return 1; |
| 86 |
} |
| 87 |
|
| 88 |
for (; low <= high; low++) |
| 89 |
*proc |= 1UL << (low - 1); |
| 90 |
} |
| 91 |
*proc &= ~0UL >> (((unsigned int)sizeof(long) * 8) - max); |
| 92 |
|
| 93 |
return 0; |
| 94 |
} |