add tests and fix memory leaks
authorLaurent Mazet <mazet@softndesign.org>
Fri, 28 Mar 2025 22:01:14 +0000 (23:01 +0100)
committerLaurent Mazet <mazet@softndesign.org>
Fri, 28 Mar 2025 22:01:14 +0000 (23:01 +0100)
morep_valid.c

index 83c712194c4975b5969a4d3709c6bd4dc009858d..f40d094b7d82d975fd12cd68adc7bd450f670d76 100644 (file)
@@ -108,7 +108,7 @@ int parse_line (char *line, uint8_t *msgtype, uint8_t **payload)
         } else if (strcmp ("PAYLOAD", var) == 0) {
             if ((*val == '"') && (val[strlen (val) - 1] == '"')) {
                 val++;
-                rc = strlen (val) - 1;
+                rc = strlen (val);
                 uint8_t *buf = *payload = (uint8_t *) calloc (rc, 1);
                 do {
                     *buf++ = *val++;
@@ -124,7 +124,7 @@ int parse_line (char *line, uint8_t *msgtype, uint8_t **payload)
                 fclose (fid);
             } else if (strlen (val) % 2 == 0) {
                 rc = strlen (val) / 2;
-                uint8_t *buf = *payload = (uint8_t *) calloc (rc / 2, 1);
+                uint8_t *buf = *payload = (uint8_t *) calloc (rc, 1);
                 while (*val != '\0') {
                     char digit[3] = {0};
                     digit[0] = *val++;
@@ -140,6 +140,7 @@ int parse_line (char *line, uint8_t *msgtype, uint8_t **payload)
             break;
         }
     }
+    free (str);
 
     return rc;
 }
@@ -360,5 +361,9 @@ int main (int argc, char **argv)
 }
 
 /* test: morep_valid.exe -h | grep usage */
+/* test: morep_valid.exe -r 2>&1 | grep 'url not specified' */
+/* test: morep_valid.exe -t 2>&1 | grep 'url not specified' */
+/* test: morep_valid.exe -t lo://00:00:00:00:00:00/0808 -v 4 script-lo.eth */
+/* test: morep_valid.exe -t lo://00:00:00:00:00:00/0808 -r lo://00:00:00:00:00:00/0808 script-lo.eth */
 
 /* vim: set ts=4 sw=4 si et: */