summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJari Vetoniemi <mailroxas@gmail.com>2019-02-24 15:09:37 +0200
committerJari Vetoniemi <mailroxas@gmail.com>2019-02-24 15:09:37 +0200
commitbfaa5b5c087d3e3e36991583f326cbef88407ebb (patch)
treece195d0ffc7bd11ae4187e74f7e553736a063352
parent11d0d93576cd834b5126529daa736d4b4b62330e (diff)
Makefile: Change default CPP/CFLAGS
-D_FORTIFY_SOURCE=2 and -O2 enables some useful diagnosis. Move WARNINGS into CFLAGS ?= assignment, as they are compiler specific. The default compilation flags assumes gcc, but can easily be changed by overriding CFLAGS and CPPFLAGS.
-rw-r--r--Makefile5
-rw-r--r--src/memview.c12
2 files changed, 11 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index e80632d..bfcca00 100644
--- a/Makefile
+++ b/Makefile
@@ -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);