2018-05-29 06:32:35

by Nick Desaulniers

[permalink] [raw]
Subject: [PATCH] blk-wbt: tracing: prefer strlcpy to strncpy

Fixes a stringop-truncation warning from gcc-8.

Signed-off-by: Nick Desaulniers <[email protected]>
---
include/trace/events/wbt.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/trace/events/wbt.h b/include/trace/events/wbt.h
index b048694..305252d 100644
--- a/include/trace/events/wbt.h
+++ b/include/trace/events/wbt.h
@@ -33,7 +33,7 @@ TRACE_EVENT(wbt_stat,
),

TP_fast_assign(
- strncpy(__entry->name, dev_name(bdi->dev), 32);
+ strlcpy(__entry->name, dev_name(bdi->dev), 32);
__entry->rmean = stat[0].mean;
__entry->rmin = stat[0].min;
__entry->rmax = stat[0].max;
@@ -67,7 +67,7 @@ TRACE_EVENT(wbt_lat,
),

TP_fast_assign(
- strncpy(__entry->name, dev_name(bdi->dev), 32);
+ strlcpy(__entry->name, dev_name(bdi->dev), 32);
__entry->lat = div_u64(lat, 1000);
),

@@ -103,7 +103,7 @@ TRACE_EVENT(wbt_step,
),

TP_fast_assign(
- strncpy(__entry->name, dev_name(bdi->dev), 32);
+ strlcpy(__entry->name, dev_name(bdi->dev), 32);
__entry->msg = msg;
__entry->step = step;
__entry->window = div_u64(window, 1000);
@@ -138,7 +138,7 @@ TRACE_EVENT(wbt_timer,
),

TP_fast_assign(
- strncpy(__entry->name, dev_name(bdi->dev), 32);
+ strlcpy(__entry->name, dev_name(bdi->dev), 32);
__entry->status = status;
__entry->step = step;
__entry->inflight = inflight;
--
2.7.4



2018-05-30 01:59:34

by Nick Desaulniers

[permalink] [raw]
Subject: Re: [PATCH] blk-wbt: tracing: prefer strlcpy to strncpy

On Mon, May 28, 2018 at 11:31 PM, Nick Desaulniers
<[email protected]> wrote:
> Fixes a stringop-truncation warning from gcc-8.
>
> Signed-off-by: Nick Desaulniers <[email protected]>
> ---
> include/trace/events/wbt.h | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/include/trace/events/wbt.h b/include/trace/events/wbt.h
> index b048694..305252d 100644
> --- a/include/trace/events/wbt.h
> +++ b/include/trace/events/wbt.h
> @@ -33,7 +33,7 @@ TRACE_EVENT(wbt_stat,
> ),
>
> TP_fast_assign(
> - strncpy(__entry->name, dev_name(bdi->dev), 32);
> + strlcpy(__entry->name, dev_name(bdi->dev), 32);
> __entry->rmean = stat[0].mean;
> __entry->rmin = stat[0].min;
> __entry->rmax = stat[0].max;
> @@ -67,7 +67,7 @@ TRACE_EVENT(wbt_lat,
> ),
>
> TP_fast_assign(
> - strncpy(__entry->name, dev_name(bdi->dev), 32);
> + strlcpy(__entry->name, dev_name(bdi->dev), 32);
> __entry->lat = div_u64(lat, 1000);
> ),
>
> @@ -103,7 +103,7 @@ TRACE_EVENT(wbt_step,
> ),
>
> TP_fast_assign(
> - strncpy(__entry->name, dev_name(bdi->dev), 32);
> + strlcpy(__entry->name, dev_name(bdi->dev), 32);
> __entry->msg = msg;
> __entry->step = step;
> __entry->window = div_u64(window, 1000);
> @@ -138,7 +138,7 @@ TRACE_EVENT(wbt_timer,
> ),
>
> TP_fast_assign(
> - strncpy(__entry->name, dev_name(bdi->dev), 32);
> + strlcpy(__entry->name, dev_name(bdi->dev), 32);
> __entry->status = status;
> __entry->step = step;
> __entry->inflight = inflight;
> --
> 2.7.4
>

Eric points out this doesn't initialize the rest of dest if src is
less than size.