From owner-freebsd-standards@FreeBSD.ORG Mon Apr 19 12:20:18 2004 Return-Path: Delivered-To: freebsd-standards@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E844A16A4CF for ; Mon, 19 Apr 2004 12:20:17 -0700 (PDT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id C54A043D49 for ; Mon, 19 Apr 2004 12:20:17 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) i3JJKHbv059421 for ; Mon, 19 Apr 2004 12:20:17 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.10/8.12.10/Submit) id i3JJKHci059420; Mon, 19 Apr 2004 12:20:17 -0700 (PDT) (envelope-from gnats) Resent-Date: Mon, 19 Apr 2004 12:20:17 -0700 (PDT) Resent-Message-Id: <200404191920.i3JJKHci059420@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-standards@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Jonathan McGee Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6AA8116A4CE for ; Mon, 19 Apr 2004 12:18:58 -0700 (PDT) Received: from po0.wam.umd.edu (po0.wam.umd.edu [128.8.10.162]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6EF9743D3F for ; Mon, 19 Apr 2004 12:18:53 -0700 (PDT) (envelope-from mcgee@wam.umd.edu) Received: from rac3.wam.umd.edu (IDENT:sendmail@rac3.wam.umd.edu [128.8.10.143]) by po0.wam.umd.edu (8.12.10/8.12.10) with ESMTP id i3JJIqci027239 for ; Mon, 19 Apr 2004 15:18:52 -0400 (EDT) Received: (from mcgee@localhost) by rac3.wam.umd.edu (8.12.10/8.12.10) id i3JJIlKi005399 for FreeBSD-gnats-submit@freebsd.org; Mon, 19 Apr 2004 15:18:47 -0400 (EDT) Message-Id: <200404191918.i3JJIlKi005399@rac3.wam.umd.edu> Date: Mon, 19 Apr 2004 15:18:47 -0400 (EDT) From: Jonathan McGee To: undisclosed-recipients: ; Subject: standards/65779: Potential bug in printf positional parameters X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Jonathan McGee List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Apr 2004 19:20:18 -0000 >Number: 65779 >Category: standards >Synopsis: Potential bug in printf positional parameters >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-standards >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Mon Apr 19 12:20:17 PDT 2004 >Closed-Date: >Last-Modified: >Originator: Jonathan McGee >Release: FreeBSD 5.2.1-RELEASE-p4 i386 >Organization: >Environment: System: FreeBSD freebie 5.2.1-RELEASE-p4 FreeBSD 5.2.1-RELEASE-p4 #0: Tue Apr 13 06:05:44 EDT 2004 root@freebie:/usr/obj/usr/src/sys/FREEBIE i386 System is build by user with CFLAGS="-O3 -pipe", CPU="p3". After the problem was found, it was retried with CFLAGS="-O0 -g" with no change in the behavior. >Description: While working on a port, found a potential issue with positional parameters in FreeBSD's libc. It seems that both sprintf and printf (the only two functions tested) are not honoring the positional argument flags. A minimum test case was written and attached (test-libc.c). When built, four integers (1, 2, 3, 4) are passed to a positional printf that should display them in order, skipping the second. When executed, the output expected is: 1 3 4 1 3 4 Instead, I get: 1 2 3 1 2 3 It seems rather sensitive to the ordering of printf and sprintf calls. I can swap them and get different behaviors (occasionally one may work). >How-To-Repeat: See attached test-libc.c >Fix: --- test-libc.c begins here --- #include int main() { int int1 = 1; int int2 = 2; int int3 = 3; int int4 = 4; char buffer[200]; char *format = "%1$i %3$i %4$i\n"; printf(format, int1, int2, int3, int4); sprintf(buffer, format, int1, int2, int3, int4); printf("%s", buffer); return 0; } --- test-libc.c ends here --- >Release-Note: >Audit-Trail: >Unformatted: