wmcalc: Null-termitate display string when clearing.
Often, the number currently being displayed has more than 10 digits. However, when clearing the display, only the first 10 digits were cleared. When a new number was entered, it would be prepended to any digits that weren't cleared. This behavior was invisible to the user, causing incorrect calculations, e.g., Debian bug #564173: 1814 / 720 * 300 -> 7568.41111 But the correct answer is 755.833333. The problem was that when the display was cleared, the string that stores this number was not null-terminated. Indeed, 1814 / 720 gives us 2.519444444 (6 4's), but only 2.51944444 (5 4's) is displayed. When we begin to multiply by 300, the final 4 remained, and so we really were multiplying by 3004.
This commit is contained in:
parent
1d813d4434
commit
ec62fab633
|
@ -63,6 +63,7 @@ void clearcalc(void) {
|
|||
for (i=0; i < DISPSIZE; i++) {
|
||||
DispString[i] = ' ';
|
||||
}
|
||||
DispString[DISPSIZE] = '\0';
|
||||
OpFlag = ' ';
|
||||
} /***** End of function clearcalc() *****************************/
|
||||
|
||||
|
@ -94,6 +95,7 @@ void clearnum(void) {
|
|||
for (i=0; i < DISPSIZE; i++) {
|
||||
DispString[i] = ' ';
|
||||
}
|
||||
DispString[DISPSIZE] = '\0';
|
||||
|
||||
} /***** End of function clearnum() ******************************/
|
||||
|
||||
|
|
Loading…
Reference in a new issue