This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [PATCH] Avoid strtok for thread safety
Hi Paolo,
I understand that you're not introducing new bugs, but we need to fix
any we find as we go along. I'm thinking something like this:
{
size_t __i = 0;
const char* __save = __s;
while (__i < _S_categories_size + _S_extra_categories_size)
{
char* __next = __save + strcspn(__save, "=;");
char* __new = new char[__next - __save + 1];
memcpy(__new, __save, __next - __save);
__new[__next - __save] = '\0';
_M_names[__i] = __new;
++__i;
__save = __next;
if (*__save == '\0')
break;
++__save;
}
if (__i != _S_categories_size + _S_extra_categories_size ||
*__save != '\0')
throw runtime_error();
}
Again, untested, but maybe better than my last posting.
(The exception chosen, "runtime error", is according to Josuttis.
I don't have the standard handy at the moment.)
Nathan Myers
ncm-nospam@cantrip.org
On Wed, Nov 27, 2002 at 01:02:24AM +0100, Paolo Carlini wrote:
> Nathan Myers wrote:
>
> >strpbrk() returns NULL if it doesn't find any of the characters
> >searched for. What happens then?
> >
> Everything can happen, probably a segmentation fault. There are no checks on
> the validity of the string, *exactly* as there weren't before.
>
> If the string is constructed by locale::locale(const char*) this is not
> really an issue,
> but, as you said before, if it's passed by the user it can be, if we
> want: someone told
> me that this area is basically QoI, since the standard prescribes
> nothing about
> all of it.
>
> So...
>
> We should decide together which checks to add, how much expensive and
> what to do
> if they are not ok. Perhaps throw an exception? Which one?
>
> Ciao, Paolo.
>
>