diff options
author | Xu Panda <xu.panda@zte.com.cn> | 2022-12-23 03:42:35 +0100 |
---|---|---|
committer | Sebastian Reichel <sre@kernel.org> | 2023-02-03 13:43:48 +0100 |
commit | 3639dbd74e2e827d544bdb28b663a44449c014e1 (patch) | |
tree | 81f9cc14c990feb29af7714c8c35fd22d2bf4c97 /drivers/power/supply | |
parent | power: supply: bq27xxx: fix reporting critical level (diff) | |
download | linux-3639dbd74e2e827d544bdb28b663a44449c014e1.tar.xz linux-3639dbd74e2e827d544bdb28b663a44449c014e1.zip |
power: supply: test-power: use strscpy() instead of strncpy()
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>
Diffstat (limited to 'drivers/power/supply')
-rw-r--r-- | drivers/power/supply/test_power.c | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/drivers/power/supply/test_power.c b/drivers/power/supply/test_power.c index 5f510ddc946d..0d0a77584c5d 100644 --- a/drivers/power/supply/test_power.c +++ b/drivers/power/supply/test_power.c @@ -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) |