]> git.mdlowis.com Git - projs/tide.git/commitdiff
fixed infinite loop and some lint issues
authorMichael D. Lowis <mike@mdlowis.com>
Thu, 10 Oct 2019 04:03:46 +0000 (00:03 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Thu, 10 Oct 2019 04:03:46 +0000 (00:03 -0400)
alcc
bin/topen [deleted file]
src/lib/buf.c
src/lib/dbc.c

diff --git a/alcc b/alcc
index 43abce7d5bffe68822f6b26df8db0e0e8b4f2286..8029d833bb7f5a8d47274c2548b59d9475b57aa7 100755 (executable)
--- a/alcc
+++ b/alcc
@@ -216,6 +216,7 @@ script=$(cat <<EOS
         paren = match(\$0, /\(/)
         semi = match(\$0, /;\s*$/)
         gsub(/"(\\\\"|[^"])*"/, "")      # ignore string literals
+        gsub(/'(\\\\'|[^'])'/, "")      # ignore char literals
         sub(/\/\/.*$/, "")             # ignore line comments
         gsub(/\/\*.*\*\//, "")         # ignore block comments on single line
         incomment = sub(/\/\*.*$/, "") # ignore block comment starts
diff --git a/bin/topen b/bin/topen
deleted file mode 100755 (executable)
index f7f82a1..0000000
--- a/bin/topen
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/sh
-file="$1"
-[ -f "$1" ] && tide "$1"
\ No newline at end of file
index 292919f8cc9cb0a9a679572b49d94969b4a6112e..193eb3db6aeb8447e707ba0e0f223e02012f1e5d 100644 (file)
@@ -41,11 +41,6 @@ static Sel selget(Buf* buf)
     return (sel.end < sel.beg ? selswap(sel) : sel);
 }
 
-//static void selset(Buf* buf, Sel sel)
-//{
-//    buf->selection = (sel.end < sel.beg ? selswap(sel) : sel);
-//}
-
 /* Creation, Resizing, Loading, and Saving
  ******************************************************************************/
 static size_t pagealign(size_t sz)
@@ -471,11 +466,13 @@ static void log_swap(Buf* buf, Log** src, Log** dest)
 
 void buf_logstart(Buf* buf)
 {
+    require(buf != NULL);
     buf->transid = abs(buf->transid);
 }
 
 void buf_logstop(Buf* buf)
 {
+    require(buf != NULL);
     if (buf->transid > 0)
     {
         buf->transid = -(buf->transid + 1);
@@ -484,24 +481,28 @@ void buf_logstop(Buf* buf)
 
 void buf_undo(Buf* buf)
 {
+    require(buf != NULL);
     log_swap(buf, &(buf->undo), &(buf->redo));
     ensure(buf_valid(buf));
 }
 
 void buf_redo(Buf* buf)
 {
+    require(buf != NULL);
     log_swap(buf, &(buf->redo), &(buf->undo));
     ensure(buf_valid(buf));
 }
 
 void buf_logclear(Buf* buf)
 {
+    require(buf != NULL);
     log_clear(&(buf->redo));
     log_clear(&(buf->undo));
 }
 
 void buf_lastins(Buf* buf)
 {
+    require(buf != NULL);
     Log* log = buf->undo;
     if (log)
     {
@@ -543,6 +544,7 @@ void buf_lastins(Buf* buf)
  ******************************************************************************/
 size_t buf_end(Buf* buf)
 {
+    require(buf != NULL);
     size_t bufsz = buf->bufend - buf->bufstart;
     size_t gapsz = buf->gapend - buf->gapstart;
     return (bufsz - gapsz);
@@ -550,6 +552,7 @@ size_t buf_end(Buf* buf)
 
 int buf_getrat(Buf* buf, size_t off)
 {
+    require(buf != NULL);
     size_t rlen = 0;
     Rune rune = 0;
     if (getb(buf, off) == '\r' && getb(buf, off+1) == '\n')
@@ -567,6 +570,7 @@ int buf_getrat(Buf* buf, size_t off)
 
 void buf_putc(Buf* buf, int c)
 {
+    require(buf != NULL);
     char utf8buf[UTF_MAX+1] = {0};
     (void)utf8encode(utf8buf, c);
     buf_puts(buf, utf8buf);
@@ -575,6 +579,7 @@ void buf_putc(Buf* buf, int c)
 
 void buf_puts(Buf* buf, char* s)
 {
+    require(buf != NULL);
     buf_del(buf);
     size_t beg = buf_selbeg(buf);
     if (s && *s)
@@ -590,11 +595,13 @@ void buf_puts(Buf* buf, char* s)
 
 int buf_getc(Buf* buf)
 {
+    require(buf != NULL);
     return buf_getrat(buf, buf->selection.end);
 }
 
 char* buf_gets(Buf* buf)
 {
+    require(buf != NULL);
     Sel sel = selget(buf);
     size_t nbytes = sel.end - sel.beg;
     char* str = malloc(nbytes+1);
@@ -608,6 +615,7 @@ char* buf_gets(Buf* buf)
 
 char* buf_getsat(Buf* buf, size_t beg, size_t end)
 {
+    require(buf != NULL);
     Sel sel = selget(buf);
     buf->selection = (Sel){ .beg = beg, .end = end };
     char* str = buf_gets(buf);
@@ -617,6 +625,7 @@ char* buf_getsat(Buf* buf, size_t beg, size_t end)
 
 void buf_del(Buf* buf)
 {
+    require(buf != NULL);
     Sel sel = selget(buf);
     size_t nbytes = sel.end - sel.beg;
     if (nbytes > 0)
@@ -736,18 +745,21 @@ static int bytes_match(Buf* buf, size_t mbeg, size_t mend, char* str)
 
 bool buf_isbol(Buf* buf, size_t off)
 {
+    require(buf != NULL);
     size_t bol = buf_bol(buf, off);
     return (bol == off);
 }
 
 bool buf_iseol(Buf* buf, size_t off)
 {
+    require(buf != NULL);
     Rune r = buf_getrat(buf, off);
     return (r == '\r' || r == '\n');
 }
 
 size_t buf_bol(Buf* buf, size_t off)
 {
+    require(buf != NULL);
     for (; !buf_iseol(buf, off-1); off--)
     {
     }
@@ -756,6 +768,7 @@ size_t buf_bol(Buf* buf, size_t off)
 
 size_t buf_eol(Buf* buf, size_t off)
 {
+    require(buf != NULL);
     for (; !buf_iseol(buf, off); off++)
     {
     }
@@ -764,6 +777,7 @@ size_t buf_eol(Buf* buf, size_t off)
 
 void buf_selword(Buf* buf, bool (*isword)(Rune))
 {
+    require(buf != NULL);
     Sel sel = selget(buf);
     for (; isword(buf_getrat(buf, sel.beg-1)); sel.beg--)
     {
@@ -776,6 +790,7 @@ void buf_selword(Buf* buf, bool (*isword)(Rune))
 
 void buf_selall(Buf* buf)
 {
+    require(buf != NULL);
     buf->selection = (Sel){ .beg = 0, .end = buf_end(buf) };
 }
 
@@ -819,6 +834,7 @@ static bool selquote(Buf* buf, Rune c)
 
 void buf_selctx(Buf* buf, bool (*isword)(Rune))
 {
+    require(buf != NULL);
     size_t bol = buf_bol(buf, buf->selection.end);
     Rune curr = buf_getc(buf);
     if (curr == '(' || curr == ')')
@@ -841,6 +857,7 @@ void buf_selctx(Buf* buf, bool (*isword)(Rune))
     {
         selline(buf);
     }
+
     else if (selquote(buf, '"') || selquote(buf, '`') || selquote(buf, '\''))
     {
         ; /* condition performs selection */
@@ -858,6 +875,7 @@ void buf_selctx(Buf* buf, bool (*isword)(Rune))
 
 size_t buf_byrune(Buf* buf, size_t pos, int count)
 {
+    require(buf != NULL);
     int move = (count < 0 ? -1 : 1);
     count *= move; // remove the sign if there is one
     for (; count > 0; count--)
@@ -890,6 +908,7 @@ size_t buf_byrune(Buf* buf, size_t pos, int count)
 
 size_t buf_byword(Buf* buf, size_t off, int count)
 {
+    require(buf != NULL);
     int move = (count < 0 ? -1 : 1);
 
     while (nextrune(buf, off, move, risblank))
@@ -919,6 +938,7 @@ size_t buf_byword(Buf* buf, size_t off, int count)
 
 size_t buf_byline(Buf* buf, size_t pos, int count)
 {
+    require(buf != NULL);
     int move = (count < 0 ? -1 : 1);
     count *= move; // remove the sign if there is one
     for (; count > 0; count--)
@@ -944,12 +964,14 @@ size_t buf_byline(Buf* buf, size_t pos, int count)
 
 bool buf_findstr(Buf* buf, int dir, char* str)
 {
+    require(buf != NULL);
     bool found = false;
     size_t len = strlen(str);
-    size_t start = buf->selection.beg,
-           mbeg = (start + dir),
-           mend = (mbeg + len);
-    while (mbeg != start)
+    size_t start = buf->selection.beg;
+    size_t mbeg = (start + dir);
+    size_t mend = (mbeg + len);
+    size_t nleft = buf_end(buf);
+    for (; (mbeg != start) && nleft; nleft--)
     {
         if ((getb(buf, mbeg) == str[0]) &&
             (getb(buf, mend-1) == str[len-1]) &&
@@ -970,6 +992,7 @@ bool buf_findstr(Buf* buf, int dir, char* str)
 
 void buf_setln(Buf* buf, size_t line)
 {
+    require(buf != NULL);
     size_t curr = 0, end = buf_end(buf);
     while (line > 1 && curr < end)
     {
@@ -986,6 +1009,7 @@ void buf_setln(Buf* buf, size_t line)
 
 void buf_getln(Buf* buf, size_t* begln, size_t* endln)
 {
+    require(buf != NULL);
     size_t line = 1, curr = 0, end = buf_end(buf);
     size_t sbeg = buf_selbeg(buf), send = buf_selend(buf);
     while (curr < end)
@@ -1014,6 +1038,7 @@ void buf_getln(Buf* buf, size_t* begln, size_t* endln)
 
 void buf_getcol(Buf* buf)
 {
+    require(buf != NULL);
     Sel sel = buf->selection;
     size_t pos = sel.end, curr = buf_bol(buf, pos);
     for (sel.col = 0; curr < pos; curr = buf_byrune(buf, curr, 1))
@@ -1025,6 +1050,7 @@ void buf_getcol(Buf* buf)
 
 void buf_setcol(Buf* buf)
 {
+    require(buf != NULL);
     Sel sel = buf->selection;
     size_t bol = buf_bol(buf, sel.end);
     size_t curr = bol, len = 0, i = 0;
@@ -1051,21 +1077,25 @@ void buf_setcol(Buf* buf)
 
 size_t buf_selbeg(Buf* buf)
 {
+    require(buf != NULL);
     return selget(buf).beg;
 }
 
 size_t buf_selend(Buf* buf)
 {
+    require(buf != NULL);
     return selget(buf).end;
 }
 
 size_t buf_selsz(Buf* buf)
 {
+    require(buf != NULL);
     return (selget(buf).end - selget(buf).beg);
 }
 
 void buf_selln(Buf* buf)
 {
+    require(buf != NULL);
     /* Expand the selection to completely select the lines covered */
     Sel sel = selget(buf);
     sel.beg = buf_bol(buf, sel.beg);
index b6e08103c3ef8c153e6c733b215e2faddc156fdd..e6c45644520653748b357e28cb2d1c477b79dbae 100644 (file)
@@ -8,31 +8,46 @@ static char ErrMsg[8192];
 static char* DumpPath = NULL;
 static void (*DumpFn)(FILE*) = NULL;
 
-static void dump_and_abort(char* msg) {
+static void dump_and_abort(char* msg)
+{
     FILE* f = (DumpPath ? fopen(DumpPath, "w") : stderr);
     fprintf(f, "%s\n\n", msg);
     if (DumpFn) DumpFn(f);
+    fprintf(f, "\n%s\n", msg);
     fclose(f);
     _Exit(1);
 }
 
-static void handle_signal(int sig) {
-    if (SIGABRT == sig) {
+static void handle_signal(int sig)
+{
+    if (SIGABRT == sig)
+    {
         dump_and_abort("SIGABRT - Process abort signal");
-    } else if (SIGBUS == sig) {
+    }
+    else if (SIGBUS == sig)
+    {
         dump_and_abort("SIGBUS - Access to an undefined portion of a memory object");
-    } else if (SIGFPE == sig) {
+    }
+    else if (SIGFPE == sig)
+    {
         dump_and_abort("SIGFPE - Erroneous arithmetic operation");
-    } else if (SIGILL == sig) {
+    }
+    else if (SIGILL == sig)
+    {
         dump_and_abort("SIGILL - Illegal instruction");
-    } else if (SIGSEGV == sig) {
+    }
+    else if (SIGSEGV == sig)
+    {
         dump_and_abort("SIGSEGV - Invalid memory reference");
-    } else if (SIGALRM == sig) {
+    }
+    else if (SIGALRM == sig)
+    {
         dump_and_abort("SIGALRM - Watchdog timer expired");
     }
 }
 
-void dbc_init(char* path, void (*dumpfn)(FILE*)) {
+void dbc_init(char* path, void (*dumpfn)(FILE*))
+{
     DumpPath = path;
     DumpFn = dumpfn;
     signal(SIGABRT,  handle_signal);
@@ -42,21 +57,26 @@ void dbc_init(char* path, void (*dumpfn)(FILE*)) {
     signal(SIGSEGV, handle_signal);
 }
 
-void dbc_require(bool success, char* text, char* file, int line) {
-    if (!success) {
+void dbc_require(bool success, char* text, char* file, int line)
+{
+    if (!success)
+    {
         snprintf(ErrMsg, sizeof(ErrMsg), "%s:%d: pre-condition failed (%s)", file, line, text);
         dump_and_abort(ErrMsg);
     }
 }
 
-void dbc_ensure(bool success, char* text, char* file, int line) {
-    if (!success) {
+void dbc_ensure(bool success, char* text, char* file, int line)
+{
+    if (!success)
+    {
         snprintf(ErrMsg, sizeof(ErrMsg), "%s:%d: post-condition failed (%s)", file, line, text);
         dump_and_abort(ErrMsg);
     }
 }
 
-void dbc_wdtkick(void) {
+void dbc_wdtkick(void)
+{
     alarm(0); /* Cancel previous alarm */
     signal(SIGALRM, handle_signal);
     alarm(1); /* Start new alarm */