| 1 |
/* Test case derived from Binutils/GDB's readline/readline/histexpand.c. |
| 2 |
{ dg-do compile } |
| 3 |
{ dg-options "-O2 -Wall" } */ |
| 4 |
|
| 5 |
char * |
| 6 |
get_subst_pattern (char *str, int *iptr, int delimiter, int is_rhs, int *lenptr) |
| 7 |
{ |
| 8 |
int si, i, j, k; |
| 9 |
char *s; |
| 10 |
|
| 11 |
s = 0; |
| 12 |
i = *iptr; |
| 13 |
|
| 14 |
for (si = i; str[si] && str[si] != delimiter; si++) |
| 15 |
if (str[si] == '\\' && str[si + 1] == delimiter) |
| 16 |
si++; |
| 17 |
|
| 18 |
if (si > i || is_rhs) |
| 19 |
{ |
| 20 |
s = (char *)__builtin_malloc (si - i + 1); |
| 21 |
for (j = 0, k = i; k < si; j++, k++) |
| 22 |
{ |
| 23 |
/* Remove a backslash quoting the search string delimiter. */ |
| 24 |
if (str[k] == '\\' && str[k + 1] == delimiter) |
| 25 |
k++; |
| 26 |
s[j] = str[k]; // { dg-bogus "-Wstringop-overflow" } |
| 27 |
} |
| 28 |
s[j] = '\0'; |
| 29 |
if (lenptr) |
| 30 |
*lenptr = j; |
| 31 |
} |
| 32 |
|
| 33 |
return s; |
| 34 |
} |