lkml.org 
[lkml]   [2020]   [Aug]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH net-next] hinic: fix strncpy output truncated compile warnings
From
Date
On 2020/8/7 3:01, David Miller wrote:
> From: Luo bin <luobin9@huawei.com>
> Date: Thu, 6 Aug 2020 15:48:30 +0800
>
>> diff --git a/drivers/net/ethernet/huawei/hinic/hinic_devlink.c b/drivers/net/ethernet/huawei/hinic/hinic_devlink.c
>> index c6adc776f3c8..1dc948c07b94 100644
>> --- a/drivers/net/ethernet/huawei/hinic/hinic_devlink.c
>> +++ b/drivers/net/ethernet/huawei/hinic/hinic_devlink.c
>> @@ -342,9 +342,9 @@ static int chip_fault_show(struct devlink_fmsg *fmsg,
>>
>> level = event->event.chip.err_level;
>> if (level < FAULT_LEVEL_MAX)
>> - strncpy(level_str, fault_level[level], strlen(fault_level[level]));
>> + strncpy(level_str, fault_level[level], strlen(fault_level[level]) + 1);
>> else
>> - strncpy(level_str, "Unknown", strlen("Unknown"));
>> + strncpy(level_str, "Unknown", sizeof(level_str));
>>
>> if (level == FAULT_LEVEL_SERIOUS_FLR) {
>
> Please fix these cases consistently, either use the strlen()+1 pattern
> or the "sizeof(destination)" one.
>
> Probably sizeof(destination) is best.
> .
>
Will fix. Thanks. Level_str array is initialized to zero, so can't use the strlen()+1 pattern, I'll
use strlen()+1 consistently.

\
 
 \ /
  Last update: 2020-08-07 02:58    [W:0.152 / U:0.596 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site