From 06bcc5b5773b744994abda1424369df24e332e2c Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Mon, 23 Dec 2024 21:58:47 -0500 Subject: do not dump past end of -d argument --- uxd.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'uxd.c') diff --git a/uxd.c b/uxd.c index 35dd2aa..9094047 100644 --- a/uxd.c +++ b/uxd.c @@ -635,8 +635,12 @@ int get_next_byte(void) { if(dump_data_arg) { /* have to cast this to unsigned char and back to int, to emulate fgetc() */ - c = (unsigned char)dump_data_arg[dump_data_idx++]; - if(!c) c = EOF; + c = (unsigned char)dump_data_arg[dump_data_idx]; + if(c) { + dump_data_idx++; + } else { + c = EOF; + } } else { c = fgetc(input); } @@ -863,6 +867,7 @@ void seek_input(void) { } } +/* -i */ void print_info(void) { printf("\nBytes: %ld\n", byte_count); printf("Valid characters: %ld\n", char_count); @@ -890,6 +895,7 @@ void dump_file(void) { fclose(input); } +/* -d */ void dump_data(void) { int datalen; @@ -927,7 +933,7 @@ int main(int argc, char **argv) { if(print_info_opt) /* -i */ print_info(); - if(restore_term) /* -T */ + if(restore_term) /* -t */ fputs(ESC_UTF8_OFF, stdout); return 0; -- cgit v1.2.3