Boost logo

Boost :

From: Jonathan Wakely (cow_at_[hidden])
Date: 2008-02-10 09:57:50


On Sun, Feb 10, 2008 at 02:37:41PM +0000, Jonathan Wakely wrote:
>
> In libs/date_time/src/gregorian/greg_month.cpp we have:
>
> short i = date_time::find_match(special_value_names,
> special_value_names,
> date_time::NumSpecialValues,
> s);
>
> This results in a read past the end of the array. I believe the caller
> should pass NumSpecialValues-1 and the error check after it should be
>
> if(i >= date_time::NumSpecialValues) { // match not found

It might help if the comment on find_match() was clearer:

    /*! find_match searches both arrays for a match to 's'. Indexing of the
     * arrays is from 0 to 'limit'. The index of the match is returned.

Is that [0,limit) or [0,limit] ?
The code does [0,limit] so the comment should say so.

     * Ex. "Jan" returns 0, "Dec" returns 11, "Tue" returns 2.
     * 'limit' can be sent in with: greg_month::max(),
     * greg_weekday::max() or date_time::NumSpecialValues */

The special_value_names array has NumSpecialValues members, so
NumSpecialValues is not a valid index.

Now I think about it, is greg_month::max() even a valid index?
greg_month::max() is 12, but the array of month names has 12 members, so
should be indexed [0,11] and similarly for greg_weekday::max().

Seems to me 'limit' should be sent in with
greg_month::max() - greg_month::min(), given how constrained_value
works. Either that or find_match() should be changed.

Jon


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk