From e1ecf80e26a5897f6e1da583625c906a97ff8a4d Mon Sep 17 00:00:00 2001 From: Mark Kim Date: Sun, 6 Feb 2022 20:29:55 -0500 Subject: [PATCH] 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. --- docs/CHANGES.txt | 4 ++++ src/im.c | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/docs/CHANGES.txt b/docs/CHANGES.txt index f6c7a258f..08ba47f1a 100644 --- a/docs/CHANGES.txt +++ b/docs/CHANGES.txt @@ -138,6 +138,10 @@ http://www.tuxpaint.org/ * Address issue with uppercase-only mode in Turkish locale. Pere Pujal i Carabantes + * Fixed a bug that can randomly crash Tux Paint when started in a language + with a input method map (*.im). + Mark Kim + * Ports & Building: ----------------- * Windows diff --git a/src/im.c b/src/im.c index f8874e904..81a97bf55 100644 --- a/src/im.c +++ b/src/im.c @@ -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 */