bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bash-4.3 bug report


From: Chet Ramey
Subject: Re: bash-4.3 bug report
Date: Mon, 14 Apr 2014 11:54:39 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.4.0

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 4/14/14, 11:19 AM, Eric Blake wrote:
> On 04/14/2014 08:50 AM, Chet Ramey wrote:
>> On 4/14/14, 5:34 AM, David Binderman wrote:
>>> Hello there,
>>>
>>>  [bind.c:2238]: (style) Array index 'j' is used before limits check.
>>>
>>> Source code is
>>>
>>>           for (j = 0; invokers[j] && j < 5; j++)
>>>
>>> Suggest new code
>>>
>>>           for (j = 0; (j < 5) && (invokers[j] != NULL); j++)
>>
>> Can you give me a use case for which this makes a difference?
> 
> It silences static code checkers and avoids undefined C behavior.

Sorry, I just don't see it.  Maybe I'm missing the undefined C behavior
part.  `invokers' is a pointer to an array of strings that is guaranteed
to be null-terminated; we only want to print at most five members.  Say
there are fewer than five strings: the loop will break when it encounters
the null terminator.  Say there are more: the loop will break after
printing five strings.

Say there are four or fewer strings; the loop will break when invokers[j]
== 0.  Say there are five strings; the loop will break when j == 5 because
invokers[5] == 0.  Say there are six or more strings; the loop will break
when j == 5 because j >= 5, but invokers[j] will be valid.

I'm a little under the weather this morning, and a little sluggish, but I
just don't see the problem.

- -- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (Darwin)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlNMBL8ACgkQu1hp8GTqdKsl/ACfaCrH+WlQMMTOYuR7F5L4NbVV
R3wAn12agFbUzk74mtnWndgaBxaCRui8
=GpJQ
-----END PGP SIGNATURE-----



reply via email to

[Prev in Thread] Current Thread [Next in Thread]