]> xenbits.xensource.com Git - libvirt.git/commitdiff
Prohibit verbose strcat
authorJán Tomko <jtomko@redhat.com>
Wed, 3 Feb 2016 08:48:40 +0000 (09:48 +0100)
committerJán Tomko <jtomko@redhat.com>
Thu, 11 Feb 2016 07:05:16 +0000 (08:05 +0100)
Using strcat directly is more readable than passing strlen
of the copied string to strncat.

cfg.mk
src/storage/storage_backend_logical.c

diff --git a/cfg.mk b/cfg.mk
index 71b0866d52f6e6c2837f474cf8732470ba974562..3f78842a5b95711a51ef99a2719e342558f2e568 100644 (file)
--- a/cfg.mk
+++ b/cfg.mk
@@ -1031,6 +1031,12 @@ sc_prohibit_not_strneq:
        halt='Use STREQ instead of !STRNEQ'     \
          $(_sc_search_regexp)
 
+sc_prohibit_verbose_strcat:
+       @prohibit='strncat\([^,]*,\s+([^,]*),\s+strlen\(\1\)\)'     \
+       in_vc_files='\.[ch]$$'                                      \
+       halt='Use strcat(a, b) instead of strncat(a, b, strlen(b))' \
+         $(_sc_search_regexp)
+
 # We don't use this feature of maint.mk.
 prev_version_file = /dev/null
 
index ba26223f1429e97b4f0a48c9160a654c65dd325e..f0d6f803837918aa747257d2b12de4defb38ed97 100644 (file)
@@ -123,11 +123,11 @@ virStorageBackendLogicalParseVolExtents(virStorageVolDefPtr vol,
     /* Allocate space for 'nextents' regex_unit strings plus a comma for each */
     if (VIR_ALLOC_N(regex, nextents * (strlen(regex_unit) + 1) + 1) < 0)
         goto cleanup;
-    strncat(regex, regex_unit, strlen(regex_unit));
+    strcat(regex, regex_unit);
     for (i = 1; i < nextents; i++) {
         /* "," is the separator of "devices" field */
         strcat(regex, ",");
-        strncat(regex, regex_unit, strlen(regex_unit));
+        strcat(regex, regex_unit);
     }
 
     if (VIR_ALLOC(reg) < 0)