Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp3203704imm; Sun, 1 Jul 2018 15:12:23 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcXVpyS/FUe3NRIZxZUABYvssoUy5GkgI9Gdm+l1dGMzCpSUASt+C1JIBcSWP0x1Numq6sU X-Received: by 2002:a62:2b4c:: with SMTP id r73-v6mr18747441pfr.134.1530483143015; Sun, 01 Jul 2018 15:12:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530483142; cv=none; d=google.com; s=arc-20160816; b=sd/PPKKsuEpj9VB/VHh3zNy2uqClMLesFlU7hyF0zDZ0jW8VQhfssBFFQrclL8wJ/0 /A+8owvFhWB7VGEMUrpNKSbdAzPOTwL1DHnDHbf1eaR1iS3Du/joPUe13wyywbIuFS6H Uc2JDk+VxvCEcG30VJwDHQa9422WQ04RNKftgwniyq9KF/vU8kal8fo4vkwIR0ASHIrW hEgA8bizZgSQe99fL2dNcB/MdWXIZI8FJMrKpxpzbbmUBllhbfxw3vn5QXgakd/1ml6t dn0/m3wMgQBPe67ae7PRa52dOU9cqTc+aGX6WMEKZgJwpBpYu9FHv/ZejxB7tYse/4VL Al1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:organization:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:mail-followup-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=DRI+Yg3gUSCDdiOVIAt53Qnd3ZfWEY+TK4PT0C0/QNo=; b=G0+xx32BvkSojQS06q52zKb+x4ukC1H+UdrRovP6fKzBDyJHIRQQfasG1bYQyYaSiC tmCjB9d8qGey7ss9fZPwE2JMBPuhYBTlrHVQMIQYpwuMazMqCw+2cno5nmd9O6WitJ6j dTqzHUR4LpsqqqRfv3CBAE11xVyWPA9lt3p0lTawaPHy1oTo6GaMfW/OsOv3RWRicyTV dR0Fr9WzWLe6j0uZR1Md4hmmhktboKOK6eZPhm2iGlC/HuzRH2rDjMq9TJp8qvcjD7LR RDtDQb8PIIEGe2YFy/7/8uhhUXp/uCiZgEtax8m7Qhoq0owkdKrsUlEmfUq8IeOeBFht VxSQ== ARC-Authentication-Results: i=1; mx.google.com; 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 n61-v6si14102372plb.256.2018.07.01.15.12.08; Sun, 01 Jul 2018 15:12:22 -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; 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 S1752592AbeGAWKb (ORCPT + 99 others); Sun, 1 Jul 2018 18:10:31 -0400 Received: from hera.aquilenet.fr ([185.233.100.1]:48006 "EHLO hera.aquilenet.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752457AbeGAWK2 (ORCPT ); Sun, 1 Jul 2018 18:10:28 -0400 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id A79B76A56; Mon, 2 Jul 2018 00:10:26 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 15vvNgbouel4; Mon, 2 Jul 2018 00:10:25 +0200 (CEST) Received: from var.youpi.perso.aquilenet.fr (static-176-158-111-12.ftth.abo.bbox.fr [176.158.111.12]) by hera.aquilenet.fr (Postfix) with ESMTPSA id B290E176; Mon, 2 Jul 2018 00:10:25 +0200 (CEST) Received: from samy by var.youpi.perso.aquilenet.fr with local (Exim 4.91) (envelope-from ) id 1fZkY3-0001jx-Ts; Mon, 02 Jul 2018 00:10:23 +0200 Date: Mon, 2 Jul 2018 00:10:23 +0200 From: Samuel Thibault To: Guenter Roeck Cc: Chris Brannon , devel@driverdev.osuosl.org, Greg Kroah-Hartman , Kirk Reiser , linux-kernel@vger.kernel.org, speakup@linux-speakup.org, William Hubbs Subject: Re: [PATCH] staging: speakup: Replace strncpy with memcpy Message-ID: <20180701221023.2fkpyv4jetf2zgjo@var.youpi.perso.aquilenet.fr> Mail-Followup-To: Samuel Thibault , Guenter Roeck , Chris Brannon , devel@driverdev.osuosl.org, Greg Kroah-Hartman , Kirk Reiser , linux-kernel@vger.kernel.org, speakup@linux-speakup.org, William Hubbs References: <1530478644-16857-1-git-send-email-linux@roeck-us.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1530478644-16857-1-git-send-email-linux@roeck-us.net> Organization: I am not organized User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Guenter Roeck, le dim. 01 juil. 2018 13:57:24 -0700, a ecrit: > 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 Reviewed-by: Samuel Thibault > --- > 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 > -- Samuel Tu as lu les docs. Tu es devenu un informaticien. Que tu le veuilles ou non. Lire la doc, c'est le Premier et Unique Commandement de l'informaticien. -+- TP in: Guide du Linuxien pervers - "L'évangile selon St Thomas"