Reply to post: Re: Need trapping

BadAlloc: Microsoft looked at memory allocation code in tons of devices and found this one common security flaw

ThomH

Re: Need trapping

But in this case you'd want INTC, if it existed, as the arithmetic is unsigned. 0xffffffff + 7 is a negative plus a positive, so it doesn't set the overflow flag.

To be completely explicit: overflow indicates that you added two signed numbers and got a number of the wrong sign as a result. Such is the range of two's complement arithmetic, that can never occur if you add numbers of different signs. You can get overflow only if you add two negative numbers and the result is positive, or if you add two positive numbers and the result is negative.

Conversely, when adding two unsigned numbers such as here, the carry flag indicates that the true result is too large to fit into a single word.

POST COMMENT House rules

Not a member of The Register? Create a new account here.

  • Enter your comment

  • Add an icon

Anonymous cowards cannot choose their icon