NetBSD Problem Report #50911
From www@NetBSD.org Mon Mar 7 12:23:24 2016
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (verified OK))
by mollari.NetBSD.org (Postfix) with ESMTPS id 8E16A7A13F
for <gnats-bugs@gnats.NetBSD.org>; Mon, 7 Mar 2016 12:23:24 +0000 (UTC)
Message-Id: <20160307122323.B155E7ACBA@mollari.NetBSD.org>
Date: Mon, 7 Mar 2016 12:23:23 +0000 (UTC)
From: dcb314@hotmail.com
Reply-To: dcb314@hotmail.com
To: gnats-bugs@NetBSD.org
Subject: src/usr.sbin/makefs/chfs/chfs_mkfs.c:134: clumsy call to memset ?
X-Send-Pr-Version: www-1.0
>Number: 50911
>Category: bin
>Synopsis: src/usr.sbin/makefs/chfs/chfs_mkfs.c:134: clumsy call to memset ?
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: bin-bug-people
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon Mar 07 12:25:00 +0000 2016
>Closed-Date: Mon Mar 07 16:10:59 +0000 2016
>Last-Modified: Mon Mar 07 16:10:59 +0000 2016
>Originator: David Binderman
>Release: cvs dated 20160305
>Organization:
>Environment:
>Description:
[src/usr.sbin/makefs/chfs/chfs_mkfs.c:127] -> [src/usr.sbin/makefs/chfs/chfs_mkfs.c:134]: (performance) Buffer 'buf' is being written before its old content has been used.
Source code is
memset(buf, 0xFF, opts->pagesize);
ebhdr.ec_hdr.magic = htole32(CHFS_MAGIC_BITMASK);
ebhdr.ec_hdr.erase_cnt = htole32(1);
ebhdr.ec_hdr.crc_ec = htole32(crc32(0,
(uint8_t *)&ebhdr.ec_hdr + 8, 4));
memcpy(buf, &ebhdr.ec_hdr, CHFS_EB_EC_HDR_SIZE);
Maybe better code
ebhdr.ec_hdr.magic = htole32(CHFS_MAGIC_BITMASK);
ebhdr.ec_hdr.erase_cnt = htole32(1);
ebhdr.ec_hdr.crc_ec = htole32(crc32(0,
(uint8_t *)&ebhdr.ec_hdr + 8, 4));
memcpy(buf, &ebhdr.ec_hdr, CHFS_EB_EC_HDR_SIZE);
memset(buf + CHFS_EB_EC_HDR_SIZE, 0xFF, opts->pagesize - CHFS_EB_EC_HDR_SIZE);
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/50911 CVS commit: src/usr.sbin/makefs/chfs
Date: Mon, 7 Mar 2016 10:58:05 -0500
Module Name: src
Committed By: christos
Date: Mon Mar 7 15:58:05 UTC 2016
Modified Files:
src/usr.sbin/makefs/chfs: chfs_mkfs.c
Log Message:
PR/50911: David Binderman: Optimize memset
To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/makefs/chfs/chfs_mkfs.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: open->closed
State-Changed-By: wiz@NetBSD.org
State-Changed-When: Mon, 07 Mar 2016 16:10:59 +0000
State-Changed-Why:
Fixed by christos, thanks!
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.