Boost logo

Boost :

From: John Nagle (nagle_at_[hidden])
Date: 2004-05-06 13:35:26


Reece Dunn wrote:
> John Nagle wrote:
>
>> Reece Dunn wrote:
>>
>>> There is currently a static-sized array in the Boost library that
>>> allows you to operate on arrays of fixed size. I was wondering if
>>> something similar exists for strings, in particular, providing
>>> buffer-overflow safe string operations.
>>>
>>> I have an nstring< std::size_t n > string class that provides
>>> size-safe copying and comparison, allowing for you to do things like:

OK, thanks. First bug reports:

1. Compile problems under VC++ 6:

        No include brings in "std::size_t".
        
2. VC++ 6.x complains about references to a zero-sized array for

           template< std::size_t m >
           inline void copy( const char( & s )[ m ] )
           {
              copy( s, m );
           }

    This may be a VC++ 6.x issue, but if it's possible to keep
VC++ 6 happy, it's worth doing. There's a big installed base.

3. "copy" function does not place a trailing null in the string.

           inline void copy( const char * s )
           {
              copy( s, ::strlen( s ));
           }

    Note that "strlen" returns a count that does NOT contain the null.

    All the operations should guarantee that the string remains null
terminated. A constructor should be provided, but all it has to
do is put a null in the first character position.

    As for the naming issue, the important thing for retrofit work
is that it should be possible to write a "using" statement that makes
"strcopy", "sprintf", for char_string etc. valid without prefixes, and
doesn't break anything else. You should be able to include something
("safe_strings.hpp"?) that does as much as possible to fix old code.

This is a good start, and not hard to fix. I look forward to the
next round.

                                John Nagle


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