diff options
-rw-r--r-- | Makefile | 5 | ||||
-rw-r--r-- | src/memview.c | 12 |
2 files changed, 11 insertions, 6 deletions
@@ -6,8 +6,9 @@ MAKEFLAGS += --no-builtin-rules WARNINGS := -Wall -Wextra -Wpedantic -Wformat=2 -Wstrict-aliasing=3 -Wstrict-overflow=5 -Wstack-usage=12500 \ -Wfloat-equal -Wcast-align -Wpointer-arith -Wchar-subscripts -Warray-bounds=2 -override CFLAGS ?= -g -override CFLAGS += -std=c99 $(WARNINGS) +override CFLAGS ?= -g -O2 $(WARNINGS) +override CFLAGS += -std=c99 +override CPPFLAGS ?= -D_FORTIFY_SOURCE=2 override CPPFLAGS += -Isrc bins = ptrace-region-rw ptrace-address-rw uio-region-rw uio-address-rw memview binsearch bintrim diff --git a/src/memview.c b/src/memview.c index 8c2a792..75f939e 100644 --- a/src/memview.c +++ b/src/memview.c @@ -65,7 +65,8 @@ get_key(struct key *key) { while (1) { unsigned char input; - fread(&input, 1, 1, TERM_STREAM); + if (fread(&input, 1, 1, TERM_STREAM) <= 0) + continue; switch (input) { case 0x04: @@ -76,7 +77,8 @@ get_key(struct key *key) break; case 0x1b: // ^[ *key = (struct key){0}; - fread(&input, 1, 1, TERM_STREAM); + if (fread(&input, 1, 1, TERM_STREAM) <= 0) + continue; if (input != '[') { key->i = 0; break; @@ -656,7 +658,7 @@ error(const char *fmt, ...) screen_nprint(ctx.term.ws.w + sizeof(FMT(FG RED) FMT(PLAIN)), FMT(FG RED) "error: " FMT(PLAIN)); va_list ap; va_start(ap, fmt); screen_vnprintf(ctx.term.ws.w - sizeof("error:"), fmt, ap); va_end(ap); screen_flush(); - for (char input = 0; input == 0;) fread(&input, 1, 1, TERM_STREAM); + for (char input = 0; input == 0;) (void)! fread(&input, 1, 1, TERM_STREAM); } static void @@ -856,7 +858,9 @@ quit(void) static void init(void) { - freopen("/dev/null", "wb", stderr); + if (!freopen("/dev/null", "wb", stderr)) + err(EXIT_FAILURE, "freopen"); + setvbuf(stderr, ctx.term.err, _IOFBF, sizeof(ctx.term.err)); setvbuf(TERM_STREAM, NULL, _IONBF, 0); tcgetattr(TERM_FILENO, &ctx.term.initial); |