From owner-freebsd-questions@FreeBSD.ORG Mon Nov 17 02:08:55 2014 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 6DA27B37 for ; Mon, 17 Nov 2014 02:08:55 +0000 (UTC) Received: from mx01.qsc.de (mx01.qsc.de [213.148.129.14]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 31925A09 for ; Mon, 17 Nov 2014 02:08:55 +0000 (UTC) Received: from r56.edvax.de (port-92-195-158-193.dynamic.qsc.de [92.195.158.193]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx01.qsc.de (Postfix) with ESMTPS id BB1063D453; Mon, 17 Nov 2014 03:08:46 +0100 (CET) Received: from r56.edvax.de (localhost [127.0.0.1]) by r56.edvax.de (8.14.5/8.14.5) with SMTP id sAH28iVb003296; Mon, 17 Nov 2014 03:08:45 +0100 (CET) (envelope-from freebsd@edvax.de) Date: Mon, 17 Nov 2014 03:08:44 +0100 From: Polytropon To: Doug Hardie Subject: Re: vsnprintf and friends modify the va_list argument Message-Id: <20141117030844.d83bbae3.freebsd@edvax.de> In-Reply-To: References: Reply-To: Polytropon Organization: EDVAX X-Mailer: Sylpheed 3.1.1 (GTK+ 2.24.5; i386-portbld-freebsd8.2) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: "freebsd-questions@freebsd.org" X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 Nov 2014 02:08:55 -0000 On Sun, 16 Nov 2014 14:15:10 -0800, Doug Hardie wrote: > I suspect this needs to be in a WARNING section of the > printf(3) man page. The print functions that use variable > arguments modify the argument list so that only one can > be called. In "man 3 printf" there is no mentioning that ap is being modified, but "man 3 stdarg" where va_start(), va_arg(), va_copy() and va_end() are being described, states the following (see 3rd sentence): The va_arg() macro expands to an expression that has the type and value of the next argument in the call. The parameter ap is the va_list ap initialized by va_start(). Each call to va_arg() modifies ap so that the next call returns the next argument. The parameter type is a type name specified so that the type of a pointer to an object that has the speci- fied type can be obtained simply by adding a * to type. It's important to understand that functions like vsnprintf(), vprintf() and fprintf() rely on the va_* functions / macros which _modify_ the va_list pointer. An additional hint is provided by the vprintf() prototypes where no "const" is mentioned in regards of the ap parameter: int vprintf(const char * restrict format, va_list ap); Maybe adding stdarg(3) to printf(3)'s SEE ALSO section would be a helpful choice here. -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...