X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=packihx%2Fpackihx.c;h=a9cf4e7a48785ed808036485f68faf3dc81f66a2;hb=d5e163c45df3f0603c1f52c7d4467b60a5e0afee;hp=8675f19038ca5a529bc4a762732cc6fcc7d58cd6;hpb=b146a9306d02808940e6344a71259cfe6056a05e;p=fw%2Fsdcc diff --git a/packihx/packihx.c b/packihx/packihx.c index 8675f190..a9cf4e7a 100644 --- a/packihx/packihx.c +++ b/packihx/packihx.c @@ -1,7 +1,7 @@ /*----------------------------------------------------------------------- * packihx.c: * - * utility to pack an Inter HEX format file by removing redundant + * utility to pack an Intel HEX format file by removing redundant * extended offset records and accumulating data records up to * OUTPUT_CHUNK (currently 16) bytes. * @@ -14,13 +14,21 @@ #include #include +#if defined(_MSC_VER) || defined(__BORLANDC__) + +typedef unsigned char Uint8 ; +typedef unsigned Uint16 ; + +#else + #include "config.h" +#endif /* A cooked line of input. */ typedef struct _Line { Uint8 len; /* length of data portion of record. */ - Uint16 offset; + Uint16 offset; Uint8 type; Uint8 *data; Uint8 checksum; @@ -98,7 +106,7 @@ Line *readLine(FILE *inFile) { return NULL; } - ++lineno; + ++lineno; if (!buffer[0] || buffer[0] == '\r' || buffer[0] == '\n') { @@ -144,8 +152,10 @@ Line *readLine(FILE *inFile) return NULL; } bp += 2; /* Two digits consumed. */ - - line->data = (Uint8 *)malloc(line->len); + + /* Hack - always allocate something, even if len is zero. + * Avoids special case for len == 0. */ + line->data = (Uint8 *)malloc(line->len ? line->len : 1); if (!line->data) { free(line); @@ -153,7 +163,7 @@ Line *readLine(FILE *inFile) return NULL; } - for (i = 0; i < line->len; i++) + for (i = 0; i < (unsigned)line->len; i++) { if (getHexByte(bp, &(line->data[i]))) { @@ -175,7 +185,7 @@ Line *readLine(FILE *inFile) free(line); return NULL; } - bp += 2; /* Two digits consumed. */ + /* bp += 2; */ /* Two digits consumed. */ return line; } @@ -184,7 +194,7 @@ Line *readLine(FILE *inFile) Uint16 lineChecksum(unsigned len, unsigned offset, unsigned type, const Uint8 *data) { - Uint16 checksum = 0; + Uint16 checksum; unsigned i; checksum = len + type + (offset >> 8) + @@ -213,7 +223,7 @@ int validateChecksum(Line *line) if (checksum != line->checksum) { fprintf(stderr, "packihx: invalid checksum %X (want %X) @ line %d\n", - (unsigned)checksum, (unsigned)(line->checksum), + (unsigned)(line->checksum), (unsigned)checksum, lineno); return -1; } @@ -300,7 +310,7 @@ int flushPendingData(void) int writeLine(Line *line) { static Uint16 lastExtendedOffset = 0; - int rc = 0; + int rc; if (line->type) { @@ -341,7 +351,7 @@ int writeLine(Line *line) } else { - if (pendingOffset + pendingLen != line->offset) + if (pendingOffset + pendingLen != (unsigned)line->offset) { /* This line is not contigous with the last one. Dump pending. */ if (flushPendingData())