From: Ruben Kerkhof Date: Mon, 14 May 2018 22:27:58 +0000 (+0200) Subject: nut plugin: fix warning X-Git-Url: https://git.octo.it/?p=collectd.git;a=commitdiff_plain;h=67b77875fa96f683987d639b29437bfbf941c4f6 nut plugin: fix warning CC src/nut_la-nut.lo In function ‘nut_ca_path’, inlined from ‘nut_config.part.1’ at src/nut.c:181:12, inlined from ‘nut_config’: src/nut.c:148:5: warning: ‘strncpy’ specified bound depends on the length of the source argument [-Wstringop-overflow=] strncpy(ca_path, value, (strlen(value) + 1)); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src/nut.c: In function ‘nut_config’: src/nut.c:148:30: note: length computed here strncpy(ca_path, value, (strlen(value) + 1)); ^~~~~~~~~~~~~ CCLD nut.la --- diff --git a/src/nut.c b/src/nut.c index 1d1e94b5..997d1a50 100644 --- a/src/nut.c +++ b/src/nut.c @@ -144,8 +144,7 @@ static int nut_verify_peer(const char *value) { static int nut_ca_path(const char *value) { if (value != NULL && strcmp(value, "") != 0) { - ca_path = malloc(strlen(value) + 1); - strncpy(ca_path, value, (strlen(value) + 1)); + ca_path = strdup(value); } else { ca_path = NULL; // Should alread be set to NULL from initialization }