From 255f873185c3a72f97dd50063e789e79aa5faf2e Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Sat, 26 Jan 2008 08:01:51 +0000 Subject: [PATCH] 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 --- ChangeLog | 5 +++++ stk500v2.c | 12 ++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index e69de29b..c3dbe603 100644 --- a/ChangeLog +++ b/ChangeLog @@ -0,0 +1,5 @@ +2008-01-26 Joerg Wunsch + + * stk500v2.c (stk500v2_recv): Make length computation unsigned so + it cannot accidentally become negative. + diff --git a/stk500v2.c b/stk500v2.c index b58fa004..a140cace 100644 --- a/stk500v2.c +++ b/stk500v2.c @@ -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) { enum states { sINIT, sSTART, sSEQNUM, sSIZE1, sSIZE2, sTOKEN, sDATA, sCSUM, sDONE } state = sSTART; - int msglen = 0; - int curlen = 0; + unsigned int msglen = 0; + unsigned int curlen = 0; int timeout = 0; unsigned char c, checksum = 0; @@ -438,13 +438,13 @@ static int stk500v2_recv(PROGRAMMER * pgm, unsigned char msg[], size_t maxsize) break; case sSIZE1: DEBUGRECV("hoping for size LSB\n"); - msglen = c*256; + msglen = (unsigned)c * 256; state = sSIZE2; break; case sSIZE2: DEBUGRECV("hoping for size MSB..."); - msglen += c; - DEBUG(" msg is %d bytes\n",msglen); + msglen += (unsigned)c; + DEBUG(" msg is %u bytes\n",msglen); state = sTOKEN; break; case sTOKEN: @@ -495,7 +495,7 @@ static int stk500v2_recv(PROGRAMMER * pgm, unsigned char msg[], size_t maxsize) } /* while */ DEBUG("\n"); - return msglen+6; + return (int)(msglen+6); }