about summary refs log tree commit diff stats
path: root/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp')
-rw-r--r--cpp/termbox/makefile2
-rw-r--r--cpp/termbox/output.inl20
-rw-r--r--cpp/termbox/termbox.c1
3 files changed, 14 insertions, 9 deletions
diff --git a/cpp/termbox/makefile b/cpp/termbox/makefile
index 58d76b21..21055318 100644
--- a/cpp/termbox/makefile
+++ b/cpp/termbox/makefile
@@ -3,5 +3,7 @@ CFLAGS=-O3 -Wall -Wextra -D_XOPEN_SOURCE
 libtermbox.a: utf8.o termbox.o
 	ar rcs libtermbox.a *.o
 
+termbox.o: termbox.c input.inl output.inl bytebuffer.inl
+
 clean:
 	rm *.o libtermbox.a
diff --git a/cpp/termbox/output.inl b/cpp/termbox/output.inl
index 45be181b..fd5d636f 100644
--- a/cpp/termbox/output.inl
+++ b/cpp/termbox/output.inl
@@ -162,16 +162,17 @@ static char *read_file(const char *file) {
 
 static char *terminfo_try_path(const char *path, const char *term) {
   char tmp[4096];
-  snprintf(tmp, sizeof(tmp), "%s/%c/%s", path, term[0], term);
-  tmp[sizeof(tmp)-1] = '\0';
+  // snprintf guarantee for older compilers
+  assert(sizeof(tmp) > sizeof(path)+sizeof("/x/")+sizeof(term)+1;
+  sprintf(tmp, "%s/%c/%s", path, term[0], term);
   char *data = read_file(tmp);
   if (data) {
     return data;
   }
 
   // fallback to darwin specific dirs structure
-  snprintf(tmp, sizeof(tmp), "%s/%x/%s", path, term[0], term);
-  tmp[sizeof(tmp)-1] = '\0';
+  // snprintf guarantee above still applies
+  sprintf(tmp, "%s/%x/%s", path, term[0], term);
   return read_file(tmp);
 }
 
@@ -191,8 +192,10 @@ static char *load_terminfo(void) {
   // next, consider ~/.terminfo
   const char *home = getenv("HOME");
   if (home) {
-    snprintf(tmp, sizeof(tmp), "%s/.terminfo", home);
-    tmp[sizeof(tmp)-1] = '\0';
+    // snprintf guarantee for older compilers
+    assert(sizeof(tmp) > sizeof(home)+sizeof("/.terminfo")+1);
+    strncpy(tmp, home, sizeof(home));
+    strcat(tmp, "/.terminfo");
     char *data = terminfo_try_path(tmp, term);
     if (data)
       return data;
@@ -201,8 +204,9 @@ static char *load_terminfo(void) {
   // next, TERMINFO_DIRS
   const char *dirs = getenv("TERMINFO_DIRS");
   if (dirs) {
-    snprintf(tmp, sizeof(tmp), "%s", dirs);
-    tmp[sizeof(tmp)-1] = '\0';
+    // snprintf guarantee for older compilers
+    assert(sizeof(tmp) > sizeof(dirs));
+    strncpy(tmp, dirs, sizeof(tmp));
     char *dir = strtok(tmp, ":");
     while (dir) {
       const char *cdir = dir;
diff --git a/cpp/termbox/termbox.c b/cpp/termbox/termbox.c
index 6d1b7b7d..13ef1359 100644
--- a/cpp/termbox/termbox.c
+++ b/cpp/termbox/termbox.c
@@ -5,7 +5,6 @@
 #include <fcntl.h>
 #include <signal.h>
 #include <stdio.h>
-int snprintf(char *str, size_t size, const char *format, ...);  // until we enable gnu99
 #include <stdbool.h>
 #include <sys/ioctl.h>
 #include <sys/time.h>