Use static memory for chosen_charset
authorMichael Schutte <michi@uiae.at>
Sat, 9 May 2009 17:29:16 +0000 (19:29 +0200)
committerMichael Schutte <michi@uiae.at>
Sat, 9 May 2009 17:29:29 +0000 (19:29 +0200)
Signed-off-by: Michael Schutte <michi@uiae.at>
src/ksyms.c

index 5bbcfd0..888f44e 100644 (file)
@@ -1641,12 +1641,14 @@ struct cs {
     { "iso-10646-18",  iso_10646_18_syms, 159 },       /* ethiopic */
     { "iso-ir-197",    iso_ir_197_syms, 160 },         /* sami */
     { "iso-ir-209",    iso_ir_209_syms, 160 },         /* sami */
+    /* When you add a new charset with a long (> 15 chars) name,
+     * please update the chosen_charset definition below. */
 };
 
 /* Functions for both dumpkeys and loadkeys. */
 
 int prefer_unicode = 0;
-static char *chosen_charset = NULL;
+static char chosen_charset[16] = "";
 
 void
 list_charsets(FILE *f) {
@@ -1696,9 +1698,7 @@ set_charset(const char *charset) {
                                if(p->name[0])
                                        syms[0].table[i] = p->name;
                        }
-                       if (chosen_charset)
-                               free(chosen_charset);
-                       chosen_charset = strdup(charset);
+                       strcpy(chosen_charset, charset);
                        return 0;
                }
        }
@@ -1798,12 +1798,12 @@ ksymtocode(const char *s, int direction) {
                                if (!strcmp(s,p->name))
                                        return (p->uni ^ 0xf000);
                }
-       } else /* if (!chosen_charset) */ {
+       } else /* if (!chosen_charset[0]) */ {
                /* note: some keymaps use latin1 but with euro,
                   so set_charset() would fail */
                /* note: some keymaps with charset line still use
                   symbols from more than one character set,
-                  so we cannot have the  `if (!chosen_charset)'  here */
+                  so we cannot have the  `if (!chosen_charset[0])'  here */
 
                for (i = 0; i < 256 - 160; i++)
                        if (!strcmp(s, latin1_syms[i].name)) {