]> granicus.if.org Git - postgresql/commitdiff
Fixes:
authorTeodor Sigaev <teodor@sigaev.ru>
Tue, 11 Jan 2005 16:07:55 +0000 (16:07 +0000)
committerTeodor Sigaev <teodor@sigaev.ru>
Tue, 11 Jan 2005 16:07:55 +0000 (16:07 +0000)
1 Report error message instead of do nothing in case of error in regex
2 Malloced storage for mask, find and repl part of Affix. This parts may be
  large enough in real life (for example in czech, thanks to moje <moje@kalhotky.net>)

contrib/tsearch2/ispell/spell.c
contrib/tsearch2/ispell/spell.h

index c5783236b639797180ef204d8f925a9be60f3946..54b01e8ed73b6bf9e727ada5b7d27607da0fdfa3 100644 (file)
@@ -10,6 +10,8 @@
 #define MAX_NORM 1024
 #define MAXNORMLEN 256
 
+#define ERRSTRSIZE     1024
+
 #define STRNCASECMP(x,y)               pg_strncasecmp(x, y, strlen(y))
 #define GETWCHAR(W,L,N,T) ( ((uint8*)(W))[ ((T)==FF_PREFIX) ? (N) : ( (L) - 1 - (N) ) ] )
 #define GETCHAR(A,N,T)   GETWCHAR( (A)->repl, (A)->replen, N, T )
@@ -250,30 +252,35 @@ NIAddAffix(IspellDict * Conf, int flag, char flagflags, const char *mask, const
        {
                Conf->Affix[Conf->naffixes].issimple = 1;
                Conf->Affix[Conf->naffixes].isregis = 0;
-               *(Conf->Affix[Conf->naffixes].mask) = '\0';
+               Conf->Affix[Conf->naffixes].mask = strdup("");
        }
        else if (RS_isRegis(mask))
        {
                Conf->Affix[Conf->naffixes].issimple = 0;
                Conf->Affix[Conf->naffixes].isregis = 1;
-               strcpy(Conf->Affix[Conf->naffixes].mask, mask);
+               Conf->Affix[Conf->naffixes].mask = strdup(mask);
        }
        else
        {
                Conf->Affix[Conf->naffixes].issimple = 0;
                Conf->Affix[Conf->naffixes].isregis = 0;
+               Conf->Affix[Conf->naffixes].mask = (char*)malloc( strlen(mask) + 2 );
                if (type == FF_SUFFIX)
                        sprintf(Conf->Affix[Conf->naffixes].mask, "%s$", mask);
                else
                        sprintf(Conf->Affix[Conf->naffixes].mask, "^%s", mask);
        }
+       MEMOUT(Conf->Affix[Conf->naffixes].mask);
+
        Conf->Affix[Conf->naffixes].compile = 1;
        Conf->Affix[Conf->naffixes].flagflags = flagflags;
        Conf->Affix[Conf->naffixes].flag = flag;
        Conf->Affix[Conf->naffixes].type = type;
 
-       strcpy(Conf->Affix[Conf->naffixes].find, find);
-       strcpy(Conf->Affix[Conf->naffixes].repl, repl);
+       Conf->Affix[Conf->naffixes].find = strdup(find);
+       MEMOUT(Conf->Affix[Conf->naffixes].find);
+       Conf->Affix[Conf->naffixes].repl = strdup(repl);
+       MEMOUT(Conf->Affix[Conf->naffixes].repl);
        Conf->Affix[Conf->naffixes].replen = strlen(repl);
        Conf->naffixes++;
        return (0);
@@ -794,12 +801,9 @@ CheckAffix(const char *word, size_t len, AFFIX * Affix, char flagflags, char *ne
                        pfree(mask);
                        if (err)
                        {
-                               /*
-                                * regerror(err, &(Affix->reg.regex), regerrstr,
-                                * ERRSTRSIZE);
-                                */
-                               pg_regfree(&(Affix->reg.regex));
-                               return (NULL);
+                               char regerrstr[ERRSTRSIZE];     
+                               pg_regerror(err, &(Affix->reg.regex), regerrstr, ERRSTRSIZE);
+                               elog(ERROR, "Regex error in '%s': %s", Affix->mask, regerrstr);
                        }
                        Affix->compile = 0;
                }
@@ -1239,6 +1243,9 @@ NIFree(IspellDict * Conf)
                        else
                                pg_regfree(&(Affix[i].reg.regex));
                }
+               free(Affix[i].mask);
+               free(Affix[i].find);
+               free(Affix[i].repl);
        }
        if (Conf->Spell)
        {
index 44f1e7be08f7861b1aa0e9ca940a962629e25d4f..cc7935fd743f6f2d122ad829a0e97da0dec0d494 100644 (file)
@@ -54,9 +54,9 @@ typedef struct aff_struct
                                isregis:1,
                                unused:1,
                                replen:16;
-       char            mask[32];
-       char            find[16];
-       char            repl[16];
+       char            *mask;
+       char            *find;
+       char            *repl;
        union
        {
                regex_t         regex;