From owner-freebsd-questions@FreeBSD.ORG Mon Nov 17 19:15:39 2014 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 9BE54322 for ; Mon, 17 Nov 2014 19:15:39 +0000 (UTC) Received: from zoom.lafn.org (zoom.lafn.org [108.92.93.123]) by mx1.freebsd.org (Postfix) with ESMTP id 6F9D8850 for ; Mon, 17 Nov 2014 19:15:39 +0000 (UTC) Received: from [10.0.1.2] (static-71-177-216-148.lsanca.fios.verizon.net [71.177.216.148]) (authenticated bits=0) by zoom.lafn.org (8.14.7/8.14.7) with ESMTP id sAHJFSlv012433 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 17 Nov 2014 11:15:29 -0800 (PST) (envelope-from bc979@lafn.org) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.0 \(1990.1\)) Subject: Re: vsnprintf and friends modify the va_list argument From: Doug Hardie In-Reply-To: <20141117030844.d83bbae3.freebsd@edvax.de> Date: Mon, 17 Nov 2014 11:15:28 -0800 Content-Transfer-Encoding: quoted-printable Message-Id: <617C3C28-2107-4D41-9E59-4C002FBDD33D@lafn.org> References: <20141117030844.d83bbae3.freebsd@edvax.de> To: Polytropon X-Mailer: Apple Mail (2.1990.1) X-Virus-Scanned: clamav-milter 0.98 at zoom.lafn.org X-Virus-Status: Clean 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 19:15:39 -0000 > On 16 November 2014, at 18:08, Polytropon wrote: >=20 > 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. >=20 > 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): >=20 > 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. >=20 > It's important to understand that functions like vsnprintf(), > vprintf() and fprintf() rely on the va_* functions / macros > which _modify_ the va_list pointer. I had guessed that might be the case, but didn=E2=80=99t take the time = to research that far. I had a problem to resolve. >=20 > An additional hint is provided by the vprintf() prototypes > where no "const" is mentioned in regards of the ap parameter: >=20 > int vprintf(const char * restrict format, va_list ap); Thats pretty obtuse ;-) >=20 > Maybe adding stdarg(3) to printf(3)'s SEE ALSO section would > be a helpful choice here. Probably, but I would normally never chase things that far to figure out = there would be a problem. I believe a warning like you quoted above in = the printf man page would be more likely to be noticed.