[uim-commit] r400 - trunk/uim
ekato at freedesktop.org
ekato at freedesktop.org
Sun Jan 30 08:40:08 PST 2005
Author: ekato
Date: 2005-01-30 08:40:04 -0800 (Sun, 30 Jan 2005)
New Revision: 400
Modified:
trunk/uim/skk-dic.c
Log:
* uim/skk-dic.c (quote_word) : Malloc fixed sized memory instead
of using realloc() to avoid some memory problem.
(sanitize_word) : Cosmetic change.
Modified: trunk/uim/skk-dic.c
===================================================================
--- trunk/uim/skk-dic.c 2005-01-30 11:09:28 UTC (rev 399)
+++ trunk/uim/skk-dic.c 2005-01-30 16:40:04 UTC (rev 400)
@@ -1547,59 +1547,103 @@
ca->line->need_save = 1;
}
+#define CAND_QUOTE_BUFSIZ 1024
static char *
quote_word(const char *word)
{
char *str;
- const char *tmp;
+ const char *p;
int len;
- str= strdup("(concat \"");
- for (tmp = word; *tmp; tmp++) {
- len = strlen(str);
+ str = malloc(CAND_QUOTE_BUFSIZ);
+ if (!str)
+ return NULL;
+ strcpy(str, "(concat \"");
+ len = strlen(str);
- switch(*tmp) {
+ for (p = word; *p; p++) {
+ switch(*p) {
case '/':
- str = realloc(str, len + strlen("\\057") + 1);
+ len += strlen("\\057");
+ if (len >= CAND_QUOTE_BUFSIZ) {
+ free(str);
+ return NULL;
+ }
strcat(str, "\\057");
break;
case '[':
- str = realloc(str, len + strlen("[") + 1);
+ len += strlen("[");
+ if (len >= CAND_QUOTE_BUFSIZ) {
+ free(str);
+ return NULL;
+ }
strcat(str, "[");
break;
case ']':
- str = realloc(str, len + strlen("]") + 1);
+ len =+ strlen("]");
+ if (len >= CAND_QUOTE_BUFSIZ) {
+ free(str);
+ return NULL;
+ }
strcat(str, "]");
break;
case '\n':
- str = realloc(str, len + strlen("\\n") + 1);
+ len += strlen("\\n");
+ if (len >= CAND_QUOTE_BUFSIZ) {
+ free(str);
+ return NULL;
+ }
strcat(str, "\\n");
break;
case '\r':
- str = realloc(str, len + strlen("\\r") + 1);
+ len += strlen("\\r");
+ if (len >= CAND_QUOTE_BUFSIZ) {
+ free(str);
+ return NULL;
+ }
strcat(str, "\\r");
break;
case '\\':
- str = realloc(str, len + strlen("\\\\") + 1);
+ len += strlen("\\\\");
+ if (len >= CAND_QUOTE_BUFSIZ) {
+ free(str);
+ return NULL;
+ }
strcat(str, "\\\\");
break;
case ';':
- str = realloc(str, len + strlen("\\073") + 1);
+ len += strlen("\\073");
+ if (len >= CAND_QUOTE_BUFSIZ) {
+ free(str);
+ return NULL;
+ }
strcat(str, "\\073");
break;
case '"':
- str = realloc(str, len + strlen("\\\""));
+ len += strlen("\\\"");
+ if (len >= CAND_QUOTE_BUFSIZ) {
+ free(str);
+ return NULL;
+ }
strcat(str, "\\\"");
break;
default:
- str = realloc(str, len + 2);
- str[len] = *tmp;
+ if ((len + 1) >= CAND_QUOTE_BUFSIZ) {
+ free(str);
+ return NULL;
+ }
+ str[len] = *p;
str[len + 1] = '\0';
+ len++;
break;
}
}
- len = strlen(str);
- str = realloc(str, len + strlen("\")") + 1);
+
+ len += strlen("\")");
+ if (len >= CAND_QUOTE_BUFSIZ) {
+ free(str);
+ return NULL;
+ }
strcat(str, "\")");
return str;
@@ -1608,14 +1652,14 @@
static char *
sanitize_word(const char *arg)
{
- const char *tmp;
+ const char *p;
int is_space_only = 1;
if (!arg || !strlen(arg)) {
return NULL;
}
- for (tmp = arg; *tmp; tmp++) {
- switch(*tmp) {
+ for (p = arg; *p; p++) {
+ switch(*p) {
case '/':
case '[':
case ']':
More information about the Uim-commit
mailing list