From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/4231 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: sscanf(3) return value doesn't count %100c assignments Date: Fri, 15 Nov 2013 15:47:02 -0500 Message-ID: <20131115204702.GE24286@brightrain.aerifal.cx> References: Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1384548430 6798 80.91.229.3 (15 Nov 2013 20:47:10 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 15 Nov 2013 20:47:10 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-4235-gllmg-musl=m.gmane.org@lists.openwall.com Fri Nov 15 21:47:16 2013 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1VhQIN-0006pw-Cb for gllmg-musl@plane.gmane.org; Fri, 15 Nov 2013 21:47:15 +0100 Original-Received: (qmail 9391 invoked by uid 550); 15 Nov 2013 20:47:14 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 9383 invoked from network); 15 Nov 2013 20:47:14 -0000 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Xref: news.gmane.org gmane.linux.lib.musl.general:4231 Archived-At: On Fri, Nov 15, 2013 at 08:23:42PM +0000, David Wuertele wrote: > Comparing musl-0.9.14 with glibc-2.13, I find sscanf(3) behaves > differently. In Glibc, sscanf() returns the same assignment counts when > using %Nc compared with using %s, but in Mulsl, sscanf returns different > assignment counts. > > For example, take the following two instructions: > > sscanf (string, "%d %s", &number, remainder); > sscanf (string, "%d %100c", &number, remainder); > > If each of these makes two assignments, they should both return 2. > Glibc works this way. But even though with Musl they both make two > assignments, Musl sscanf() returns 2 for the %s and it returns 1 for > the %100c version. musl's sscanf returns 1 because only the %d was matched. %100c requires _exactly_ 100 characters; anything shorter is a matching failure. See C99 7.19.6.2 The fscanf function, paragraph 12: 12 The conversion specifiers and their meanings are: .... c Matches a sequence of characters of exactly the number specified by the field width (1 if no field width is present in the directive). What you're seeing is a known bug in glibc: https://sourceware.org/bugzilla/show_bug.cgi?id=12701 It's an old WONTFIX from the days when Ulrich Drepper was maintainer. Rich