|
|
Subscribe / Log in / New account

Stagefrightening

Stagefrightening

Posted Aug 1, 2015 23:56 UTC (Sat) by mathstuf (subscriber, #69389)
In reply to: Stagefrightening by error27
Parent article: Stagefrightening

> Also we often use integer overflows to test for integer overflows like this "if (foo + bar < foo)".

Sounds like something worth a __builtin_will_overflow function to explicitly denote such uses.


to post comments

Stagefrightening

Posted Aug 2, 2015 11:14 UTC (Sun) by kleptog (subscriber, #1183) [Link] (2 responses)

In gcc you can just say: if(__builtin_add_overflow(foo, bar, &sum)) { error("Overflow"); }

See: https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Built...

Other compilers have similar features: https://msdn.microsoft.com/en-us/library/windows/desktop/...

It's not these these features don't exist, it's that (a) they're not standardised and (b) people aren't using them.

Stagefrightening

Posted Aug 2, 2015 13:03 UTC (Sun) by mathstuf (subscriber, #69389) [Link] (1 responses)

Yep, much better interface there since you don't waste the computation.

> It's not these these features don't exist, it's that (a) they're not standardised

Why would this matter for, at least, the kernel?

Stagefrightening

Posted Aug 3, 2015 21:08 UTC (Mon) by kleptog (subscriber, #1183) [Link]

> > It's not these these features don't exist, it's that (a) they're not standardised

>Why would this matter for, at least, the kernel?

For the kernel it doesn't matter so much, other than it's new (GCC 5.0 new to be precise). But you could probably whip these up in an afternoon in assembly if you wanted to, I think it's telling that this hasn't happened. You don't need compiler support to make these functions, it just makes it easier. The kernel devs could have implemented it years ago if they wanted to.

For all user space applications not being standardised makes it hard because you'd really rather not rely on special compiler features.

Stagefrightening

Posted Aug 2, 2015 11:31 UTC (Sun) by PaXTeam (guest, #24616) [Link]


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds