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:mime-version :content-type; q=dns; s=default; b=fmAHEbXHrYJYsJDMHrTjlbJy0UQsG 3uoK7lnRrQ5JoGmF1AJjojLE0a0RALljBtnG55Xu4kYAMVk92gAEHnM/dFFmCx1o /qCtEyXOEomiNP8vn+somWdM0mpVinYhiixE4G12TjNl95GDGzz9J2l8v8AbeKr9 vHH17opWx8Zvlc= 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:mime-version :content-type; s=default; bh=eTpSu23XPjElPwNqvd9dzETwGKs=; b=EbH 2DUA8rEtXEjol+LlzHY+fOzTInmm0juf0yLG0lGa+xLZEkrEvIYvvHaQeQB0i2kG tNWPIrjUKM+RMzxc458weH/dtMPsaofDDOzuWWLnnPiC/8FFRsjaq+zZws4JFZQm i41Pf+Kiq+sd2EhZ+EdTrRE5xyTdB6jyIHrdEYRU= Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , 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.0 required=5.0 tests=AWL,BAYES_20,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 spammy=Ticket, lc, alphabet, tony X-HELO: mars.tony.develop-help.com Date: Tue, 12 Apr 2016 15:07:22 +1000 From: Tony Cook To: cygwin AT cygwin DOT com Subject: strxfrm() returns an incorrect value on a short buffer Message-ID: <20160412050722.GE12445@mars.tony.develop-help.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes strxfrm() returns an incorrect value if you supply an output buffer and that buffer is too short for the result. With the code following: #include #include #include int main() { char xbuf[5] = ""; char *lc = setlocale(LC_ALL, "en_AU.utf8"); if (!lc) { perror("setlocale"); return 1; } size_t sza = strxfrm(xbuf, "alphabet", sizeof(xbuf)); printf("sz: %zd\n", sza); size_t szb = strxfrm(NULL, "alphabet", 0); printf("sz: %zd\n", szb); return 0; } On cygwin: tony AT phobos ~ $ gcc -ostrxfrmtest strxfrmtest.c tony AT phobos ~ $ ./strxfrmtest sz: 5 sz: 20 tony AT phobos ~ $ uname -a CYGWIN_NT-6.1-WOW phobos 2.5.0(0.297/5/3) 2016-04-11 09:55 i686 Cygwin On Linux: tony AT mars:~$ gcc -ostrxfrmtest strxfrmtest.c tony AT mars:~$ ./strxfrmtest sz: 26 sz: 26 tony AT mars:~$ uname -a Linux mars 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt20-1+deb8u3 (2016-01-17) x86_64 GNU/Linux From looking at the source: https://cygwin.com/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=winsup/cygwin/nlsfuncs.cc;h=9dbd9b16d53094c60aa835756c967c054ced8e62;hb=HEAD#l1286 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. This came out of the discussion in: https://rt.perl.org/Ticket/Display.html?id=121734 (not that I've reproduced that issue.) 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