Description: repair problematic static buffer returned by norm_charmap() Author: Alexander Zangerl --- a/sbr/norm_charmap.c +++ b/sbr/norm_charmap.c @@ -28,12 +28,10 @@ #define digit(x) ((x) >= '0' && (x) <= '9') -static char buf[16]; - char * norm_charmap(char *name) { - char *p; + char *p, *buf; if (!name) return name; @@ -73,6 +71,9 @@ norm_charmap(char *name) /* ISO 8859 will be converted to "ISO-8859-x" */ if ((p = strstr(name, "8859-"))) { + /* mustn't overwrite previous norm_charmap results, so dynamic buffer */ + if (!(buf=malloc(16))) + return buf; memcpy(buf, "ISO-8859-\0\0", 12); p += 5; if (digit(*p)) { @@ -80,10 +81,14 @@ norm_charmap(char *name) if (digit(*p)) buf[10] = *p++; return buf; } + free(buf); /* free mem if dud input */ } /* Windows code pages will be converted to "WINDOWS-12xx" */ if ((p = strstr(name, "CP12"))) { + /* mustn't overwrite previous norm_charmap results, so dynamic buffer */ + if (!(buf=malloc(16))) + return buf; memcpy(buf, "WINDOWS-12\0\0", 13); p += 4; if (digit(*p)) { @@ -91,6 +96,7 @@ norm_charmap(char *name) if (digit(*p)) buf[11] = *p++; return buf; } + free(buf); /* free mem if dud input */ } /* TIS-620 comes in at least the following two forms */