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]
Date:	Wed, 16 Sep 2015 09:25:56 +0200
From:	Clemens Ladisch <clemens@...isch.de>
To:	Aaro Koskinen <aaro.koskinen@....fi>,
	Eric Curtin <ericcurtin17@...il.com>
Cc:	valentina.manea.m@...il.com, shuah.kh@...sung.com,
	linux-usb@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: tools: usbip: detach: avoid calling strlen() at each iteration

Aaro Koskinen wrote:
> On Tue, Sep 15, 2015 at 09:27:20PM +0100, Eric Curtin wrote:
>> -	for (unsigned int i = 0; i < strlen(port); i++)
>> +	unsigned int port_len = strlen(port);
>> +
>> +	for (unsigned int i = 0; i < port_len; i++)
>
> port is read only in this function, so maybe just use "const" and the
> compiler should know to do the same without adding a new variable?

If the compiler knows the implementation of strlen() (because it's
a built-in function), then it sees that nobody modifies port[] in the
loop.  If the compiler does not know the implementation of strlen()
(because -fno-builtins is used), then it is possible that some other
function has a valid non-const pointer and modifies the data through it.

(Anyway, the detach_port() function is not time critical, so I don't
think that optimizing it is worthwhile if it reduces readability.  But
seeing the strlen() call at that place grates on me; I'm not against
moving it out of the loop.)

The loop goes through the string one character at a time, so it might
be possible to drop strlen() altogether and just stop the loop when the
end of the string is reached.

But the actual purpose of the loop is to check whether there is a valid
number.  This could be done more easily by replacing the loop and the
following atoi() call with strtol().


Regards,
Clemens
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists