Skip to content

Commit

Permalink
Merge pull request #4 from ansemjo/pr-trim-crlf-whitespace
Browse files Browse the repository at this point in the history
trim line ending whitespace when reading ihex file
  • Loading branch information
Polarisru authored Feb 23, 2020
2 parents 3741ea7 + 3dd4a83 commit 50c7477
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions ihex.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include "ihex.h"

Expand Down Expand Up @@ -131,13 +132,18 @@ uint8_t IHEX_ReadFile(FILE *fp, uint8_t *data, uint16_t maxlen, uint16_t *max_ad
uint8_t i;
uint8_t byte;
char str[128];
char *end;

addr = 0;
segment = 0;
while (!feof(fp))
{
if (fgets(str, sizeof(str), fp) == NULL)
return IHEX_ERROR_FILE;
// trim whitespace on the right
end = str + strlen(str) - 1;
while (end > str && isspace((unsigned char) *end)) end--;
end[1] = '\0';
if (strlen(str) < IHEX_MIN_STRING)
return IHEX_ERROR_FMT;
len = IHEX_GetByte(&str[IHEX_OFFS_LEN]);
Expand Down
2 changes: 1 addition & 1 deletion ihex.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <stdbool.h>

#define IHEX_LINE_LENGTH 16
#define IHEX_MIN_STRING 12
#define IHEX_MIN_STRING 11

#define IHEX_OFFS_LEN 1
#define IHEX_OFFS_ADDR 3
Expand Down

0 comments on commit 50c7477

Please sign in to comment.