]> xenbits.xensource.com Git - libvirt.git/commitdiff
cfg.mk: variable initialization when declared with cleanup macro
authorSukrit Bhatnagar <skrtbhtngr@gmail.com>
Fri, 13 Jul 2018 17:54:40 +0000 (23:24 +0530)
committerErik Skultety <eskultet@redhat.com>
Sat, 14 Jul 2018 15:01:30 +0000 (17:01 +0200)
A variable, which is never assigned a value in the function, might get
passed into the cleanup function which may or may not raise any errors.

To maintain the correct usage, the variable must be initialized, either
with a value or with NULL. This syntax-check rule takes care of that.

Signed-off-by: Sukrit Bhatnagar <skrtbhtngr@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
cfg.mk

diff --git a/cfg.mk b/cfg.mk
index 6bebd0ad9f91df7addebaefd6fa7a495cbe2eb56..609ae869c2e551209f50c1d40a058e55af99cf52 100644 (file)
--- a/cfg.mk
+++ b/cfg.mk
@@ -1057,6 +1057,17 @@ sc_prohibit_backslash_alignment:
        halt='Do not attempt to right-align backslashes' \
          $(_sc_search_regexp)
 
+# Some syntax rules pertaining to the usage of cleanup macros
+# implementing GNU C's cleanup attribute
+
+# Rule to ensure that varibales declared using a cleanup macro are
+# always initialized.
+sc_require_attribute_cleanup_initialization:
+       @prohibit='VIR_AUTO(FREE|PTR)\(.+\) *[^=]+;' \
+       in_vc_files='\.[chx]$$' \
+       halt='variable declared with a cleanup macro must be initialized' \
+         $(_sc_search_regexp)
+
 # We don't use this feature of maint.mk.
 prev_version_file = /dev/null