public inbox for linux-m68k@lists.linux-m68k.org
 help / color / mirror / Atom feed
* arch/m68k/mac/oss.c:51: bad for loop ?
@ 2015-03-27 16:15 David Binderman
  2015-03-28  4:18 ` Finn Thain
  0 siblings, 1 reply; 2+ messages in thread
From: David Binderman @ 2015-03-27 16:15 UTC (permalink / raw)
  To: funaho@jurai.org, linux-m68k@lists.linux-m68k.org

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 majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: arch/m68k/mac/oss.c:51: bad for loop ?
  2015-03-27 16:15 arch/m68k/mac/oss.c:51: bad for loop ? David Binderman
@ 2015-03-28  4:18 ` Finn Thain
  0 siblings, 0 replies; 2+ messages in thread
From: Finn Thain @ 2015-03-28  4:18 UTC (permalink / raw)
  To: David Binderman; +Cc: funaho@jurai.org, linux-m68k@lists.linux-m68k.org

[-- Attachment #1: Type: TEXT/PLAIN, Size: 900 bytes --]


On Fri, 27 Mar 2015, David Binderman wrote:

> 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;
>     }

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!

-- 

> 
> Regards
> 
> David Binderman
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-03-28  4:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-27 16:15 arch/m68k/mac/oss.c:51: bad for loop ? David Binderman
2015-03-28  4:18 ` Finn Thain

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox