Fix for bad division in expressions. Thanks to A. Seed for reporting!
authorShamus Hammons <jlhamm@acm.org>
Thu, 19 Feb 2015 16:04:29 +0000 (10:04 -0600)
committerShamus Hammons <jlhamm@acm.org>
Thu, 19 Feb 2015 16:04:29 +0000 (10:04 -0600)
direct.c
expr.c
version.h

index 3146c5345599c18d9703daa1c787ce157e961ceb..a2eef8867618154b181ec48ba513a4afb1c16387 100644 (file)
--- a/direct.c
+++ b/direct.c
@@ -25,6 +25,7 @@
 TOKEN exprbuf[128];                    // Expression buffer 
 SYM * symbolPtr[1000000];      // Symbol pointers table
 static long unused;                    // For supressing 'write' warnings
+char buffer[256];                      // Scratch buffer for messages
 
 
 // Directive handler table
@@ -810,7 +811,6 @@ int d_dc(WORD siz)
                // dc.b 'string' [,] ...
                if (siz == SIZB && *tok == STRING && (tok[2] == ',' || tok[2] == EOL))
                {
-//                     i = strlen((const char*)tok[1]);
                        i = strlen(string[tok[1]]);
 
                        if ((challoc - ch_size) < i) 
@@ -854,7 +854,11 @@ int d_dc(WORD siz)
                                        return error("non-absolute byte value");
 
                                if (eval + 0x100 >= 0x200)
-                                       return error(range_error);
+                               {
+                                       sprintf(buffer, "%s (value = $%X)", range_error, eval);
+//                                     return error(range_error);
+                                       return error(buffer);
+                               }
 
                                D_byte(eval);
                        }
diff --git a/expr.c b/expr.c
index 8e2c33aa11f93e37538e13a75a91daa293d5832f..07391acfe6f8fceb5dfaabcdaea036f1acf9b117 100644 (file)
--- a/expr.c
+++ b/expr.c
@@ -531,7 +531,9 @@ int evexpr(TOKEN * tk, VALUE * a_value, WORD * a_attr, SYM ** a_esym)
 //printf("evexpr(): +\n");
                        --sval;                                                 // Pop value
                        --sattr;                                                // Pop attrib 
+//printf("--> N+N: %i + %i = ", *sval, sval[1]);
                        *sval += sval[1];                               // Compute value
+//printf("%i\n", *sval);
 
                        if (!(*sattr & TDB))
                                *sattr = sattr[1];
@@ -543,7 +545,9 @@ int evexpr(TOKEN * tk, VALUE * a_value, WORD * a_attr, SYM ** a_esym)
 //printf("evexpr(): -\n");
                        --sval;                                                 // Pop value
                        --sattr;                                                // Pop attrib 
+//printf("--> N-N: %i - %i = ", *sval, sval[1]);
                        *sval -= sval[1];                               // Compute value
+//printf("%i\n", *sval);
 
                        attr = (WORD)(*sattr & TDB);
 #if 0
@@ -664,7 +668,9 @@ printf("EVEXPR (-): sym1 = %X, sym2 = %X\n", attr, sattr[1]);
                        case '*':
                                --sval;
                                --sattr;                                        // Pop attrib 
+//printf("--> NxN: %i x %i = ", *sval, sval[1]);
                                *sval *= sval[1];
+//printf("%i\n", *sval);
                                break;
                        case '/':
                                --sval;
@@ -673,7 +679,13 @@ printf("EVEXPR (-): sym1 = %X, sym2 = %X\n", attr, sattr[1]);
                                if (sval[1] == 0)
                                        return error("divide by zero");
 
-                               *sval /= sval[1];
+//printf("--> N/N: %i / %i = ", sval[0], sval[1]);
+                               // Compiler is picky here: Without casting these, it discards
+                               // the sign if dividing a negative # by a positive one,
+                               // creating a bad result. :-/
+                               // Probably a side effect of using VALUE intead of ints.
+                               *sval = (int)sval[0] / (int)sval[1];
+//printf("%i\n", *sval);
                                break;
                        case '%':
                                --sval;
index 67cf96c17d5a9a9b79a5ebf657524532ff2c3fd5..8ebcaff774854ca9933ebb5ca78859e65ea5b24e 100644 (file)
--- a/version.h
+++ b/version.h
@@ -13,6 +13,6 @@
 
 #define MAJOR   1              // Major version number
 #define MINOR   3              // Minor version number
-#define PATCH   4              // Patch release number
+#define PATCH   5              // Patch release number
 
 #endif // __VERSION_H__