shithub: mc

Download patch

ref: 060940410c47bea543fa9ef1518d533c63591597
parent: c8ba8d209ea2eb5963d143f3ea68509a7be72e9a
author: Ori Bernstein <[email protected]>
date: Tue Jul 10 11:37:48 EDT 2012

GCC, you're annoying at times.

    Fix some warnings.

--- a/8/isel.c
+++ b/8/isel.c
@@ -407,6 +407,7 @@
     eax = locphysreg(Reax);
     edx = locphysreg(Redx);
     cl = locphysreg(Rcl);
+    r = NULL;
     switch (exprop(n)) {
         case Oadd:      r = binop(s, Iadd, args[0], args[1]); break;
         case Osub:      r = binop(s, Isub, args[0], args[1]); break;
@@ -617,6 +618,7 @@
 
     p = insnfmts[insn->op];
     i = 0;
+    modeidx = 0;
     for (; *p; p++) {
         if (*p !=  '%') {
             fputc(*p, fd);
@@ -637,7 +639,6 @@
                 i++;
                 break;
             case 't':
-                modeidx = 0;
             default:
                 /* the  asm description uses 1-based indexing, so that 0
                  * can be used as a sentinel. */
--- a/8/main.c
+++ b/8/main.c
@@ -44,7 +44,8 @@
 
     swapsuffix(objfile, 1024, f, ".s", ".o");
     snprintf(cmd, 1024, Asmcmd, objfile, f);
-    system(cmd);
+    if (system(cmd) == -1)
+      die("Couldn't run assembler");
 }
 
 int main(int argc, char **argv)
--- a/parse/tok.c
+++ b/parse/tok.c
@@ -130,38 +130,48 @@
 
 static int kwd(char *s)
 {
-    int i;
-    struct {char* kw; int tt;} kwmap[] = {
-        {"type",        Ttype},
+    static const struct {char* kw; int tt;} kwmap[] = {
+        {"castto",      Tcast},
+        {"const",       Tconst},
+        {"default",     Tdefault},
+        {"elif",        Telif},
+        {"else",        Telse},
+        {"export",      Texport},
+        {"extern",      Textern},
+        {"false",       Tboollit},
         {"for",         Tfor},
-        {"while",       Twhile},
+        {"generic",     Tgeneric},
+        {"goto",        Tgoto},
         {"if",          Tif},
-        {"else",        Telse},
-        {"elif",        Telif},
         {"match",       Tmatch},
-        {"default",     Tdefault},
-        {"goto",        Tgoto},
-        {"struct",      Tstruct},
-        {"union",       Tunion},
-        {"const",       Tconst},
-        {"var",         Tvar},
-        {"generic",     Tgeneric},
-        {"castto",      Tcast},
-        {"extern",      Textern},
-        {"export",      Texport},
-        {"protect",     Tprotect},
-        {"use",         Tuse},
         {"pkg",         Tpkg},
+        {"protect",     Tprotect},
         {"sizeof",      Tsizeof},
+        {"struct",      Tstruct},
         {"true",        Tboollit},
-        {"false",       Tboollit},
-        {NULL, 0}
+        {"type",        Ttype},
+        {"union",       Tunion},
+        {"use",         Tuse},
+        {"var",         Tvar},
+        {"while",       Twhile},
     };
 
-    for (i = 0; kwmap[i].kw; i++)
-        if (!strcmp(kwmap[i].kw, s))
-            return kwmap[i].tt;
+    size_t min, max, mid;
+    int cmp;
 
+
+    min = 0;
+    max = sizeof(kwmap)/sizeof(kwmap[0]);
+    while (max > min) {
+        mid = (max + min) / 2;
+        cmp = strcmp(s, kwmap[mid].kw);
+        if (cmp == 0)
+            return kwmap[mid].tt;
+        else if (cmp > 0)
+            min = mid + 1;
+        else if (cmp < 0)
+            max = mid;
+    }
     return Tident;
 }
 
@@ -389,11 +399,20 @@
     return mktok(tt);
 };
 
+static int ord(char c)
+{
+    if (c >= '0' && c <= '9')
+        return c - '0';
+    else if (c >= 'a' && c <= 'z')
+        return c - 'a';
+    else
+        return c - 'A';
+}
+
 static Tok *number(int base)
 {
     Tok *t;
     int start;
-    char *endp;
     int c;
     int isfloat;
 
@@ -404,21 +423,17 @@
         next();
         if (c == '.')
             isfloat = 1;
+        if (ord(c) > base)
+            fatal(line, "Integer digit '%c' outside of base %d", c, base);
     }
 
     /* we only support base 10 floats */
     if (isfloat && base == 10) {
-        strtod(&fbuf[start], &endp);
-        if (endp == &fbuf[fidx]) {
-            t = mktok(Tfloatlit);
-            t->str = strdupn(&fbuf[start], fidx - start);
-        }
+        t = mktok(Tfloatlit);
+        t->str = strdupn(&fbuf[start], fidx - start);
     } else {
-        strtol(&fbuf[start], &endp, base);
-        if (endp == &fbuf[fidx]) {
-            t = mktok(Tintlit);
-            t->str = strdupn(&fbuf[start], fidx - start);
-        }
+        t = mktok(Tintlit);
+        t->str = strdupn(&fbuf[start], fidx - start);
     }
 
     return t;