From 2fe25642908600bd190b2325bbca91bb8a72bc1e Mon Sep 17 00:00:00 2001 From: Laurent Mazet Date: Fri, 28 Mar 2025 23:01:14 +0100 Subject: [PATCH] add tests and fix memory leaks --- morep_valid.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/morep_valid.c b/morep_valid.c index 83c7121..f40d094 100644 --- a/morep_valid.c +++ b/morep_valid.c @@ -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: */ -- 2.30.2