/*-----------------------------------------------------------------------
* 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.
*
#include <ctype.h>
#include <assert.h>
+#if defined(_MSC_VER)
+
+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;
{
return NULL;
}
- ++lineno;
+ ++lineno;
if (!buffer[0] || buffer[0] == '\r' || buffer[0] == '\n')
{
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);
return NULL;
}
- for (i = 0; i < line->len; i++)
+ for (i = 0; i < (unsigned)line->len; i++)
{
if (getHexByte(bp, &(line->data[i])))
{
free(line);
return NULL;
}
- bp += 2; /* Two digits consumed. */
+ /* bp += 2; */ /* Two digits consumed. */
return line;
}
Uint16 lineChecksum(unsigned len, unsigned offset, unsigned type,
const Uint8 *data)
{
- Uint16 checksum = 0;
+ Uint16 checksum;
unsigned i;
checksum = len + type + (offset >> 8) +
int writeLine(Line *line)
{
static Uint16 lastExtendedOffset = 0;
- int rc = 0;
+ int rc;
if (line->type)
{
}
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())