[patch] scim_chewing_imengine_setup config_color_common looping bug

0 views
Skip to first unread message

Scott Tsai

unread,
May 20, 2006, 2:53:57 PM5/20/06
to Chewing IM Development
Patch is against scim-chewing-0.3.0

The setup code uses contructs like:
for (unsigned int i = 0; config_color_common[i].bg_key; i++) {
...
}
to loop over the config_color_common array, but there's no "end marker"
where the bg_key is False. This of course causes invalid memory access
thus crashing "scim-setup".

The patch below seems to fix it:
--- scim-chewing-0.3.0/src/scim_chewing_imengine_setup.cpp 2006-05-21
02:48:09.000000000 +0800
+++ /home/scottt/scim_chewing_imengine_setup.cpp.hacked 2006-05-21
02:47:44.000000000 +0800
@@ -212,6 +212,8 @@
#define FG_COLOR_DEFAULT "#000000"
#define FG_COLOR ""

+#define NELEM(a) (sizeof(a) / sizeof((a)[0]))
+
static ColorConfigData config_color_common[] = {
{
FG_COLOR,
@@ -660,7 +662,7 @@
}
}

- for (unsigned int i = 0; config_color_common[i].bg_key; i++) {
+ for (int i = 0; i<NELEM(config_color_common); i++) {
ColorConfigData &entry = config_color_common[i];
if (entry.widget) {
scim_color_button_set_colors (
@@ -752,12 +754,10 @@
__config_keyboards[ i ].data);
}

-#if 0
- for (unsigned int i = 0; config_color_common[i].bg_key; i++) {
+ for (unsigned int i = 0; i<NELEM(config_color_common); i++) {
ColorConfigData &entry = config_color_common[i];
entry.bg_value = config->read (String (entry.bg_key),
entry.bg_value);
}
-#endif

setup_widget_value ();

@@ -835,7 +835,7 @@
__config_keyboards [i].data);
}

- for (unsigned int i = 0; config_color_common[i].bg_key; i++) {
+ for (unsigned int i = 0; i<NELEM(config_color_common); i++) {
ColorConfigData &entry = config_color_common[i];
if (entry.changed) {
entry.bg_value = config->write (String (entry.bg_key),
@@ -914,7 +914,7 @@
if (!config_key)
return NULL;

- for (unsigned int i = 0; config_color_common[i].bg_key; i++) {
+ for (unsigned int i = 0; i<NELEM(config_color_common); i++) {
ColorConfigData *entry = &config_color_common[i];
if (entry->fg_key && !strcmp (entry->bg_key, config_key))
return entry;

Jim Huang

unread,
May 20, 2006, 10:36:20 PM5/20/06
to chewin...@googlegroups.com
2006/5/21, Scott Tsai <scot...@gmail.com>:

>
> Patch is against scim-chewing-0.3.0
>
> The setup code uses contructs like:
> for (unsigned int i = 0; config_color_common[i].bg_key; i++) {
> ...
> }
> to loop over the config_color_common array, but there's no "end marker"
> where the bg_key is False. This of course causes invalid memory access
> thus crashing "scim-setup".

hi Scott,

Applied. Thanks!

Sincerely,
-jserv

Reply all
Reply to author
Forward
0 new messages