commit 9005e5c975d57701622880ac9ff93fecf92f2e6b
parent 679507900ae8bbf716757186c90a4b205302758d
Author: William Casarin <jb55@jb55.com>
Date: Wed, 19 Jun 2019 00:09:57 -0700
make reading input break on the first non-hex char
Diffstat:
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/util.c b/util.c
@@ -109,12 +109,13 @@ ssize_t getline(char **lineptr, size_t *n, FILE *stream) {
int read_arg_or_stdin(const char *arg, unsigned char *buf, size_t buflen,
size_t *written)
{
+ unsigned char dummy;
if (arg != NULL) {
unsigned char *p = buf;
bool done = false;
for (size_t i = 0; i < buflen; i++) {
*p = arg[i];
- if (arg[i] == 0) {
+ if (*p == 0 || !char_to_hex(&dummy, *p)) {
done = true;
break;
}