aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2010-08-18 17:31:39 -0600
committerEric Blake <eblake@redhat.com>2010-11-17 10:13:12 -0700
commite8aba782e755760a77a8a35f9583e4e31995cda4 (patch)
treed379bdc0d19350916590dd6c131f326eb0d07f7d /HACKING
parentvirt-aa-helper: translate error messages (diff)
downloadlibvirt-e8aba782e755760a77a8a35f9583e4e31995cda4.tar.gz
libvirt-e8aba782e755760a77a8a35f9583e4e31995cda4.tar.bz2
libvirt-e8aba782e755760a77a8a35f9583e4e31995cda4.zip
maint: avoid remaining sprintf uses
* cfg.mk (sc_prohibit_sprintf): New rule. (sc_prohibit_asprintf): Avoid false positives. * docs/hacking.html.in (Printf-style functions): Document the policy. * HACKING: Regenerate. * .x-sc_prohibit_sprintf: New exemptions. * Makefile.am (syntax_check_exceptions): Ship new file. * src/vbox/vbox_tmpl.c (vboxStartMachine, vboxAttachUSB): Use virAsprintf instead. * src/uml/uml_driver.c (umlOpenMonitor): Use snprintf instead. * tools/virsh.c (cmdDetachInterface): Likewise. * src/security/security_selinux.c (SELinuxGenSecurityLabel): Likewise. * src/openvz/openvz_driver.c (openvzDomainDefineCmd): Likewise, and ensure large enough buffer.
Diffstat (limited to 'HACKING')
-rw-r--r--HACKING6
1 files changed, 6 insertions, 0 deletions
diff --git a/HACKING b/HACKING
index 2711ea1e0..17ad34479 100644
--- a/HACKING
+++ b/HACKING
@@ -538,6 +538,12 @@ virAsprintf, in util.h:
This makes it so gcc's -Wformat and -Wformat-security options can do their
jobs and cross-check format strings with the number and types of arguments.
+When printing to a string, consider using virBuffer for incremental
+allocations, virAsprintf for a one-shot allocation, and snprintf for
+fixed-width buffers. Do not use sprintf, even if you can prove the buffer
+won't overflow, since gnulib does not provide the same portability guarantees
+for sprintf as it does for snprintf.
+
Use of goto
===========