Skip to content

Commit

Permalink
power: supply: test-power: use strscpy() instead of strncpy()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Xu Panda authored and Sebastian Reichel committed Feb 3, 2023
1 parent e2b018c commit 3639dbd
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions drivers/power/supply/test_power.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3639dbd

Please sign in to comment.