Skip to contentSkip to conversation

arch/m68k/mac/oss.c:51: bad for loop ?

DISCUSSION David Binderman 2 participants 2 messages Mar 27, 2015 – Mar 28, 2015

lore
Share & tools
lore
#0 lore raw

Hello there,

arch/m68k/mac/oss.c:51:21: warning: iteration 16u invokes undefined behavior [-Waggressive-loop-optimizations]

    for (i = 0; i <= OSS_NUM_SOURCES; i++) {
        oss->irq_level[i] = 0;
    }

Maybe better code

    for (i = 0; i < OSS_NUM_SOURCES; i++) {
        oss->irq_level[i] = 0;
    }

Regards

David Binderman

--
To unsubscribe from this list: send the line "unsubscribe linux-m68k" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#1 lore raw
Quoted 9 lines · David Binderman

Hello there,

arch/m68k/mac/oss.c:51:21: warning: iteration 16u invokes undefined behavior [-Waggressive-loop-optimizations]

    for (i = 0; i <= OSS_NUM_SOURCES; i++) {
        oss->irq_level[i] = 0;
    }

Quoted 5 lines

Maybe better code

    for (i = 0; i < OSS_NUM_SOURCES; i++) {
        oss->irq_level[i] = 0;
    }

I agree. A quick look at arch/m68k/include/asm/mac_oss.h suggests (if not confirms) that this is a bug. I will send a patch though I won't be able to test that on suitable hardware as I'm out-of-town.

It is interesting that the compiler needs -Waggressive-loop-optimizations in order to detect the out-of-bounds array access. I suppose the loop has to be unrolled before the array index is checked.

Thankyou for the static analysis!

Quoted 5 lines

Regards

David Binderman