Re: [PATCH V2] Fix buffer size warning for strcpy

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

 



> > You really should explain here why we change from filling with spaces to
> > filling with nuls.
> I guess that a commit-comment would still be needed, but I think that a
> more conventional approach could make it all clearer:
> 
> - memset(ve->name, ' ', 16);
> - if (name)
> -	strncpy(ve->name, name, 16);
> + int l = strnlen(ve->name, 16);
> + memcpy(ve->name, name, l);
> + if (l < 16) /* no null-termination expected when all the space is used */
> + 	ve->name[l] = '\0';
> 
> Cheers,
> Gal

my bad - I obviously meant strnlen(name, 16).



[Index of Archives]     [Linux RAID Wiki]     [ATA RAID]     [Linux SCSI Target Infrastructure]     [Linux Block]     [Linux IDE]     [Linux SCSI]     [Linux Hams]     [Device Mapper]     [Device Mapper Cryptographics]     [Kernel]     [Linux Admin]     [Linux Net]     [GFS]     [RPM]     [git]     [Yosemite Forum]


  Powered by Linux