This is the mail archive of the
mailing list for the Cygwin project.
Re: strxfrm() returns an incorrect value on a short buffer
- From: Achim Gratz <Stromeko at NexGo dot DE>
- To: cygwin at cygwin dot com
- Date: Tue, 12 Apr 2016 10:20:13 +0000 (UTC)
- 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>
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
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.
Problem reports: http://cygwin.com/problems.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple