libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / Wstringop-overflow-51.c
blob6f36643c8bb60216f0b955244cce9bdb393ce8fe
1 /* Test case derived from Binutils/GDB's readline/readline/histexpand.c.
2 { dg-do compile }
3 { dg-options "-O2 -Wall" } */
5 char *
6 get_subst_pattern (char *str, int *iptr, int delimiter, int is_rhs, int *lenptr)
8 int si, i, j, k;
9 char *s;
11 s = 0;
12 i = *iptr;
14 for (si = i; str[si] && str[si] != delimiter; si++)
15 if (str[si] == '\\' && str[si + 1] == delimiter)
16 si++;
18 if (si > i || is_rhs)
20 s = (char *)__builtin_malloc (si - i + 1);
21 for (j = 0, k = i; k < si; j++, k++)
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" }
28 s[j] = '\0';
29 if (lenptr)
30 *lenptr = j;
33 return s;