avrdude-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avrdude-dev] Minor efficiency question


From: Larry Colen
Subject: [avrdude-dev] Minor efficiency question
Date: Fri, 16 Dec 2011 01:25:31 -0800
User-agent: Mozilla/5.0 (Windows NT 5.1; rv:8.0) Gecko/20111105 Thunderbird/8.0


As I posted to the list a couple of days ago, I'm trying to figure out
why perfectly legitimate hex files are causing avrdude to give me errors. In the process of trying to understand what the relevant code is doing I found what seems to be an error in the code, though it's more of an inefficiency.

At about line 175 in fileio.c, in ihex_readrec(), there is a test at the beginning that there are at least two characters available for the byte count:

  if (offset + 2 > len)              
    return -1;

The way I read the description of the intel hex format the minimum legal length of a record is 11 bytes. It seems to me that if the function were just to test that the record length were at least 9, once it was computed, you could drop several of the intermediate checks that the record was long enough to make the next calculation.

//  :ccAAAA0tDDDDDDDDss
//   cc                  Byte count
//     AAAA              Address
//         0t            Record Type
//           DDDDDDDD    Data
//                   ss  Checksum

If each case where the test for length could fail, a different error code were returned, I could see some diagnostic use for the multiple tests, but since they all just return -1, it seems that you could save a few CPU cycles for each record by just making sure that the length were greater than the minimum, and then that the length and the cc value agreed with each other.

  Larry

--
Larry Colen address@hidden (from dos4est)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]