[Piglit] [PATCH] Fix infinite loop in piglit_is_extension_in_string.

Paul Berry stereotype441 at gmail.com
Tue Dec 20 08:19:57 PST 2011


On 20 December 2011 06:56, Brian Paul <brianp at vmware.com> wrote:

> On 12/19/2011 10:46 PM, Paul Berry wrote:
>
>> If piglit_is_extension_in_string(**) finds an extension whose name
>> begins with the name it is searching for, but is not equal to the name
>> it is searching for (e.g. it is searching for EXT_transform_feedback
>> but it finds EXT_transform_feedback2), we need it to advance by one
>> character before restarting the search, otherwise it will loop
>> indefinitely.
>>
>> Prevents a hang when running some transform feedback tests on nVidia's
>> proprietary Linux driver.
>> ---
>>  tests/util/piglit-util.c |   16 ++++++++++++----
>>  1 files changed, 12 insertions(+), 4 deletions(-)
>>
>> diff --git a/tests/util/piglit-util.c b/tests/util/piglit-util.c
>> index 65b02f5..3241528 100644
>> --- a/tests/util/piglit-util.c
>> +++ b/tests/util/piglit-util.c
>> @@ -145,15 +145,23 @@ bool piglit_is_extension_in_string(**const char
>> *haystack, const char *needle)
>>        if (needle_len == 0)
>>                return false;
>>
>> -       while (haystack != NULL) {
>> +       while (true) {
>>                const char *const s = strstr(haystack, needle);
>>
>> -               if (s != NULL
>> -               &&  (s[needle_len] == ' ' || s[needle_len] == '\0')) {
>> +               if (s == NULL)
>> +                       return false;
>> +
>> +               if (s[needle_len] == ' ' || s[needle_len] == '\0') {
>>                        return true;
>>                }
>>
>> -               haystack = s;
>> +               /* strstr found an extension whose name begins with
>> +                * needle, but whose name is not equal to needle.
>> +                * Restart the search at s + 1 so that we don't just
>> +                * find the same extension again and go into an
>> +                * infinite loop.
>> +                */
>> +               haystack = s + 1;
>>
>
> Actually, I think you could do "haystack = s + needle_len" but it's no big
> deal.
>

Oh yeah.  That's a better idea.


>
>         }
>>
>>        return false;
>>
>
> -Brian
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/piglit/attachments/20111220/fa121143/attachment.html>


More information about the Piglit mailing list