ArduinoISP.pde provided with Arduino 0022, line 364
int length = 256 * getch() + getch();
With the GNU compiler, if 0x00 is received first and then 0x80 is received second, then this evaluates to
int length = 256 * 0x00 + 0x80;
and the result of "length" is 128 as expected
However, if this code is ported to another compiler, the following happens
int length = 256 * 0x80 + 0x00;
the result of "length" is 0x8000, which is not the expected result. This has caused a port of the ArduinoISP code to fail by running the for loop on line 343 for longer than what avrdude specified, causing a timeout.
please see http://en.wikipedia.org/wiki/Sequence_point
about the nature of the problem
Consider two functions f() and g(). In C and C++, the + operator is not a sequence point, and therefore in the expression f()+g() it is possible that either f() or g() will be executed first.
Due to this, I plead that the next release would use something like
unsigned char higherBits = getch();
unsigned char lowerBits = getch();
int length = 256 * higherBits + lowerBits;
There are several locations where this change needs to be made, the one I pointed out is only one such location.