summaryrefslogtreecommitdiff
path: root/engines/net.c
diff options
context:
space:
mode:
authorBart Van Assche <bvanassche@acm.org>2019-08-14 13:10:08 -0700
committerJens Axboe <axboe@kernel.dk>2019-08-14 15:01:29 -0600
commit36833fb04b5f9a734e96a571dfb52fc54b5b95e7 (patch)
tree6600f0f62d861bac57b8f6b5d101a18d43610a66 /engines/net.c
parent27bbef0cb264b7d66a5f93424d6fc6ff973e22a2 (diff)
downloadfio-36833fb04b5f9a734e96a571dfb52fc54b5b95e7.tar.gz
fio-36833fb04b5f9a734e96a571dfb52fc54b5b95e7.tar.bz2
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>
Diffstat (limited to 'engines/net.c')
-rw-r--r--engines/net.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/engines/net.c b/engines/net.c
index ca6fb344..91f25774 100644
--- a/engines/net.c
+++ b/engines/net.c
@@ -1105,8 +1105,7 @@ static int fio_netio_setup_connect_unix(struct thread_data *td,
struct sockaddr_un *soun = &nd->addr_un;
soun->sun_family = AF_UNIX;
- memset(soun->sun_path, 0, sizeof(soun->sun_path));
- strncpy(soun->sun_path, path, sizeof(soun->sun_path) - 1);
+ snprintf(soun->sun_path, sizeof(soun->sun_path), "%s", path);
return 0;
}
@@ -1135,9 +1134,8 @@ static int fio_netio_setup_listen_unix(struct thread_data *td, const char *path)
mode = umask(000);
- memset(addr, 0, sizeof(*addr));
addr->sun_family = AF_UNIX;
- strncpy(addr->sun_path, path, sizeof(addr->sun_path) - 1);
+ snprintf(addr->sun_path, sizeof(addr->sun_path), "%s", path);
unlink(path);
len = sizeof(addr->sun_family) + strlen(path) + 1;