X-Recipient: archive-cygwin@delorie.com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:to:from:subject:date:message-id:references
	:mime-version:content-type:content-transfer-encoding; q=dns; s=
	default; b=Y3O/64CkrOynt9hMDm1wAOddbJVpImtUpmrkSLkWzlSUwYN38eoZE
	C93kwqMFWjMpFMvF9VNXZeR4BGHHir3nbrYXLIx/poe5D8joGcFXh8nAz54PMExX
	sNKt7tge8AZiQsFVxySvC9Ypkc+blqvjHxtjUVPjJR/j5MrP5B6gp8=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:to:from:subject:date:message-id:references
	:mime-version:content-type:content-transfer-encoding; s=default;
	 bh=f2JtbSZYoD5XCv50e4+yap3QlbM=; b=s2He4MjCaIRSOOuxVuJYJ1HuL9g1
	pfwtBXG9VhPCPodyHGMxVANdTjQ07yP6YhA8rfbYckdeUrFl6W52oOMBZ+JSLHXs
	TgjH1mesvHT8UxFFDGhN46OjBuxEHbzIq2GcV5PAubXYbBA1koC0VOrifAcoM7EJ
	8EIgo2PyTE0bW/8=
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=0.1 required=5.0 tests=AWL,BAYES_00,FSL_HELO_BARE_IP_2,RCVD_IN_DNSWL_LOW,RCVD_NUMERIC_HELO,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=no version=3.3.2 spammy=UD:develop-help.com, develop-help.com, develophelpcom, H*MI:sk:2016041
X-HELO: plane.gmane.org
To: cygwin@cygwin.com
From: Achim Gratz <Stromeko@NexGo.DE>
Subject: Re: strxfrm() returns an incorrect value on a short buffer
Date: Tue, 12 Apr 2016 10:20:13 +0000 (UTC)
Lines: 38
Message-ID: <loom.20160412T120452-463@post.gmane.org>
References: <20160412050722.GE12445@mars.tony.develop-help.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
User-Agent: Loom/3.14 (http://gmane.org/)
X-IsSubscribed: yes

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.


Regards,
Achim.


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

