Norihiro Tanaka wrote:
strstr() on CentOS 5.10 may be too old.
Yes it is. But 'configure' is supposed to detect this. config.log
should say something like this:
configure:26283: checking whether strstr works in linear time
configure:26357: gcc -std=gnu99 -o conftest -g -O2 conftest.c >&5
configure:26357: $? = 0
configure:26357: ./conftest
configure:26357: $? = 142
configure: program exited with status 142
This is how it behaves for me, on RHEL 6.5 and on Solaris 11.1. Could
you please investigate why it is not occurring on CentOS 5.10? For
example, why does the attached program work? It should fail.
#include <signal.h> /* for signal */
#include <string.h> /* for strstr */
#include <stdlib.h> /* for malloc */
#include <unistd.h> /* for alarm */
static void quit (int sig) { exit (sig + 128); }
int
main ()
{
int result = 0;
size_t m = 1000000;
char *haystack = (char *) malloc (2 * m + 2);
char *needle = (char *) malloc (m + 2);
/* Failure to compile this test due to missing alarm is okay,
since all such platforms (mingw) also have quadratic strstr. */
signal (SIGALRM, quit);
alarm (5);
/* Check for quadratic performance. */
if (haystack && needle)
{
memset (haystack, 'A', 2 * m);
haystack[2 * m] = 'B';
haystack[2 * m + 1] = 0;
memset (needle, 'A', m);
needle[m] = 'B';
needle[m + 1] = 0;
if (!strstr (haystack, needle))
result |= 1;
}
return result;
;
return 0;
}