* [PATCH linux-next] power: supply: test-power: use strscpy() to instead of strncpy()
@ 2022-12-23 2:42 yang.yang29
2023-02-03 12:46 ` [PATCH linux-next] power: supply: test-power: use strscpy() to instead of? strncpy() Sebastian Reichel
0 siblings, 1 reply; 2+ messages in thread
From: yang.yang29 @ 2022-12-23 2:42 UTC (permalink / raw)
To: sre; +Cc: linux-pm, linux-kernel, xu.panda, yang.yang29
From: Xu Panda <xu.panda@zte.com.cn>
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>
---
drivers/power/supply/test_power.c | 3 +--
1 file changed, 1 insertion(+), 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)
--
2.15.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH linux-next] power: supply: test-power: use strscpy() to instead of? strncpy()
2022-12-23 2:42 [PATCH linux-next] power: supply: test-power: use strscpy() to instead of strncpy() yang.yang29
@ 2023-02-03 12:46 ` Sebastian Reichel
0 siblings, 0 replies; 2+ messages in thread
From: Sebastian Reichel @ 2023-02-03 12:46 UTC (permalink / raw)
To: yang.yang29; +Cc: linux-pm, linux-kernel, xu.panda
[-- Attachment #1: Type: text/plain, Size: 1053 bytes --]
Hi,
On Fri, Dec 23, 2022 at 10:42:35AM +0800, yang.yang29@zte.com.cn wrote:
> From: Xu Panda <xu.panda@zte.com.cn>
>
> 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>
> ---
Thanks, queued.
-- Sebastian
> drivers/power/supply/test_power.c | 3 +--
> 1 file changed, 1 insertion(+), 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)
> --
> 2.15.2
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-02-03 12:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-23 2:42 [PATCH linux-next] power: supply: test-power: use strscpy() to instead of strncpy() yang.yang29
2023-02-03 12:46 ` [PATCH linux-next] power: supply: test-power: use strscpy() to instead of? strncpy() Sebastian Reichel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).