lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <30f3ac625d734674aa6697440aa3253f@AcuMS.aculab.com>
Date:   Fri, 15 Jun 2018 09:10:52 +0000
From:   David Laight <David.Laight@...LAB.COM>
To:     'Paul Clarke' <pc@...ibm.com>,
        Thomas Richter <tmricht@...ux.ibm.com>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "linux-perf-users@...r.kernel.org" <linux-perf-users@...r.kernel.org>,
        "acme@...nel.org" <acme@...nel.org>,
        "jolsa@...hat.com" <jolsa@...hat.com>
CC:     "brueckner@...ux.vnet.ibm.com" <brueckner@...ux.vnet.ibm.com>,
        "schwidefsky@...ibm.com" <schwidefsky@...ibm.com>,
        "heiko.carstens@...ibm.com" <heiko.carstens@...ibm.com>
Subject: RE: [PATCH 1/3] perf alias: Remove trailing newline when reading
 sysfs files

From: Paul Clarke
> Sent: 14 June 2018 14:18
...
> > +	/* Remove trailing newline from sysfs file */
> > +	cp = strrchr(buf, '\n');
> > +	if (cp)
> > +		*cp = '\0';
> 
> A nit, perhaps, but this will search backwards through the entire string if a newline is not found,
> which is the most common case, I presume.  Would it be more efficient to just look at the last
> character?  Something like:
> i = strlen(buf);
> if (i > 0 && buf[i-1] == '\n')
>   buf[i-1] = '\0';

Worse it will do horrid things of the output has multiple lines of text
without a newline at the end.

Both strlen() and strrhr() need to scan the entire string.
However since strlen is only looking for one value it should be much
more efficient - especially on 64bit systems where shifts and bit
operations can be used to find the 64bit word containing the first
zero byte.

I suspect rtrim() has an extra data cache miss.

	David

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ