[PATCH libdrm] xf86drm.c: Use integer logarithm.

Paul Gofman pgofman at codeweavers.com
Wed Oct 28 10:09:22 UTC 2020


On 10/28/20 11:18, Pekka Paalanen wrote:
>
>>  
>> +static unsigned log2_int(unsigned x)
>> +{
>> +    unsigned l;
>> +
>> +    if (x < 2) {
>> +        return 0;
>> +    }
>> +    for (l = 2; ; l++) {
>> +        if ((unsigned)(1 << l) > x) {
> Hi,
>
> wouldn't this loop fail to end when x >= 0x80000000?
>
> Sure, such value probably cannot occur where this is currently used,
> but it seems like a landmine for the next developer to step on.
>
Indeed, thanks. I've sent the patches for consideration which avoid
function duplication and potentially infinite loop.


More information about the dri-devel mailing list