stk500v2_recv(): Make length computation unsigned so

it cannot accidentally become negative.


git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@767 81a1dc3b-b13d-400b-aceb-764788c761c2
This commit is contained in:
Joerg Wunsch 2008-01-26 08:01:51 +00:00
parent 2b64213cdc
commit 255f873185
2 changed files with 11 additions and 6 deletions

View File

@ -0,0 +1,5 @@
2008-01-26 Joerg Wunsch <j.gnu@uriah.heep.sax.de>
* stk500v2.c (stk500v2_recv): Make length computation unsigned so
it cannot accidentally become negative.

View File

@ -390,8 +390,8 @@ static int stk500v2_jtagmkII_recv(PROGRAMMER * pgm, unsigned char msg[],
static int stk500v2_recv(PROGRAMMER * pgm, unsigned char msg[], size_t maxsize) { static int stk500v2_recv(PROGRAMMER * pgm, unsigned char msg[], size_t maxsize) {
enum states { sINIT, sSTART, sSEQNUM, sSIZE1, sSIZE2, sTOKEN, sDATA, sCSUM, sDONE } state = sSTART; enum states { sINIT, sSTART, sSEQNUM, sSIZE1, sSIZE2, sTOKEN, sDATA, sCSUM, sDONE } state = sSTART;
int msglen = 0; unsigned int msglen = 0;
int curlen = 0; unsigned int curlen = 0;
int timeout = 0; int timeout = 0;
unsigned char c, checksum = 0; unsigned char c, checksum = 0;
@ -438,13 +438,13 @@ static int stk500v2_recv(PROGRAMMER * pgm, unsigned char msg[], size_t maxsize)
break; break;
case sSIZE1: case sSIZE1:
DEBUGRECV("hoping for size LSB\n"); DEBUGRECV("hoping for size LSB\n");
msglen = c*256; msglen = (unsigned)c * 256;
state = sSIZE2; state = sSIZE2;
break; break;
case sSIZE2: case sSIZE2:
DEBUGRECV("hoping for size MSB..."); DEBUGRECV("hoping for size MSB...");
msglen += c; msglen += (unsigned)c;
DEBUG(" msg is %d bytes\n",msglen); DEBUG(" msg is %u bytes\n",msglen);
state = sTOKEN; state = sTOKEN;
break; break;
case sTOKEN: case sTOKEN:
@ -495,7 +495,7 @@ static int stk500v2_recv(PROGRAMMER * pgm, unsigned char msg[], size_t maxsize)
} /* while */ } /* while */
DEBUG("\n"); DEBUG("\n");
return msglen+6; return (int)(msglen+6);
} }