From owner-freebsd-questions@FreeBSD.ORG Sun Nov 16 22:34:25 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 767E3148 for ; Sun, 16 Nov 2014 22:34:25 +0000 (UTC) Received: from zoom.lafn.org (zoom.lafn.org [108.92.93.123]) by mx1.freebsd.org (Postfix) with ESMTP id 4FAA02DE for ; Sun, 16 Nov 2014 22:34:24 +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 sAGMFA08086791 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Sun, 16 Nov 2014 14:15:11 -0800 (PST) (envelope-from bc979@lafn.org) From: Doug Hardie Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: vsnprintf and friends modify the va_list argument Message-Id: Date: Sun, 16 Nov 2014 14:15:10 -0800 To: "freebsd-questions@freebsd.org" Mime-Version: 1.0 (Mac OS X Mail 8.0 \(1990.1\)) X-Mailer: Apple Mail (2.1990.1) X-Virus-Scanned: clamav-milter 0.98 at zoom.lafn.org X-Virus-Status: Clean 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: Sun, 16 Nov 2014 22:34:25 -0000 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. For example, to print the = arguments and also write them to a file using the following code will = cause a segmentation violation: vprintf (fd, fmt, args); vsnprintf (buf, sizeof(buf), fmt, args); Switching the order of the calls doesn=E2=80=99t eliminate the = segmentation violation. You have to do something on the order of: vsnprintf (buf, sizeof(buf), fmt, args); fprintf (fd, =E2=80=9C%s=E2=80=9D, buf);=