Giter Site home page Giter Site logo

Comments (3)

ansemjo avatar ansemjo commented on July 2, 2024

strlen(str) appears to be counting CRLF as two characters, therefore yielding an unexpected length. Completely trimming whitespace first and reducing the expected length by one fixes it for me and should be portable:

diff --git a/ihex.c b/ihex.c
index 860a8ad..642d54f 100644
--- a/ihex.c
+++ b/ihex.c
@@ -1,4 +1,5 @@
 #include <stdio.h>
+#include <ctype.h>
 #include <string.h>
 #include "ihex.h"
 
@@ -131,6 +132,7 @@ 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;
@@ -138,6 +140,10 @@ uint8_t IHEX_ReadFile(FILE *fp, uint8_t *data, uint16_t maxlen, uint16_t *max_ad
   {
     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]);
diff --git a/ihex.h b/ihex.h
index d2f2f83..e96c6cf 100644
--- a/ihex.h
+++ b/ihex.h
@@ -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

(taken from: https://stackoverflow.com/a/122721)

from updiprog.

Polarisru avatar Polarisru commented on July 2, 2024

Hello, thank you for your message, i will check it with Windows version and commit the fix as soon as possible.

from updiprog.

ansemjo avatar ansemjo commented on July 2, 2024

I've created a PR #4 for you with the above patch. :)

edit: attaching the source and firmware file if you need it for testing: blink.zip

from updiprog.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.