Hi, just a few word to say that I have tried to implement such a class, but I have currently failed to have something working. There are lot of implicit cast to int, and that leads to ambiguity between operators acting on int and those actinng on UnsignedInt. I will continue to try but not too long.
Regards, Matt (gentildemon) Le 07/02/2010 14:09, Matthieu Fertré a écrit : > Hi, > > I'm quite fed up with integer overflow/wrap. Unsigned integers in > particular are particularly dangerous [1]. Last week, I have again fixed > a bug related to unsigned int wrap (uint length = 0 - 4, the result of > this operation gives a very big number, not zero nor -4) > > One friend suggests me to implement an UnsignedInt class, redefining > operators, so that it ensures that unsigned never begans negative and > launches assertion failure when it happens. Then, we just have to > "typedef uint UnsignedInt" instead of "typedef uint unsigned int". > > Are you ok with that ? (The class may optionnally be used only in debug > mode) > > Regards, > > Matt (gentildemon) > > > [1] > https://www.securecoding.cert.org/confluence/display/cplusplus/INT30-CPP.+Ensure+that+unsigned+integer+operations+do+not+wrap > > > _______________________________________________ > Wormux-dev mailing list > [email protected] > https://mail.gna.org/listinfo/wormux-dev > > _______________________________________________ Wormux-dev mailing list [email protected] https://mail.gna.org/listinfo/wormux-dev
