Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp3160252imm; Sun, 1 Jul 2018 14:00:26 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfoAj5ZXZT+xKXynvq/avLgzwhqoCRXwhhg201HHblbQX8GOA84WtFTTln5gkJwG+shGS8G X-Received: by 2002:a62:4015:: with SMTP id n21-v6mr22718680pfa.198.1530478826122; Sun, 01 Jul 2018 14:00:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530478826; cv=none; d=google.com; s=arc-20160816; b=a5Ut7bGV3Wmn9bh7xSoRzGx1W9HSRpIuBDg3LcnxdWRxBfio0Q89dVBKNMZh9fygPB w1FhlN7uEfFABqvsJza3KCNC/KRZes8SAzeq0h4uiWWwwfHaQgEg3e4i30hk9ZEmjfJi M2tC6jQEsScupFwBPq7hp+eu1/KD9oY2xx9Ht3/6oeuf3XNEWzVW4wY/5AXPQt4xjBLi xmS4ckBBGqFLOK5ebxkb3tpy6Zvgjehm2rkEHMxEx/n1hS6ubdUU/WorOrK9QBQb2yNb BmV7Wf43t1JjpByHMxwx1cxcEal4j+igj7FleOYvyDOS2fzUv8CFjKOUllItKllvnoBt CKtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=vL0zSIuefsr+axgAw6y4nES0Np/wsCitjF58yF9hvNU=; b=hXLEvNIgx63ulWwRAgpl11wW3JdzW2fB3lwnR0ZAYBuC4cM3LFjcNW04EKChQ5RAfG Xa0hZtgyG2YiiF8xV8pAUSASjdmUqP3hfeqS2zchPpmQMh6k+yB72NzDQVL/cfuvQjgK PJONdAwEyXMZuP5nCsgeioXs2EsJYTS6bocW72U2dA+Ph8ZAZdTJKrTDtLI+/PyO1bcy Ra6RXDLVxCUZsBicVjM3ak1GTu3dFo1If6lxEnhyNdrz16Ca1Vxsa8wX4Cuf/hPSSDlH 8xXWUb1SfrmYcWfuyTdZXgOHdtgrWOXNxcni4cAwZbpzYneQHOgp4hgIYdId2xpZDFF3 4/JQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@roeck-us.net header.s=default header.b="vJ2ly/2/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c32-v6si14315331plj.277.2018.07.01.14.00.11; Sun, 01 Jul 2018 14:00:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@roeck-us.net header.s=default header.b="vJ2ly/2/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752726AbeGAU5c (ORCPT + 99 others); Sun, 1 Jul 2018 16:57:32 -0400 Received: from bh-25.webhostbox.net ([208.91.199.152]:53836 "EHLO bh-25.webhostbox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752535AbeGAU52 (ORCPT ); Sun, 1 Jul 2018 16:57:28 -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=vL0zSIuefsr+axgAw6y4nES0Np/wsCitjF58yF9hvNU=; b=vJ2ly/2/1u13bRipPFnLO9jl9W YLG9HomvGmLZtgijO4/iI07fe5EQP1vm2ci+XZZppr9zz+97mWWtf0fy4TjyWlV0XeFev88O2vkQ1 Fh46tNuccOFzuMqnJtxhZYOeAz7UncVTNkwkGQ6IBqCnLiQgM8s4LxdnPy9noCb9pr3QJ5EYONSEw YInqa2nI2nCw4memcdttrM826AO8YAFLae5EtcAkMhj0aVK2AaN4hc1rIhHp88YdZANruAsTrvCby 72lor3osUOT4f1Iw0jsTSVB0+2Ii2zXONiCyDl/77ZSwXdoPyvOBFfR9dvxHoM5GT6sO/+eq/5jh/ zMiO116A==; Received: from 108-223-40-66.lightspeed.sntcca.sbcglobal.net ([108.223.40.66]:48692 helo=localhost) by bh-25.webhostbox.net with esmtpa (Exim 4.89) (envelope-from ) id 1fZjPS-007eCp-NC; Sun, 01 Jul 2018 20:57:27 +0000 From: Guenter Roeck To: Chris Brannon Cc: devel@driverdev.osuosl.org, Greg Kroah-Hartman , Kirk Reiser , linux-kernel@vger.kernel.org, Samuel Thibault , speakup@linux-speakup.org, William Hubbs , Guenter Roeck Subject: [PATCH] staging: speakup: Replace strncpy with memcpy Date: Sun, 1 Jul 2018 13:57:24 -0700 Message-Id: <1530478644-16857-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 generates the following warnings. drivers/staging/speakup/kobjects.c: In function 'punc_store': drivers/staging/speakup/kobjects.c:522:2: warning: 'strncpy' output truncated before terminating nul copying as many bytes from a string as its length drivers/staging/speakup/kobjects.c:504:6: note: length computed here drivers/staging/speakup/kobjects.c: In function 'synth_store': drivers/staging/speakup/kobjects.c:391:2: warning: 'strncpy' output truncated before terminating nul copying as many bytes from a string as its length drivers/staging/speakup/kobjects.c:388:8: 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 --- drivers/staging/speakup/kobjects.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/staging/speakup/kobjects.c b/drivers/staging/speakup/kobjects.c index f1f90222186b..08f11cc17371 100644 --- a/drivers/staging/speakup/kobjects.c +++ b/drivers/staging/speakup/kobjects.c @@ -388,7 +388,7 @@ static ssize_t synth_store(struct kobject *kobj, struct kobj_attribute *attr, len = strlen(buf); if (len < 2 || len > 9) return -EINVAL; - strncpy(new_synth_name, buf, len); + memcpy(new_synth_name, buf, len); if (new_synth_name[len - 1] == '\n') len--; new_synth_name[len] = '\0'; @@ -519,7 +519,7 @@ static ssize_t punc_store(struct kobject *kobj, struct kobj_attribute *attr, return -EINVAL; } - strncpy(punc_buf, buf, x); + memcpy(punc_buf, buf, x); while (x && punc_buf[x - 1] == '\n') x--; -- 2.7.4