This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

fix latent bug in strstr.c testcase

I found this while trying to backport some testcases to an older

The execute/builtins/strstr.c testcase has a bug in the strstr()
function which is in the lib/strstr.c file.  The exit condition is
wrong.  We exit with success if we reach the end of the second string. 
It is not necessary to reach the end of the first string.

This works in mainline by accident.  Even when compiling with -O0, the
strstr calls with a NULL substring get optimized away, the strstr calls
with a single char substring get optimized into strchr calls, and the
remaining strstr calls all use a substring which matches the tail end of
the first string argument, which happens to work with the broken exit
test.  And thus the testcase works at all optimizations levels.

With an older compiler, the testcase fails at -O0 because we aren't
optimizing any of the strstr calls.

You can see the problem on mainline if you compile the testcase with
-fno-builtin.  With this patch, it now also works with -fno-builtin.

This was tested with an x86_64-linux build and make check.  There were
no changes to the testsuite results.

I have checked in this patch.
Jim Wilson, GNU Tools Support,

Attachment: patch.lib.strstr
Description: Text document

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]