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] [day] [month] [year] [list]
Date:	Tue, 02 Feb 2016 20:50:02 +0100
From:	Rasmus Villemoes <linux@...musvillemoes.dk>
To:	Andrew Morton <akpm@...ux-foundation.org>
Cc:	Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
	Tejun Heo <tj@...nel.org>,
	Linus Walleij <linus.walleij@...aro.org>,
	Dmitry Eremin-Solenikov <dbaryshkov@...il.com>,
	linux-kernel@...r.kernel.org, linux-pm@...r.kernel.org,
	"David S . Miller" <davem@...emloft.net>,
	David Airlie <airlied@...ux.ie>
Subject: Re: [PATCH v4 1/9] lib/string: introduce match_string() helper

On Tue, Feb 02 2016, Andrew Morton <akpm@...ux-foundation.org> wrote:

> On Thu, 28 Jan 2016 15:14:17 +0200 Andy Shevchenko <andriy.shevchenko@...ux.intel.com> wrote:
>
>> + * @array:	array of strings
>> + * @n:		number of strings in the array or -1 for NULL terminated arrays
>> + * @string:	string to match with
>> + *
>> + * Return:
>> + * index of a @string in the @array if matches, or %-ENODATA otherwise.
>> + */
>> +int match_string(const char * const *array, size_t n, const char *string)
>> +{
>> +	int index;
>> +	const char *item;
>> +
>> +	for (index = 0; index < n; index++) {
>
> So we're taking an int and comparing that with (size_t)-1, relying upon
> the compiler promoting the int to an unsigned type because size_t is
> unsigned.  It works, but it isn't pretty - there wasn't really much
> point in making size have type size_t.

n has unsigned type to make it easy to pass 'infinity'; *that's* where
we rely on integer promotion.

One could make index be unsigned int (or size_t), but it won't matter,
because it will never have a value where the type promotion (nor the
implicit cast back to int if/when it's used as a return value) changes
its value.

Rasmus

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ