[PATCH 12/18] test_power: change strncpy+truncation to strlcpy

From: Dominique Martinet
Date: Thu Jul 12 2018 - 21:25:58 EST


Generated by scripts/coccinelle/misc/strncpy_truncation.cocci

Signed-off-by: Dominique Martinet <asmadeus@xxxxxxxxxxxxx>
---

Please see https://marc.info/?l=linux-kernel&m=153144450722324&w=2 (the
first patch of the serie) for the motivation behind this patch

drivers/power/supply/test_power.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/power/supply/test_power.c b/drivers/power/supply/test_power.c
index 57246cdbd042..64adf630f64f 100644
--- a/drivers/power/supply/test_power.c
+++ b/drivers/power/supply/test_power.c
@@ -297,8 +297,7 @@ static int map_get_value(struct battery_property_map *map, const char *key,
char buf[MAX_KEYLENGTH];
int cr;

- strncpy(buf, key, MAX_KEYLENGTH);
- buf[MAX_KEYLENGTH-1] = '\0';
+ strlcpy(buf, key, MAX_KEYLENGTH);

cr = strnlen(buf, MAX_KEYLENGTH) - 1;
if (cr < 0)
--
2.17.1