delorie.com/archives/browse.cgi | search |
X-Recipient: | archive-cygwin AT delorie DOT 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:date:from:to:subject:message-id:references | |
:mime-version:content-type:in-reply-to; q=dns; s=default; b=KSyy | |
q9ib+YA1dUjnOQOwD/Pc5EEy6PkOSoXGWRr0uNTzhDuTk7kepw+oXSIKqbFinxLL | |
x29SnCbl2SIxiTFu++wrAO98Q4G9QX32F1hESrnciCc+mqQLVbrhDF3B8g/oLeGY | |
V70RLjMu9v5/FwzVtmGNe9UxvWPux8pVBelr9Ac= | |
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:date:from:to:subject:message-id:references | |
:mime-version:content-type:in-reply-to; s=default; bh=RDmUe5d9md | |
Hf9k6KMZ2urO8wf7w=; b=NzgFB+S+92jinGWfCunrY0XCaabHN8fZ34Y73B9jWi | |
d1RlRdD5Hm05IP/EZbSRt1Ft02AtF3qPDigawxJCD0YW1knXYFg6JEmlk2xtgfzT | |
brS4uCSPouuB+CWJmBRNLU9421zvXzYMyTSVLox199crhlbPdejlS/PWUdWj1sZ+ | |
A= | |
Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
List-Id: | <cygwin.cygwin.com> |
List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> |
List-Archive: | <http://sourceware.org/ml/cygwin/> |
List-Post: | <mailto:cygwin AT cygwin DOT com> |
List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs> |
Sender: | cygwin-owner AT cygwin DOT com |
Mail-Followup-To: | cygwin AT cygwin DOT com |
Delivered-To: | mailing list cygwin AT cygwin DOT com |
Authentication-Results: | sourceware.org; auth=none |
X-Virus-Found: | No |
X-Spam-SWARE-Status: | No, score=-1.2 required=5.0 tests=AWL,BAYES_05,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 spammy=develop-help.com, UD:develop-help.com, develophelpcom, defensiveness |
X-HELO: | mars.tony.develop-help.com |
Date: | Tue, 12 Apr 2016 20:56:58 +1000 |
From: | Tony Cook <tony AT develop-help DOT com> |
To: | cygwin AT cygwin DOT com |
Subject: | Re: strxfrm() returns an incorrect value on a short buffer |
Message-ID: | <20160412105658.GF12445@mars.tony.develop-help.com> |
References: | <20160412050722 DOT GE12445 AT mars DOT tony DOT develop-help DOT com> <loom DOT 20160412T120452-463 AT post DOT gmane DOT org> |
MIME-Version: | 1.0 |
In-Reply-To: | <loom.20160412T120452-463@post.gmane.org> |
User-Agent: | Mutt/1.5.23 (2014-03-12) |
X-IsSubscribed: | yes |
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 does. Tony -- 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
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |