[Python-Dev] 2.4 vs Windows vs bsddb (original) (raw)
David Hopwood david.nospam.hopwood at blueyonder.co.uk
Wed Oct 11 00:49:48 CEST 2006
- Previous message: [Python-Dev] 2.4 vs Windows vs bsddb
- Next message: [Python-Dev] 2.4 vs Windows vs bsddb [correction]
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Tim Peters wrote:
Given that, the assert() in question looks fine to me:
if (dberrmsg[0] && bytesleft < (sizeof(errTxt) - 4)) {_ _bytesleft = sizeof(errTxt) - bytesleft - 4 - 1;_ _assert(bytesleft >= 0); We can't get into the block unless bytesleft < sizeof(errTxt) - 4_ _is true. Subtracting bytesleft from both sides, then swapping LHS and RHS:_ _sizeof(errTxt) - bytesleft - 4 > 0 which implies sizeof(errTxt) - bytesleft - 4 >= 1 Subtracting 1 from both sides: sizeof(errTxt) - bytesleft - 4 - 1 >= 0 And since the LHS of that is the new value of bytesleft, it must be true that bytesleft >= 0 Either that, or the original author (and me, just above) made an error in analyzing what must be true at this point.
You omitted to state an assumption that sizeof(errTxt) >= 4, since size_t (and the constant 4) are unsigned. Also bytes_left must initially be nonnegative so that the subexpression 'sizeof(errTxt) - bytes_left' cannot overflow.
-- David Hopwood <david.nospam.hopwood at blueyonder.co.uk>
- Previous message: [Python-Dev] 2.4 vs Windows vs bsddb
- Next message: [Python-Dev] 2.4 vs Windows vs bsddb [correction]
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]