]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
syntax-check: Introduce sc_prohibit_g_autofree_const rule
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 8 Jan 2026 15:50:01 +0000 (16:50 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 15 Jan 2026 10:17:06 +0000 (11:17 +0100)
The aim of this rule is to capture the following pattern:

  g_autofree const char *var = ...;

The pattern is problematic, because it frees a const pointer. If
written the old way, we'd get a compiler warning:

  warning: passing argument 1 of ‘free’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
build-aux/syntax-check.mk

index 4deaa70368ed98ddcc99074b001a24e2f7398e18..f605c9b0e3c59a0019adb3193fb46414ba12f081 100644 (file)
@@ -389,6 +389,12 @@ sc_prohibit_unsigned_pid:
        halt='use signed type for pid values' \
          $(_sc_search_regexp)
 
+sc_prohibit_g_autofree_const:
+       @prohibit='\<g_auto(free|ptr)\>.* const.* \*[^*]' \
+       halt='‘g_autofree’ discards ‘const’ qualifier from pointer target type' \
+         $(_sc_search_regexp)
+
+
 # Many of the function names below came from this filter:
 # git grep -B2 '\<_('|grep -E '\.c- *[[:alpha:]_][[:alnum:]_]* ?\(.*[,;]$' \
 # |sed 's/.*\.c-  *//'|perl -pe 's/ ?\(.*//'|sort -u \