Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 16 Nov 2014 14:15:10 -0800
From:      Doug Hardie <bc979@lafn.org>
To:        "freebsd-questions@freebsd.org" <freebsd-questions@freebsd.org>
Subject:   vsnprintf and friends modify the va_list argument
Message-ID:  <C9A11AB7-0085-464E-A6FB-F6A3603B6372@lafn.org>

next in thread | raw e-mail | index | archive | help
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);=



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?C9A11AB7-0085-464E-A6FB-F6A3603B6372>