Skip to content

Commit 3639dbd

Browse files
Xu Pandasre
authored andcommitted
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 <[email protected]> Signed-off-by: Yang Yang <[email protected]> Signed-off-by: Sebastian Reichel <[email protected]>
1 parent e2b018c commit 3639dbd

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

drivers/power/supply/test_power.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,7 @@ static int map_get_value(struct battery_property_map *map, const char *key,
306306
char buf[MAX_KEYLENGTH];
307307
int cr;
308308

309-
strncpy(buf, key, MAX_KEYLENGTH);
310-
buf[MAX_KEYLENGTH-1] = '\0';
309+
strscpy(buf, key, MAX_KEYLENGTH);
311310

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

0 commit comments

Comments
 (0)