Fix random crashes in Korean, Japanese, and some other languages

Occasionally running Tux Paint in Korean, Japanese, and possibly other
languages would cause Tux Paint to crash.  This commit fixes it.

This bug was previously mentioned as the possible cause of these
previously reported crashes, though they were determined to be
unrelated:

  https://sourceforge.net/p/tuxpaint/mailman/message/37364981/
  https://sourceforge.net/p/tuxpaint/mailman/message/37376574/

The cause of the crash turned out to be in the function that loads the
input method map (*.im).  Some languages that use more than one
keystroke to produce one unicode character use this mapfile to track, in
a state machine, what keys have been pressed and what unicode character
should be output.  This state machine's memory is increased dynamically
as needed when the input method map file is loaded.  There was a line of
code that references the old memory that could have moved by the memory
increase.  This line of code has been moved to prior to the memory
increase to avoid accessing memory that may have moved.
This commit is contained in:
Mark Kim 2022-02-06 20:29:55 -05:00
parent c9e195549f
commit e1ecf80e26
2 changed files with 5 additions and 2 deletions

View file

@ -138,6 +138,10 @@ http://www.tuxpaint.org/
* Address issue with uppercase-only mode in Turkish locale.
Pere Pujal i Carabantes <perepujal@gmail.com>
* Fixed a bug that can randomly crash Tux Paint when started in a language
with a input method map (*.im).
Mark Kim <markuskimius@gmail.com>
* Ports & Building:
-----------------
* Windows

View file

@ -447,6 +447,7 @@ static int sm_add(STATE_MACHINE * sm, char *seq, const wchar_t * unicode, char f
return 1;
}
sm_init(next->state);
sm_found = next->state;
/* Increase store for next time, if necessary */
if (++(sm->next_size) >= sm->next_maxsize)
@ -457,8 +458,6 @@ static int sm_add(STATE_MACHINE * sm, char *seq, const wchar_t * unicode, char f
return 1;
}
}
sm_found = next->state;
}
/* Recurse */