Commit 5b354d2c authored by Teodor Sigaev's avatar Teodor Sigaev

Fixes:

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>)
parent e2480165
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
#define MAX_NORM 1024 #define MAX_NORM 1024
#define MAXNORMLEN 256 #define MAXNORMLEN 256
#define ERRSTRSIZE 1024
#define STRNCASECMP(x,y) pg_strncasecmp(x, y, strlen(y)) #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 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 ) #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 ...@@ -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].issimple = 1;
Conf->Affix[Conf->naffixes].isregis = 0; Conf->Affix[Conf->naffixes].isregis = 0;
*(Conf->Affix[Conf->naffixes].mask) = '\0'; Conf->Affix[Conf->naffixes].mask = strdup("");
} }
else if (RS_isRegis(mask)) else if (RS_isRegis(mask))
{ {
Conf->Affix[Conf->naffixes].issimple = 0; Conf->Affix[Conf->naffixes].issimple = 0;
Conf->Affix[Conf->naffixes].isregis = 1; Conf->Affix[Conf->naffixes].isregis = 1;
strcpy(Conf->Affix[Conf->naffixes].mask, mask); Conf->Affix[Conf->naffixes].mask = strdup(mask);
} }
else else
{ {
Conf->Affix[Conf->naffixes].issimple = 0; Conf->Affix[Conf->naffixes].issimple = 0;
Conf->Affix[Conf->naffixes].isregis = 0; Conf->Affix[Conf->naffixes].isregis = 0;
Conf->Affix[Conf->naffixes].mask = (char*)malloc( strlen(mask) + 2 );
if (type == FF_SUFFIX) if (type == FF_SUFFIX)
sprintf(Conf->Affix[Conf->naffixes].mask, "%s$", mask); sprintf(Conf->Affix[Conf->naffixes].mask, "%s$", mask);
else else
sprintf(Conf->Affix[Conf->naffixes].mask, "^%s", mask); sprintf(Conf->Affix[Conf->naffixes].mask, "^%s", mask);
} }
MEMOUT(Conf->Affix[Conf->naffixes].mask);
Conf->Affix[Conf->naffixes].compile = 1; Conf->Affix[Conf->naffixes].compile = 1;
Conf->Affix[Conf->naffixes].flagflags = flagflags; Conf->Affix[Conf->naffixes].flagflags = flagflags;
Conf->Affix[Conf->naffixes].flag = flag; Conf->Affix[Conf->naffixes].flag = flag;
Conf->Affix[Conf->naffixes].type = type; Conf->Affix[Conf->naffixes].type = type;
strcpy(Conf->Affix[Conf->naffixes].find, find); Conf->Affix[Conf->naffixes].find = strdup(find);
strcpy(Conf->Affix[Conf->naffixes].repl, repl); 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->Affix[Conf->naffixes].replen = strlen(repl);
Conf->naffixes++; Conf->naffixes++;
return (0); return (0);
...@@ -794,12 +801,9 @@ CheckAffix(const char *word, size_t len, AFFIX * Affix, char flagflags, char *ne ...@@ -794,12 +801,9 @@ CheckAffix(const char *word, size_t len, AFFIX * Affix, char flagflags, char *ne
pfree(mask); pfree(mask);
if (err) if (err)
{ {
/* char regerrstr[ERRSTRSIZE];
* regerror(err, &(Affix->reg.regex), regerrstr, pg_regerror(err, &(Affix->reg.regex), regerrstr, ERRSTRSIZE);
* ERRSTRSIZE); elog(ERROR, "Regex error in '%s': %s", Affix->mask, regerrstr);
*/
pg_regfree(&(Affix->reg.regex));
return (NULL);
} }
Affix->compile = 0; Affix->compile = 0;
} }
...@@ -1239,6 +1243,9 @@ NIFree(IspellDict * Conf) ...@@ -1239,6 +1243,9 @@ NIFree(IspellDict * Conf)
else else
pg_regfree(&(Affix[i].reg.regex)); pg_regfree(&(Affix[i].reg.regex));
} }
free(Affix[i].mask);
free(Affix[i].find);
free(Affix[i].repl);
} }
if (Conf->Spell) if (Conf->Spell)
{ {
......
...@@ -54,9 +54,9 @@ typedef struct aff_struct ...@@ -54,9 +54,9 @@ typedef struct aff_struct
isregis:1, isregis:1,
unused:1, unused:1,
replen:16; replen:16;
char mask[32]; char *mask;
char find[16]; char *find;
char repl[16]; char *repl;
union union
{ {
regex_t regex; regex_t regex;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment