[PATCH v1] Initialize local variables in functions

Mike Frysinger vapier at gentoo.org
Wed Aug 6 13:29:51 UTC 2014


On Mon 04 Aug 2014 08:35:02 zubin.mithra at gmail.com wrote:
> From: Zubin Mithra <zubin.mithra at gmail.com>
> 
> * desc.c (decode_select): Initialize fds to NULL.
> * strace.c (expand_tcbtab): Change type to unsigned.
> (startup_child): Initialize pathname array.

you need to describe why you're making a change, not just how

> --- a/desc.c
> +++ b/desc.c
> @@ -314,7 +314,7 @@ decode_select(struct tcb *tcp, long *args, enum
> bitness_t bitness) {
>  	int i, j;
>  	int nfds, fdsize;
> -	fd_set *fds;
> +	fd_set *fds = NULL;
>  	const char *sep;
>  	long arg;

why ?  i guess you're handling the case where nfds==0 ?  seems like fds is 
used uninitialized in that case.

however, if you do this, you'll see that the nfds<0 check also sets fds to 
NULL, so you should delete that line.

> --- a/strace.c
> +++ b/strace.c
> @@ -675,7 +675,7 @@ expand_tcbtab(void)
>  	   callers have pointers and it would be a pain.
>  	   So tcbtab is a table of pointers.  Since we never
>  	   free the TCBs, we allocate a single chunk of many.  */
> -	int i = tcbtabsize;
> +	unsigned int i = tcbtabsize;

i guess this is because tcpbtabsize is unsigned, and i is only used to compare 
to that.

> @@ -1160,7 +1160,7 @@ startup_child(char **argv)
>  {
>  	struct_stat statbuf;
>  	const char *filename;
> -	char pathname[MAXPATHLEN];
> +	char pathname[MAXPATHLEN] = "";
>  	int pid;
>  	struct tcb *tcp;

i'm not seeing a problem here.  pathname looks like it's always initialized 
before it's used.  note that sizeof(pathname) is not using the value of 
pathname, so those checks don't count ...
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20140806/d30696b0/attachment.bin>


More information about the Strace-devel mailing list