Optimize the code that copies strings
authorBart Van Assche <bvanassche@acm.org>
Wed, 14 Aug 2019 20:10:08 +0000 (13:10 -0700)
committerJens Axboe <axboe@kernel.dk>
Wed, 14 Aug 2019 21:01:29 +0000 (15:01 -0600)
commit36833fb04b5f9a734e96a571dfb52fc54b5b95e7
tree6600f0f62d861bac57b8f6b5d101a18d43610a66
parent27bbef0cb264b7d66a5f93424d6fc6ff973e22a2
Optimize the code that copies strings

Using strncpy() to copy strings is suboptimal because strncpy writes a
bunch of additional unnecessary null bytes. Use snprintf() instead of
strncpy(). An additional advantage of snprintf() is that it guarantees
that the output string is '\0'-terminated.

This patch is an improvement for commit 32e31c8c5f7b ("Fix string copy
compilation warnings").

Cc: Damien Le Moal <damien.lemoal@wdc.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
14 files changed:
cconv.c
client.c
diskutil.c
engines/net.c
engines/sg.c
filesetup.c
gclient.c
init.c
ioengines.c
options.c
parse.c
server.c
stat.c
verify.c