From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 91399 invoked by alias); 12 Apr 2016 10:57:16 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 91371 invoked by uid 89); 12 Apr 2016 10:57:15 -0000 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 Received: from develop-help.com (HELO mars.tony.develop-help.com) (14.200.49.10) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 12 Apr 2016 10:57:03 +0000 Received: from mars.tony.develop-help.com (localhost [127.0.0.1]) by mars.tony.develop-help.com (8.14.4/8.14.4/Debian-8) with ESMTP id u3CAuxlv007986 for ; Tue, 12 Apr 2016 20:56:59 +1000 Received: (from tony@localhost) by mars.tony.develop-help.com (8.14.4/8.14.4/Submit) id u3CAuwm3007984 for cygwin@cygwin.com; Tue, 12 Apr 2016 20:56:58 +1000 Date: Tue, 12 Apr 2016 10:57:00 -0000 From: Tony Cook To: cygwin@cygwin.com Subject: Re: strxfrm() returns an incorrect value on a short buffer Message-ID: <20160412105658.GF12445@mars.tony.develop-help.com> References: <20160412050722.GE12445@mars.tony.develop-help.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes X-SW-Source: 2016-04/txt/msg00240.txt.bz2 On Tue, Apr 12, 2016 at 10:20:13AM +0000, Achim Gratz wrote: > Tony Cook 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