fix crash when displaying numbers between [0.1, 1)

This commit is contained in:
Jeff Wang 2019-04-05 00:52:56 -04:00
parent 66c611795e
commit ef298cddd0
2 changed files with 4 additions and 3 deletions

View File

@ -132,8 +132,7 @@ The keys on the original calculator map as follows:
Hold `mode` and `0` at the same time to turn off. NOTE: There is no auto power off. Hold `mode` and `0` at the same time to turn off. NOTE: There is no auto power off.
# Bugs # Bugs
1. Currently, trying to display numbers between `[0.1, 1)` causes the calculator to crash. 1. The calculator does not properly check for overflow.
1. There are other calculations which can randomly cause the calculator to crash.
1. There are probably more bugs waiting to be discovered. 1. There are probably more bugs waiting to be discovered.
# Internals # Internals

View File

@ -806,7 +806,9 @@ int8_t decn_to_str(char* buf, const dec80* x){
buf[i] = '0'; buf[i] = '0';
i++; i++;
INSERT_DOT(); INSERT_DOT();
for (j = exponent + 1; j < 0; j++){ //pad zeros right of decimal point
// for (j = exponent + 1; j < 0; j++){ <--- results in undefined behavior (signed overflow), and causes crash
for (j = -exponent -1; j > 0; --j){
buf[i] = '0'; buf[i] = '0';
i++; i++;
} }