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 <xu.panda@zte.com.cn> Signed-off-by: Yang Yang <yang.yang29@zte.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
1 parent e2b018c commit 3639dbd

1 file changed

Lines changed: 1 addition & 2 deletions

File tree

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)