[PATCH 2/4] syscall.c: Add helpers for vector reallocation, syscall and errno finder

Dmitry V. Levin ldv at altlinux.org
Fri Jul 29 00:37:24 UTC 2016


On Wed, Jul 27, 2016 at 08:41:15PM +0200, Nahim El Atmani wrote:
> From: Nahim El Atmani <naam at lse.epita.fr>
> 
> From: Nahim El Atmani <nahim+dev at naam.me>

Too many Froms.

> * syscall.c (reallocate_vec): New function.
>   (reallocate_qual): Use it.
>   (find_errno_by_name): New function.
>   (find_scno_by_name): Likewise.

No need to indent.  You can also write
((find_errno_by_name, find_scno_by_name): New functions.

> -static void
> -reallocate_qual(const unsigned int n)
> +static inline void

No need to use "inline" keyword.

> +reallocate_vec(void **vec, size_t size, size_t elt, int n)

The names of arguments are confusing.  In terms of xreallocarray,
"size" is "old_nmemb", "elt" is "size", and "n" is "new_nmemb".

>  {
>  	unsigned p;
> -	qualbits_t *qp;
> +	char *ptr;

Why "char *"?  If "vec" has type "void **", then vec[p] has type "void *".

> +
>  	for (p = 0; p < SUPPORTED_PERSONALITIES; p++) {
> -		qp = qual_vec[p] = xreallocarray(qual_vec[p], n,
> -						 sizeof(qualbits_t));
> -		memset(&qp[num_quals], 0, (n - num_quals) * sizeof(qualbits_t));
> +		ptr = vec[p] = xreallocarray(vec[p], n, elt);
> +		memset(ptr + elt * size, 0, (n - size) * elt);
>  	}
> +}
> +
> +static inline void

No need to use "inline" keyword.

> +reallocate_qual(const unsigned int n)
> +{
> +	reallocate_vec((void **)qual_vec, num_quals, sizeof(qualbits_t), n);
>  	num_quals = n;
>  }
>  
> +static int
> +find_errno_by_name(const char *name)
> +{
> +	unsigned int i;
> +
> +	for (i = 1; i < nerrnos; i++) {
> +		if (errnoent[i] && (strcmp(name, errnoent[i]) == 0))
> +			return i;
> +	}
> +
> +	return -1;
> +}
> +
> +static int
> +find_scno_by_name(const char *name, unsigned personality)
> +{
> +	unsigned int i;
> +
> +	for (i = 0; i < nsyscall_vec[personality]; i++) {
> +		if (sysent_vec[personality][i].sys_name
> +		    && strcmp(name, sysent_vec[personality][i].sys_name) == 0) {
> +			return i;
> +		}
> +	}
> +
> +	return -1;
> +}

These static functions are added but never used.  This results to
compilation warnings and --enable-gcc-Werror turns them into errors:

syscall.c:434:1: error: 'find_errno_by_name' defined but not used [-Werror=unused-function]
 find_errno_by_name(const char *name)
 ^
syscall.c:447:1: error: 'find_scno_by_name' defined but not used [-Werror=unused-function]
 find_scno_by_name(const char *name, unsigned personality)
 ^

Even with subsequent patches applied these compilation warnings/errors
remain unless --enable-fault-injection is specified.


-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20160729/3bc12c8b/attachment.bin>


More information about the Strace-devel mailing list