This is the mail archive of the
mailing list for the Cygwin project.
Re: strxfrm() returns an incorrect value on a short buffer
- From: Tony Cook <tony at develop-help dot com>
- To: cygwin at cygwin dot com
- Date: Tue, 12 Apr 2016 20:56:58 +1000
- Subject: Re: strxfrm() returns an incorrect value on a short buffer
- Authentication-results: sourceware.org; auth=none
- References: <20160412050722 dot GE12445 at mars dot tony dot develop-help dot com> <loom dot 20160412T120452-463 at post dot gmane dot org>
On Tue, Apr 12, 2016 at 10:20:13AM +0000, Achim Gratz wrote:
> Tony Cook <tony <at> develop-help.com> writes:
> > strxfrm() returns an incorrect value if you supply an output buffer
> > and that buffer is too short for the result.
> The text in the C standard is:
> The strxfrm function returns the length of the transformed string (not
> including the
> terminating null character). If the value returned is n or more, the
> contents of the array
> pointed to by s1 are indeterminate.
> EXAMPLE The value of the following expression is the size of the array
> needed to hold the
> transformation of the string pointed to by s.
> 1 + strxfrm(NULL, s, 0)
> It doesn't really provide for an explanation of what should happen if you
> start with a buffer that is too small, but from the standpoint of
> defensiveness, if you are getting the size of your buffer or larger, then
> you should ask again with a size of zero to get the actual minimum size
> needed or try again with a larger buffer until the returned value is smaller
> than the buffer size.
> > It appears that strxfrm() is just returning the size of the output
> > buffer on an overflow error rather than calling LCMapString() again
> > with cchDest set to zero to get the required buffer length that
> > strxfrm() is meant to return on a short buffer.
> So, you may be expecting something that the standard doesn't explicitly
> specify, although you might reasonhably invoke that Cygwin should behave
> like Linux in this case.
The specification of strxfrm() in the standard doesn't special-case a
length of zero beyond allowing for s1 to be NULL.
If an implementation were permitted to return the lesser of the full
length of the transformed string and the size of the buffer the
example in the standard wouldn't return what the description says it
Problem reports: http://cygwin.com/problems.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple