On 11 February 2012 09:53, Richard Bown
<[email protected]> wrote:
> I was going to say "that bit of smugness is going to come back and bite him
> in the ass" but of course I didn't..

On this note: today I got a bug report on a project of mine, where the
bug was arguably caused by my having used signed instead of unsigned
integers.

The situation was a pretty familiar one in the MIDI or audio-file
handling of software like Rosegarden -- it was decoding a sequence of
bytes (stored in a std::string) into a series of integer values by
pulling out individual bytes and composing them by bit-shifting (take
the high-order byte, shift by 8, take the next byte, add and shift
etc).

The problem was that the byte values were assigned to signed integers,
and in some cases these came out negative, giving a completely bogus
result. The proposed fix was to assign to unsigneds instead.

The only reason I say the problem was "arguably" caused by using
signed integers is that the real root of the problem is storing byte
sequences in std::string in the first place. std::string is a sequence
of plain char, not signed or unsigned char, so the signedness of its
elements is platform-dependent. Assigning these into signed values
then materialised the problem.


Chris

------------------------------------------------------------------------------
Keep Your Developer Skills Current with LearnDevNow!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-d2d
_______________________________________________
Rosegarden-devel mailing list
[email protected] - use the link below to unsubscribe
https://lists.sourceforge.net/lists/listinfo/rosegarden-devel

Reply via email to