]> git.mdlowis.com Git - projs/tide.git/commitdiff
fixed all errors found by clang and fixed some compiler warnings as well as a use...
authorMichael D. Lowis <mike@mdlowis.com>
Sat, 15 Jul 2017 14:44:35 +0000 (10:44 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Sat, 15 Jul 2017 14:44:35 +0000 (10:44 -0400)
config.mk
inc/stdc.h
inc/utf.h
lib/buf.c
lib/exec.c
lib/utf8.c
lib/utils.c
lib/view.c
lib/win.c
pick.c
tide.c

index 844622148a16a7ccfb87f1d48ee50e56bb84b60b..f391e19870612a94e32abc399d4374cd132c80c0 100644 (file)
--- a/config.mk
+++ b/config.mk
@@ -33,7 +33,7 @@ GCOV   = 0
 
 # Treat all warnings as errors (poor man's lint?)
 ifeq ($(WERROR), 1)
-       CFLAGS += -Wall -Wextra -Werror
+       CFLAGS += -Wall -Wextra -Wno-unused-parameter
 endif
 
 # GCC Debugging
index cbbcd57d8f4060693b76d95f3a38cafc04f3e237..57d65962817a9754cee6c534bb2fd664163d7081 100644 (file)
@@ -44,7 +44,7 @@ typedef intptr_t  intptr;
 
 /* Generic Death Function
  *****************************************************************************/
-void die(const char* msgfmt, ...);
+void die(const char* msgfmt, ...) __attribute__((__noreturn__));
 
 /* Option Parsing
  *
index 0aa87f98abb30c18df18cf75141c6be79262e3bf..b0573633c7a4495690ecaa574fecc3245b1f8323 100644 (file)
--- a/inc/utf.h
+++ b/inc/utf.h
@@ -8,7 +8,7 @@ enum {
 };
 
 /* Represents a unicode code point */
-typedef uint32_t Rune;
+typedef int32_t Rune;
 
 size_t utf8encode(char str[UTF_MAX], Rune rune);
 bool utf8decode(Rune* rune, size_t* length, int byte);
index 5c8bfb31e61e3d8061ecf5ad564d9869297ac4d0..fc81b52b651596163d5e89f19b2f58f14bc450ec 100644 (file)
--- a/lib/buf.c
+++ b/lib/buf.c
@@ -13,10 +13,8 @@ static void log_clear(Log** list);
 static void log_insert(Buf* buf, Log** list, size_t beg, size_t end);
 static void log_delete(Buf* buf, Log** list, size_t off, Rune* r, size_t len);
 static void syncgap(Buf* buf, size_t off);
-static void buf_resize(Buf* buf, size_t sz);
 static void delete(Buf* buf, size_t off);
 static size_t insert(Buf* buf, size_t off, Rune rune);
-static int range_match(Buf* buf, size_t dbeg, size_t dend, size_t mbeg, size_t mend);
 static int rune_match(Buf* buf, size_t mbeg, size_t mend, Rune* runes);
 static void swaplog(Buf* buf, Log** from, Log** to, Sel* sel);
 static size_t next_size(size_t curr);
@@ -173,7 +171,6 @@ size_t buf_delete(Buf* buf, size_t beg, size_t end) {
     log_clear(&(buf->redo));
     for (size_t i = end-beg; i > 0; i--) {
         Rune r = buf_get(buf, beg);
-        bool is_eol = (r == '\n' || r == RUNE_CRLF);
         log_delete(buf, &(buf->undo), beg, &r, 1);
         delete(buf, beg);
     }
@@ -279,7 +276,7 @@ void buf_getword(Buf* buf, bool (*isword)(Rune), Sel* sel) {
 
 void buf_getblock(Buf* buf, Rune first, Rune last, Sel* sel) {
     int balance = 0, dir;
-    size_t beg = sel->end, end = sel->end, off;
+    size_t beg, end = sel->end;
 
     /* figure out which end of the block we're starting at */
     if (buf_get(buf, end) == first)
@@ -538,7 +535,7 @@ static void buf_resize(Buf* buf, size_t sz) {
         *(copy.gapstart++) = *(curr);
     /* free the buffer and commit the changes */
     free(buf->bufstart);
-    *buf = copy;
+    memcpy(buf, &copy, sizeof(Buf));
 }
 
 static void delete(Buf* buf, size_t off) {
@@ -566,16 +563,6 @@ static size_t insert(Buf* buf, size_t off, Rune rune) {
     return rcount;
 }
 
-static int range_match(Buf* buf, size_t dbeg, size_t dend, size_t mbeg, size_t mend) {
-    size_t n1 = dend-dbeg, n2 = mend-mbeg;
-    if (n1 != n2) return n1-n2;
-    for (; n1 > 0; n1--, dbeg++, mbeg++) {
-        int cmp = buf_get(buf, dbeg) - buf_get(buf, mbeg);
-        if (cmp != 0) return cmp;
-    }
-    return 0;
-}
-
 static int rune_match(Buf* buf, size_t mbeg, size_t mend, Rune* runes) {
     for (; *runes; runes++, mbeg++) {
         int cmp = *runes - buf_get(buf, mbeg);
index c264ea4db5515b4abd13008d03ffc642708627ff..0c4d5bc3780bd50024ba1d7b9dffcec16b16cb51 100644 (file)
@@ -156,7 +156,7 @@ static void send_data(int fd, void* data) {
             job->nwrite += nwrite;
         }
         if  (nwrite < 0 || job->ndata <= 0)
-            job_closefd(job, fd);
+            close(fd);
     } else {
         job_closefd(job, fd);
     }
@@ -190,7 +190,6 @@ static void recv_data(int fd, void* data) {
             }
         } else {
             close(fd);
-            job_closefd(job, -fd);
         }
     } else {
         job_closefd(job, fd);
index e4fddabaf1c4b2e0f3ccabb5f61909b131ab6459..184340ec53f73b5dc565fd1340e92ab880be52ba 100644 (file)
@@ -5,15 +5,15 @@
 #include <wchar.h>
 #include <ctype.h>
 
-const uint8_t UTF8_SeqBits[] = { 0x00u, 0x80u, 0xC0u, 0xE0u, 0xF0u, 0xF8u, 0xFCu, 0xFEu };
-const uint8_t UTF8_SeqMask[] = { 0x00u, 0xFFu, 0x1Fu, 0x0Fu, 0x07u, 0x03u, 0x01u, 0x00u };
-const uint8_t UTF8_SeqLens[] = { 0x01u, 0x00u, 0x02u, 0x03u, 0x04u, 0x05u, 0x06u, 0x00u };
+const uint8_t UTF8_SeqBits[] = { 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE };
+const uint8_t UTF8_SeqMask[] = { 0x00, 0xFF, 0x1F, 0x0F, 0x07, 0x03, 0x01, 0x00 };
+const uint8_t UTF8_SeqLens[] = { 0x01, 0x00, 0x02, 0x03, 0x04, 0x05, 0x06, 0x00 };
 
 static bool runevalid(Rune val) {
     return (val <= RUNE_MAX)
-        && ((val & 0xFFFEu) != 0xFFFEu)
-        && ((val < 0xD800u) || (val > 0xDFFFu))
-        && ((val < 0xFDD0u) || (val > 0xFDEFu));
+        && ((val & 0xFFFE) != 0xFFFE)
+        && ((val < 0xD800) || (val > 0xDFFF))
+        && ((val < 0xFDD0) || (val > 0xFDEF));
 }
 
 static size_t runelen(Rune rune) {
index 8608da73f44b74340db93eb8760efa842ca9be15..05e0b6372fe48e30bd947348c04357ecef8585a5 100644 (file)
@@ -123,7 +123,7 @@ char* getcurrdir(void) {
 char* dirname(char* path) {
     path = stringdup(path);
     char* end = strrchr(path, '/');
-    if (!end) return NULL;
+    if (!end) return (free(path), NULL);
     *end = '\0';
     return path;
 }
index 36a7b1b3021a7fc4fcad51e95ca3480943759835..90dbdbc66d79bc5c842294e419be5e33217901b1 100644 (file)
@@ -66,11 +66,10 @@ size_t view_limitrows(View* view, size_t maxrows, size_t ncols) {
 }
 
 void view_resize(View* view, size_t nrows, size_t ncols) {
-    size_t line = 1, off = 0;
+    size_t off = 0;
     if (view->nrows == nrows && view->ncols == ncols) return;
     /* free the old row data */
     if (view->nrows) {
-        line = view->rows[0]->line;
         off  = view->rows[0]->off;
         for (size_t i = 0; i < view->nrows; i++)
             free(view->rows[i]);
@@ -701,10 +700,8 @@ static void apply_colors(View* view) {
             if (!curr) { r = -1; break; } // Break both loops if we're done
 
             /* check if we're in the current region */
-            if (curr->beg <= off && off <= curr->end) {
-                uint32_t attr = row->cols[col].attr;
+            if (curr->beg <= off && off <= curr->end)
                 row->cols[col].attr = (row->cols[col].attr & 0xFF00) | curr->color;
-            }
             off++, col++;
             while (col < row->len && row->cols[col].rune == '\0')
                 col++;
index c579d91c81d19eeb9d312f2554aa44a04ee91d83..6f0c1633a0f5838070ad9d0471e21f0a37ce94f2 100644 (file)
--- a/lib/win.c
+++ b/lib/win.c
@@ -211,8 +211,6 @@ static void layout(int width, int height) {
 }
 
 static void onredraw(int width, int height) {
-    static uint64_t maxtime = 0;
-    uint64_t start = getmillis();
     size_t fheight = x11_font_height(Font);
     size_t fwidth  = x11_font_width(Font);
 
@@ -286,10 +284,6 @@ static void onredraw(int width, int height) {
         size_t y = Regions[Focused].y + (Regions[Focused].csry * fheight) + (fheight/2);
         x11_mouse_set(x, y);
     }
-
-    uint64_t stop = getmillis();
-    uint64_t elapsed = stop-start;
-    //printf("%llu\n", elapsed);
 }
 
 static void oninput(int mods, Rune key) {
@@ -326,7 +320,6 @@ static void oninput(int mods, Rune key) {
 
 static void scroll_actions(int btn, bool pressed, int x, int y) {
     size_t row = (y-Regions[SCROLL].y) / x11_font_height(Font);
-    size_t col = (x-Regions[SCROLL].x) / x11_font_width(Font);
     switch (btn) {
         case MouseLeft:
             if (pressed)
@@ -405,24 +398,23 @@ static bool update_focus(void) {
 
 static void draw_line_num(bool current, size_t x, size_t y, size_t gcols, size_t num) {
     int color = config_get_int(ClrGutterNor);
-    if (ShowLineNumbers) {
-        if (current) {
-            color = config_get_int(ClrGutterSel);;
-            size_t fheight = x11_font_height(Font);
-            x11_draw_rect((color >> 8), x-3, y-fheight, gutter_size(), fheight);
-        }
-        UGlyph glyphs[gcols];
-        for (int i = gcols-1; i >= 0; i--) {
-            glyphs[i].attr = color & 0xFF;
-            if (num > 0) {
-                glyphs[i].rune = ((num % 10) + '0');
-                num /= 10;
-            } else {
-                glyphs[i].rune = ' ';
-            }
+    if (!gcols) return;
+    if (current) {
+        color = config_get_int(ClrGutterSel);;
+        size_t fheight = x11_font_height(Font);
+        x11_draw_rect((color >> 8), x-3, y-fheight, gutter_size(), fheight);
+    }
+    UGlyph glyphs[gcols];
+    for (int i = gcols-1; i >= 0; i--) {
+        glyphs[i].attr = color & 0xFF;
+        if (num > 0) {
+            glyphs[i].rune = ((num % 10) + '0');
+            num /= 10;
+        } else {
+            glyphs[i].rune = ' ';
         }
-        draw_glyphs(x, y, glyphs, gcols, gcols);
     }
+    draw_glyphs(x, y, glyphs, gcols, gcols);
 }
 
 static void draw_glyphs(size_t x, size_t y, UGlyph* glyphs, size_t rlen, size_t ncols) {
diff --git a/pick.c b/pick.c
index 84d0087c0755f6a1aa7ff82f2924d31127ebbd63..6d1ada575a53f8120ecdbdc79424dbaf4d49aecd 100644 (file)
--- a/pick.c
+++ b/pick.c
@@ -61,6 +61,8 @@ static void load_choices(void) {
             choice.length = strlen(choice_text);
             choice.score  = 1.0;
             vec_push_back(&Choices, &choice);
+        } else {
+            free(choice_text);
         }
     }
     vec_sort(&Choices, by_score);
diff --git a/tide.c b/tide.c
index 0f84018cef4cb9f67b92a4932aac66e8defabf90..3712d23f3dcfef28eae64f049935df92ee2fe450 100644 (file)
--- a/tide.c
+++ b/tide.c
@@ -139,7 +139,7 @@ static void trim_whitespace(void) {
 static void quit(void) {
     static uint64_t before = 0;
     uint64_t now = getmillis();
-    if (!win_buf(EDIT)->modified || (now-before) <= config_get_int(DblClickTime)) {
+    if (!win_buf(EDIT)->modified || (now-before) <= (uint64_t)config_get_int(DblClickTime)) {
         #ifndef TEST
         x11_deinit();
         #else
@@ -180,7 +180,7 @@ void onmouseleft(WinRegion id, bool pressed, size_t row, size_t col) {
     static uint64_t before = 0;
     if (!pressed) return;
     uint64_t now = getmillis();
-    count = ((now-before) <= config_get_int(DblClickTime) ? count+1 : 1);
+    count = ((now-before) <= (uint64_t)config_get_int(DblClickTime) ? count+1 : 1);
     before = now;
 
     if (count == 1) {
@@ -591,7 +591,7 @@ int pty_spawn(char** argv) {
 
 void pty_update(int fd, void* data) {
     /* Read from command if we have one */
-    long n = 0, r = 0, i = 0;
+    long n = 0, i = 0;
     static char cmdbuf[8192];
     if ((n = read(CmdFD, cmdbuf, sizeof(cmdbuf))) < 0)
         CmdFD = -1;