From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=3.0 tests=DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_PASS,T_DKIM_INVALID, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC2D2C6778C for ; Sun, 1 Jul 2018 20:57:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 68E1F258CE for ; Sun, 1 Jul 2018 20:57:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=roeck-us.net header.i=@roeck-us.net header.b="UrqPXCjb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 68E1F258CE Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=roeck-us.net Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752700AbeGAU5Y (ORCPT ); Sun, 1 Jul 2018 16:57:24 -0400 Received: from bh-25.webhostbox.net ([208.91.199.152]:57340 "EHLO bh-25.webhostbox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752639AbeGAU5V (ORCPT ); Sun, 1 Jul 2018 16:57:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=roeck-us.net; s=default; h=Message-Id:Date:Subject:Cc:To:From:Sender: Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=c91jDihQTeKdaUB8MOJIePUqWLCJCtQFevpYXmI35SI=; b=UrqPXCjb5UwCZrlg+BcuVWYhHa alyjtgsFAXMTfiJZ0wUjhZlyKUQ0wXG2HWXzM4fJqHRZ/5p7lqHnxuOjeij7+fU2Qm2etdXHkkLc+ DcCxcFmATc8ku8u9fjRStV+y+wNws79LMkJy14VXz0+iIFqT0FBle9J5mMybEtjEEKJ8yH1wrO9+u GTK/HWUDAOqGbGU0HOKmuSZ+lF1C3x3Opy6uemv72l4k8Dk174Mq9d8cbfCjlhMLoAf+BkXnbnKXs 39h7vqQbigMEeplhuPj5EESzbm7IGAez0vw0y6+y0l+yoNx0DBba6OIP9+j8uegMYF0JUToyaSJta 0T3MeksQ==; Received: from 108-223-40-66.lightspeed.sntcca.sbcglobal.net ([108.223.40.66]:48690 helo=localhost) by bh-25.webhostbox.net with esmtpa (Exim 4.89) (envelope-from ) id 1fZjPM-007eBT-JV; Sun, 01 Jul 2018 20:57:21 +0000 From: Guenter Roeck To: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, Guenter Roeck Subject: [PATCH] kobject: Replace strncpy with memcpy Date: Sun, 1 Jul 2018 13:57:16 -0700 Message-Id: <1530478636-16555-1-git-send-email-linux@roeck-us.net> X-Mailer: git-send-email 2.7.4 X-Authenticated_sender: guenter@roeck-us.net X-OutGoing-Spam-Status: No, score=-1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bh-25.webhostbox.net X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - roeck-us.net X-Get-Message-Sender-Via: bh-25.webhostbox.net: authenticated_id: guenter@roeck-us.net X-Authenticated-Sender: bh-25.webhostbox.net: guenter@roeck-us.net X-Source: X-Source-Args: X-Source-Dir: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org gcc 8.1.0 complains: lib/kobject.c:128:3: warning: 'strncpy' output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation] lib/kobject.c: In function 'kobject_get_path': lib/kobject.c:125:13: note: length computed here Using strncpy() is indeed less than perfect since the length of data to be copied has already been determined with strlen(). Replace strncpy() with memcpy() to address the warning and optimize the code a little. Signed-off-by: Guenter Roeck --- lib/kobject.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/kobject.c b/lib/kobject.c index 18989b5b3b56..e876957743c8 100644 --- a/lib/kobject.c +++ b/lib/kobject.c @@ -125,7 +125,7 @@ static void fill_kobj_path(struct kobject *kobj, char *path, int length) int cur = strlen(kobject_name(parent)); /* back up enough to print this name with '/' */ length -= cur; - strncpy(path + length, kobject_name(parent), cur); + memcpy(path + length, kobject_name(parent), cur); *(path + --length) = '/'; } -- 2.7.4