From owner-freebsd-current@FreeBSD.ORG Tue Aug 24 19:03:08 2004 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3EC7616A4CE; Tue, 24 Aug 2004 19:03:08 +0000 (GMT) Received: from n33.kp.t-systems-sfr.com (n33.kp.t-systems-sfr.com [129.247.16.33]) by mx1.FreeBSD.org (Postfix) with ESMTP id 34AB143D3F; Tue, 24 Aug 2004 19:03:07 +0000 (GMT) (envelope-from harti@freebsd.org) Received: from n81.sp.op.dlr.de (n81g.sp.op.dlr.de [129.247.163.1]) i7OJ2rX331792; Tue, 24 Aug 2004 21:02:54 +0200 Received: from zeus.nt.op.dlr.de (zeus.nt.op.dlr.de [129.247.173.3]) i7OJ2rI77672; Tue, 24 Aug 2004 21:02:53 +0200 Received: from beagle.kn.op.dlr.de (opkndnwsbsd178 [129.247.173.178]) by zeus.nt.op.dlr.de (8.11.7+Sun/8.9.1) with ESMTP id i7OJ2qe25951; Tue, 24 Aug 2004 21:02:53 +0200 (MET DST) Date: Tue, 24 Aug 2004 21:03:02 +0200 (CEST) From: Harti Brandt X-X-Sender: brandt@beagle.kn.op.dlr.de To: Sean McNeil In-Reply-To: <1093371600.10464.23.camel@server.mcneil.com> Message-ID: <20040824205417.L517@beagle.kn.op.dlr.de> References: <1092777586.92327.9.camel@server.mcneil.com> <20040817213813.GE3827@gothmog.gr><4127841D.6050104@freebsd.org> <20040824200225.V517@beagle.kn.op.dlr.de> <1093371600.10464.23.camel@server.mcneil.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: Giorgos Keramidas cc: Tim Kientzle cc: current@freebsd.org Subject: Re: bsdtar core dumps X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Harti Brandt List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Aug 2004 19:03:08 -0000 On Tue, 24 Aug 2004, Sean McNeil wrote: SM>On Tue, 2004-08-24 at 11:08, Harti Brandt wrote: SM>> On Tue, 24 Aug 2004, Sean McNeil wrote: SM>> SM>[snip] SM>> SM>> Sorry to jump in. SM>> SM>> You cannot use a va_list twice. As soon as someone call va_arg() on the SM>> ap all the aps in the calling functions get invalid. The only thing that SM>> can and must be done is that the function that did the va_start() must SM>> call va_end. SM>> SM>> If you need it twice you must make a copy as in the patch below. SM>> But the function call va_copy must also call va_end() on that copy SM>> (this seems missing in the patch). SM> SM>I took the lead from /usr/src/lib/libc/stdio/vfprintf.c SM> SM>It happens to do a va_copy(orgap,ap) but never does a va_end(orgap). SM>Either vfprintf.c is incorrect or it is not necessary to call va_end(). vfprintf.c is wrong. Paragraph 1 of 7.15.1 of C99 states: "Each invocation of the va_start and va_copy macros shall be matched by a corresponding invocation of the va_end macro in the same function." SM>One point I would like to make clear - you _can_ use a va_list twice on SM>architectures that will pass the va_list argument by value (i.e. i386). SM>This makes it easy to produce faulty code for those architectures that SM>pass by reference and thus have a side-effect. Since most people here SM>are developing and testing on x86 machines I would think this problem to SM>have happened more often than it has. This depends on what you call _can_. Again citing C99 (paragraph 3 of 7.15): "The object ap may be passed as an argument to another function; if that function invokes the va_arg macro with parameter ap, the value of ap in the calling function is indeterminate and shall be passed to the va_end macro prior to any further reference to ap." (ap is a va_list here). That is rather clear. I wouldn't call the fact that it incidentally happens to work on that concrete compiler/machine implementation an argument for 'can be used twice'. Especially in the case if stdarg.h it is very helpful to closly follow the standard. harti