On Thu, Oct 02, 2014 at 05:58:43AM -0500, Vladimir Támara Patiño wrote:
> POSIX doesn't specify behavior for wcsrtombs and mbsrtowcs when the
> source parameter is NULL.
> http://pubs.opengroup.org/onlinepubs/009695399/functions/mbsrtowcs.html
> http://pubs.opengroup.org/onlinepubs/009695399/functions/wcsrtombs.html
> 
> However segfaulting in such cases, as happens with this example,  
> IMHO, is not desirable.

It's perferctly acceptable for buggy applications to crash sooner
rather than later. I don't think code which uses a NULL src will
have any chance of surviving much longer even with your change.

> The attached patch solves this by setting errno in EINVAL and 
> returning (size_t)-1 when the source parameter is NULL or points
> to NULL, also includes this information in the man page.

We can't just invent new meanings for errors codes.
mbsrtowcs already defines EINVAL as "ps points to an object that
contains an invalid conversion state".

Reply via email to