From patchwork Fri Jan 12 07:45:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiongfeng Wang X-Patchwork-Id: 10159727 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1E62C602A7 for ; Fri, 12 Jan 2018 07:39:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0F8D4289A2 for ; Fri, 12 Jan 2018 07:39:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 002C4289A7; Fri, 12 Jan 2018 07:39:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 74C07289A2 for ; Fri, 12 Jan 2018 07:39:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752841AbeALHjk (ORCPT ); Fri, 12 Jan 2018 02:39:40 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:4171 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750714AbeALHjk (ORCPT ); Fri, 12 Jan 2018 02:39:40 -0500 Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 956CBA31DB603; Fri, 12 Jan 2018 15:39:23 +0800 (CST) Received: from localhost.localdomain.localdomain (10.175.113.25) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.361.1; Fri, 12 Jan 2018 15:39:14 +0800 From: Xiongfeng Wang To: , , CC: , , Subject: [PATCH] iio: accel: use strlcpy() instead of strncpy() Date: Fri, 12 Jan 2018 15:45:38 +0800 Message-ID: <1515743138-94480-1-git-send-email-wangxiongfeng2@huawei.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-CFilter-Loop: Reflected Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Xiongfeng Wang gcc-8 reports drivers/iio/accel/st_accel_i2c.c: In function 'st_accel_i2c_probe': ./include/linux/string.h:245:9: warning: '__builtin_strncpy' specified bound 20 equals destination size [-Wstringop-truncation] The compiler require that the length of the dest string is greater than the length we want to copy to make sure the dest string is nul-terminated. We can just use strlcpy() to avoid this warning. Signed-off-by: Xiongfeng Wang --- drivers/iio/accel/st_accel_i2c.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/iio/accel/st_accel_i2c.c b/drivers/iio/accel/st_accel_i2c.c index 363429b..6bdec8c 100644 --- a/drivers/iio/accel/st_accel_i2c.c +++ b/drivers/iio/accel/st_accel_i2c.c @@ -159,9 +159,8 @@ static int st_accel_i2c_probe(struct i2c_client *client, if ((ret < 0) || (ret >= ST_ACCEL_MAX)) return -ENODEV; - strncpy(client->name, st_accel_id_table[ret].name, + strlcpy(client->name, st_accel_id_table[ret].name, sizeof(client->name)); - client->name[sizeof(client->name) - 1] = '\0'; } else if (!id) return -ENODEV;