From: Shamus Hammons Date: Thu, 19 Feb 2015 16:04:29 +0000 (-0600) Subject: Fix for bad division in expressions. Thanks to A. Seed for reporting! X-Git-Tag: v2.1.0~206 X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=rmac;a=commitdiff_plain;h=d9aaeb6dc9db7a224a85e8a8ca44ddcb23cf7657 Fix for bad division in expressions. Thanks to A. Seed for reporting! --- diff --git a/direct.c b/direct.c index 3146c53..a2eef88 100644 --- 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 8e2c33a..07391ac 100644 --- 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; diff --git a/version.h b/version.h index 67cf96c..8ebcaff 100644 --- 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__