FreeCalypso > hg > freecalypso-hwlab
changeset 151:d515cfbb3f39
fc-simtool: hex string parsing: add minimum length parameter
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 07 Feb 2021 00:18:30 +0000 |
parents | 54e33e9238b6 |
children | 250d172662ca |
files | simtool/hexstr.c simtool/writecmd.c |
diffstat | 2 files changed, 6 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/simtool/hexstr.c Sun Feb 07 00:06:50 2021 +0000 +++ b/simtool/hexstr.c Sun Feb 07 00:18:30 2021 +0000 @@ -20,10 +20,10 @@ return(-1); } -decode_hex_data_from_string(arg, databuf, maxlen) +decode_hex_data_from_string(arg, databuf, minlen, maxlen) char *arg; u_char *databuf; - unsigned maxlen; + unsigned minlen, maxlen; { unsigned count; @@ -37,15 +37,15 @@ return(-1); } if (count >= maxlen) { - fprintf(stderr, "error: hex input data is too long\n"); + fprintf(stderr, "error: hex string is too long\n"); return(-1); } databuf[count] = (decode_hex_digit(arg[0]) << 4) | decode_hex_digit(arg[1]); arg += 2; } - if (!count) { - fprintf(stderr, "error: empty hex string argument\n"); + if (count < minlen) { + fprintf(stderr, "error: hex string is too short\n"); return(-1); } return(count);
--- a/simtool/writecmd.c Sun Feb 07 00:06:50 2021 +0000 +++ b/simtool/writecmd.c Sun Feb 07 00:18:30 2021 +0000 @@ -36,7 +36,7 @@ fprintf(stderr, "error: offset argument is out of range\n"); return(-1); } - rc = decode_hex_data_from_string(argv[2], data, 255); + rc = decode_hex_data_from_string(argv[2], data, 1, 255); if (rc < 0) return(rc); len = rc;