FreeCalypso > hg > freecalypso-hwlab
diff simtool/hexstr.c @ 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 |
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);