Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754861AbeAHR4b (ORCPT + 1 other); Mon, 8 Jan 2018 12:56:31 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:42628 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754833AbeAHR42 (ORCPT ); Mon, 8 Jan 2018 12:56:28 -0500 X-Google-Smtp-Source: ACJfBosR9mLrfTyIBqVPlkuO7fmUILhFVFsMPJgmFXpwnCWDmoWJRsw/k7m1tIJrjHyQpkBimDyGPQ== Message-ID: <1515434186.7215.17.camel@dubeyko.com> Subject: Re: [PATCH] fs/hfsplus: use memcpy() instead of strncpy() From: Viacheslav Dubeyko To: Xiongfeng Wang , linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, arnd@arndb.de Date: Mon, 08 Jan 2018 09:56:26 -0800 In-Reply-To: <1515413857-48430-1-git-send-email-wangxiongfeng2@huawei.com> References: <1515413857-48430-1-git-send-email-wangxiongfeng2@huawei.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.18.5.2-0ubuntu3.2 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: On Mon, 2018-01-08 at 20:17 +0800, Xiongfeng Wang wrote: > From: Xiongfeng Wang > > gcc-8 reports > > inlined from 'copy_name' at fs/hfsplus/xattr.c:416:3: > ./include/linux/string.h:245:9: warning: '__builtin_strncpy' output > truncated before terminating nul copying 4 bytes from a string of the > same length [-Wstringop-truncation] > > Since we don't need to copy '\0', we can just use memcpy() to avoid > this > warning. > If the gcc-8 emits the warning then the suggested change makes sense. Looks good. Reviewed-by: Vyacheslav Dubeyko Thanks, Vyacheslav Dubeyko. > Signed-off-by: Xiongfeng Wang > --- >  fs/hfsplus/xattr.c | 2 +- >  1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/fs/hfsplus/xattr.c b/fs/hfsplus/xattr.c > index e538b75..0dc8a65 100644 > --- a/fs/hfsplus/xattr.c > +++ b/fs/hfsplus/xattr.c > @@ -413,7 +413,7 @@ static int copy_name(char *buffer, const char > *xattr_name, int name_len) >   int offset = 0; >   >   if (!is_known_namespace(xattr_name)) { > - strncpy(buffer, XATTR_MAC_OSX_PREFIX, > XATTR_MAC_OSX_PREFIX_LEN); > + memcpy(buffer, XATTR_MAC_OSX_PREFIX, > XATTR_MAC_OSX_PREFIX_LEN); >   offset += XATTR_MAC_OSX_PREFIX_LEN; >   len += XATTR_MAC_OSX_PREFIX_LEN; >   }