[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [trivial for-2.6] util/id: fully allocate names table
From: |
Markus Armbruster |
Subject: |
Re: [Qemu-devel] [trivial for-2.6] util/id: fully allocate names table |
Date: |
Wed, 25 Nov 2015 11:27:24 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) |
Kevin Wolf <address@hidden> writes:
> Am 25.11.2015 um 09:18 hat Markus Armbruster geschrieben:
>> John Snow <address@hidden> writes:
>>
>> > Trivial: this array should be allocated to have ID_MAX entries always.
>> > Otherwise if someone were to forget to expand this table, the assertion
>> > in the id generator won't actually trigger; it will read junk data.
>>
>> You mean this one:
>>
>> assert(id < ID_MAX);
>>
>> The assertion is crap, because it fails to protect array access
>> id_subsys_str[id]. Here's one that does:
>>
>> assert(0 <= id && id < ARRAY_SIZE(id_subsys_str));
>
> Or without the kraxelism id >= 0. However, depending on whether enums
> are signed or unsigned, I seem to remember that this could trigger
> compiler warnings (comparison is always true). And this one should be
> unsigned with gcc because it doesn't include negative values.
Whatever it takes to express the range check in a way the compiler
likes.
Since ARRAY_SIZE()'s value is size_t, and size_t is unsigned, the
comparison with 0 can simply be omitted.