This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: strxfrm() returns an incorrect value on a short buffer

On Tue, Apr 12, 2016 at 10:20:13AM +0000, Achim Gratz wrote:
> Tony Cook <tony <at>> 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:
Unsubscribe info:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]