]> Sergey Matveev's repositories - nnn.git/commitdiff
Fix warnings. Harden compilation.
authorArun Prakash Jana <engineerarun@gmail.com>
Mon, 3 Apr 2017 20:10:04 +0000 (01:40 +0530)
committerArun Prakash Jana <engineerarun@gmail.com>
Tue, 4 Apr 2017 01:50:38 +0000 (07:20 +0530)
.travis.yml
Makefile
nnn.c

index 1ff932a2a902b948f6ef55b71fbf0851e3c92bd7..4fa9e5417c41a0adb82cdc93f851700b32e1bf88 100644 (file)
@@ -13,5 +13,5 @@ matrix:
     - os: osx
       compiler: clang
 script:
-  - make CFLAGS='-Werror'
-  - make CFLAGS='-Wall -Wextra -Werror'
+  - make clean
+  - make
index af8b10b2be3d8009ad5714ebd1e098fd387cd67c..c527d511f73a29e6fb5004b1b5ccb5cb87610edc 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@ VERSION = 0.6
 PREFIX = /usr/local
 MANPREFIX = $(PREFIX)/man
 
-CFLAGS += -O3 -march=native
+CFLAGS += -O3 -march=native -Wall -Wextra -Werror
 LDLIBS = -lcurses
 
 DISTFILES = nnn.c config.def.h nnn.1 Makefile README.md LICENSE
diff --git a/nnn.c b/nnn.c
index a04e24a734de856793d0e62d72423c8262759338..00116b74511915e8faa99b72409ebf9b641216fb 100644 (file)
--- a/nnn.c
+++ b/nnn.c
 #include <grp.h>
 
 #ifdef DEBUG
+static int
+xprintf(int fd, const char *fmt, ...)
+{
+       char buf[BUFSIZ];
+       int r;
+       va_list ap;
+
+       va_start(ap, fmt);
+       r = vsnprintf(buf, sizeof(buf), fmt, ap);
+       if (r > 0)
+               r = write(fd, buf, r);
+       va_end(ap);
+       return r;
+}
+
 #define DEBUG_FD 8
 #define DPRINTF_D(x) xprintf(DEBUG_FD, #x "=%d\n", x)
 #define DPRINTF_U(x) xprintf(DEBUG_FD, #x "=%u\n", x)
@@ -90,6 +105,8 @@ typedef struct entry {
        off_t size;
 } *pEntry;
 
+typedef unsigned long ulong;
+
 /* Global context */
 static struct entry *dents;
 static int ndents, cur;
@@ -120,21 +137,6 @@ static void printmsg(char *);
 static void printwarn(void);
 static void printerr(int, char *);
 
-static int
-xprintf(int fd, const char *fmt, ...)
-{
-       char buf[BUFSIZ];
-       int r;
-       va_list ap;
-
-       va_start(ap, fmt);
-       r = vsnprintf(buf, sizeof(buf), fmt, ap);
-       if (r > 0)
-               r = write(fd, buf, r);
-       va_end(ap);
-       return r;
-}
-
 static void *
 xrealloc(void *p, size_t size)
 {
@@ -729,7 +731,6 @@ show_stats(char* fpath, char* fname, struct stat *sb)
 {
        char buf[PATH_MAX + 48];
        char *perms = get_lsperms(sb->st_mode, buf);
-       FILE *pf;
        char *p, *begin = buf;
 
        clear();
@@ -750,7 +751,7 @@ show_stats(char* fpath, char* fname, struct stat *sb)
               sb->st_size, sb->st_blocks, sb->st_blksize, buf);
 
        /* Show containing device, inode, hardlink count */
-       sprintf(buf, "%lxh/%lud", sb->st_dev, sb->st_dev);
+       sprintf(buf, "%lxh/%lud", (ulong)sb->st_dev, (ulong)sb->st_dev);
        printw("\n  Device: %-15s Inode: %-11lu Links: %-9lu",
               buf, sb->st_ino, sb->st_nlink);
 
@@ -826,7 +827,7 @@ show_stats(char* fpath, char* fname, struct stat *sb)
        /* Show exit keys */
        printw("\n\n  << (q/Esc)");
 
-       while (*buf = getch())
+       for (*buf = getch(); *buf != 'q' && *buf != 27; *buf = getch())
                if (*buf == 'q' || *buf == 27)
                        return;
 }
@@ -868,7 +869,7 @@ show_help(void)
        /* Show exit keys */
        printw("\n\n    << (q/Esc)");
 
-       while (c = getch())
+       for (c = getch(); c != 'q' && c != 27; c = getch())
                if (c == 'q' || c == 27)
                        return;
 }
@@ -927,6 +928,7 @@ dentfind(struct entry *dents, int n, char *path)
        if (!path)
                return 0;
 
+       int i;
        char *p = xmemrchr(path, '/', strlen(path));
        if (!p)
                p = path;
@@ -937,7 +939,7 @@ dentfind(struct entry *dents, int n, char *path)
 
        DPRINTF_S(p);
 
-       for (int i = 0; i < n; i++)
+       for (i = 0; i < n; i++)
                if (strcmp(p, dents[i].name) == 0)
                        return i;
 
@@ -1175,6 +1177,7 @@ nochange:
                                                status = system(cmd);
                                                continue;
                                        } else {
+                                               status++; /* Dummy operation */
                                                printmsg("No association");
                                                goto nochange;
                                        }