Re: [PATCH] misc: fix string buffer compile warnings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Funnily enough I just started looking into xfsdump warnings a few
minutes ago..

> --- a/common/global.c
> +++ b/common/global.c
> @@ -82,7 +82,7 @@ global_hdr_alloc(int argc, char *argv[])
>  
>  	/* fill in the magic number
>  	 */
> -	strncpy(ghdrp->gh_magic, GLOBAL_HDR_MAGIC, GLOBAL_HDR_MAGIC_SZ);
> +	memcpy(ghdrp->gh_magic, GLOBAL_HDR_MAGIC, GLOBAL_HDR_MAGIC_SZ);

This chunk and all the other ones switching to memcpy where we have
a fixed size look good and impossible to improve on to me.

> -	sprintf(question,
> +	snprintf(question, sizeof(question),
>  		 "pre-erase (-%c) option specified "
>  		 "and non-blank media encountered:\n"
>  		 "please confirm media erase "
> diff --git a/invutil/fstab.c b/invutil/fstab.c

For this and a few others that just s(n)printf I wonder if just
switching to asprintf and dynamically allocating the buffer is
the right thing to do.  That's a GNU/BSD extension, but we probably
don't care about anything else.

> index 88d849e..56132e1 100644
> --- a/invutil/fstab.c
> +++ b/invutil/fstab.c
> @@ -149,7 +149,7 @@ fstab_select(WINDOW *win, node_t *current, node_t *list)
>  int
>  fstab_highlight(WINDOW *win, node_t *current, node_t *list)
>  {
> -    static char txt[256];
> +    static char txt[512];

And for put_info_line/put_line I suspect just passing a format
string is the best thing to do, as this avoids the extra
snprintf and buffer entirely.  That's in fact what I had just started
on.





[Index of Archives]     [XFS Filesystem Development (older mail)]     [Linux Filesystem Development]     [Linux Audio Users]     [Yosemite Trails]     [Linux Kernel]     [Linux RAID]     [Linux SCSI]


  Powered by Linux