power: supply: test-power: use strscpy() instead of strncpy()
authorXu Panda <xu.panda@zte.com.cn>
Fri, 23 Dec 2022 02:42:35 +0000 (10:42 +0800)
committerSebastian Reichel <sre@kernel.org>
Fri, 3 Feb 2023 12:43:48 +0000 (13:43 +0100)
The implementation of strscpy() is more robust and safer.
That's now the recommended way to copy NUL-terminated strings.

Signed-off-by: Xu Panda <xu.panda@zte.com.cn>
Signed-off-by: Yang Yang <yang.yang29@zte.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
drivers/power/supply/test_power.c

index 5f510dd..0d0a775 100644 (file)
@@ -306,8 +306,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';
+       strscpy(buf, key, MAX_KEYLENGTH);
 
        cr = strnlen(buf, MAX_KEYLENGTH) - 1;
        if (cr < 0)