c++ - Runtime error dividing by -1 -
c++ - Runtime error dividing by -1 -
i don't uncertainty need check partition zero. i've never heard of checking partition negative 1 though!
if( *y == 0 ) homecoming 0; //undefined else homecoming *x / *y; x, y pointers int32_t, include detail in case of relevance.
at runtime, if *x==0x80000000, *y==0xffffffff, error (in xcode):
exc_arithmetic (code=exc_i386_div, subcode=0x0)
all can find online suggestions partition zero, can see check above, , can see debug window, not case here.
what error mean, , how can prepare it?
2's complement representation asymmetric: there 1 more negative number positive number, , negative number has no positive counterpart. consequently, negating min_int integer overflow (where min_int value 1-bit sign bit, 0x80000000 32-bit integers).
min_int / -1 is, therefore, arithmetic overflow. unlike overflow subtraction (which checked), overflow when dividing can cause trap, , apparently that's happening in case.
and, yes, technically speaking should check min_int / -1 overflow case before dividing, because result undefined.
note: in mutual case of intel x64 architecture, partition overflow trap, same partition 0. confusingly, corresponding posix signal sigfpe thought of "floating point exception", although there no floating point in sight. current posix standard glosses sigfpe meaning "erroneous arithmetic operation".
c++ xcode integer-division secure-coding
Comments
Post a Comment