On Wed, Feb 10, 2016 at 06:47:00PM +0100, Andrea Bolognani wrote:
On Wed, 2016-02-10 at 17:26 +0100, Ján Tomko wrote:
> Using strcat directly is more readable than passing strlen
> of the copied string to strncat.
> ---
> cfg.mk | 5 +++++
> src/storage/storage_backend_logical.c | 4 ++--
> 2 files changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/cfg.mk b/cfg.mk
> index 71b0866..be9e475 100644
> --- a/cfg.mk
> +++ b/cfg.mk
> @@ -1031,6 +1031,11 @@ sc_prohibit_not_strneq:
> halt='Use STREQ instead of !STRNEQ' \
> $(_sc_search_regexp)
>
> +sc_prohibit_verbose_strcat:
> + @prohibit='strncat\([^,]*,\s+([^,]*),\s+strlen\(\1\)\)' \
I'd rather use [^,]+ to match parameters, as there will always
be at least one symbol, but shouldn't make any difference in
practice.
> + halt='Use strcat(a, b) instead of strncat(a, b, strlen())' \
s/strlen()/strlen(b)/
That would make it match itself, so I limited the check to C files
in_vc_files='\.[ch]$$'
Jan