summaryrefslogtreecommitdiff
path: root/plugins/SpellChecker/src/hunspell/affentry.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/SpellChecker/src/hunspell/affentry.cxx')
-rw-r--r--plugins/SpellChecker/src/hunspell/affentry.cxx153
1 files changed, 97 insertions, 56 deletions
diff --git a/plugins/SpellChecker/src/hunspell/affentry.cxx b/plugins/SpellChecker/src/hunspell/affentry.cxx
index 6406f2577a..435fef804e 100644
--- a/plugins/SpellChecker/src/hunspell/affentry.cxx
+++ b/plugins/SpellChecker/src/hunspell/affentry.cxx
@@ -1,12 +1,16 @@
-#include "..\commons.h"
+#include "..\commons.h"
+
+#define MAXTEMPWORDLEN (MAXWORDUTF8LEN + 4)
PfxEntry::PfxEntry(AffixMgr* pmgr, affentry* dp)
+ // register affix manager
+ : pmyMgr(pmgr)
+ , next(NULL)
+ , nexteq(NULL)
+ , nextne(NULL)
+ , flgnxt(NULL)
{
- // register affix manager
- pmyMgr = pmgr;
-
// set up its initial values
-
aflag = dp->aflag; // flag
strip = dp->strip; // string to strip
appnd = dp->appnd; // string to append
@@ -19,9 +23,6 @@ PfxEntry::PfxEntry(AffixMgr* pmgr, affentry* dp)
memcpy(c.conds, dp->c.l.conds1, MAXCONDLEN_1);
c.l.conds2 = dp->c.l.conds2;
} else memcpy(c.conds, dp->c.conds, MAXCONDLEN);
- next = NULL;
- nextne = NULL;
- nexteq = NULL;
morphcode = dp->morphcode;
contclass = dp->contclass;
contclasslen = dp->contclasslen;
@@ -44,16 +45,17 @@ PfxEntry::~PfxEntry()
// add prefix to this word assuming conditions hold
char * PfxEntry::add(const char * word, int len)
{
- char tword[MAXWORDUTF8LEN + 4];
+ char tword[MAXTEMPWORDLEN];
if ((len > stripl || (len == 0 && pmyMgr->get_fullstrip())) &&
(len >= numconds) && test_condition(word) &&
(!stripl || (strncmp(word, strip, stripl) == 0)) &&
- ((MAXWORDUTF8LEN + 4) > (len + appndl - stripl))) {
+ ((MAXTEMPWORDLEN) > (len + appndl - stripl))) {
/* we have a match so add prefix */
char * pp = tword;
if (appndl) {
- strcpy(tword,appnd);
+ strncpy(tword, appnd, MAXTEMPWORDLEN-1);
+ tword[MAXTEMPWORDLEN-1] = '\0';
pp += appndl;
}
strcpy(pp, (word + stripl));
@@ -101,13 +103,15 @@ inline int PfxEntry::test_condition(const char * st)
if (*st == '\0' && p) return 0; // word <= condition
break;
}
- case '.': if (!pos) { // dots are not metacharacters in groups: [.]
+ case '.':
+ if (!pos) { // dots are not metacharacters in groups: [.]
p = nextchar(p);
// skip the next character
for (st++; (opts & aeUTF8) && (*st & 0xc0) == 0x80; st++);
if (*st == '\0' && p) return 0; // word <= condition
break;
}
+ /* FALLTHROUGH */
default: {
if (*st == *p) {
st++;
@@ -124,11 +128,11 @@ inline int PfxEntry::test_condition(const char * st)
}
if (pos && st != pos) {
ingroup = true;
- while (p && *p != ']' && (p = nextchar(p)));
+ while (p && *p != ']' && ((p = nextchar(p)) != NULL));
}
} else if (pos) {
ingroup = true;
- while (p && *p != ']' && (p = nextchar(p)));
+ while (p && *p != ']' && ((p = nextchar(p)) != NULL));
}
} else if (pos) { // group
p = nextchar(p);
@@ -144,7 +148,7 @@ struct hentry * PfxEntry::checkword(const char * word, int len, char in_compound
{
int tmpl; // length of tmpword
struct hentry * he; // hash entry of root word or NULL
- char tmpword[MAXWORDUTF8LEN + 4];
+ char tmpword[MAXTEMPWORDLEN];
// on entry prefix is 0 length or already matches the beginning of the word.
// So if the remaining root word has positive length
@@ -158,7 +162,10 @@ struct hentry * PfxEntry::checkword(const char * word, int len, char in_compound
// generate new root word by removing prefix and adding
// back any characters that would have been stripped
- if (stripl) strcpy (tmpword, strip);
+ if (stripl) {
+ strncpy(tmpword, strip, MAXTEMPWORDLEN-1);
+ tmpword[MAXTEMPWORDLEN-1] = '\0';
+ }
strcpy ((tmpword + stripl), (word + appndl));
// now make sure all of the conditions on characters
@@ -205,7 +212,7 @@ struct hentry * PfxEntry::check_twosfx(const char * word, int len,
{
int tmpl; // length of tmpword
struct hentry * he; // hash entry of root word or NULL
- char tmpword[MAXWORDUTF8LEN + 4];
+ char tmpword[MAXTEMPWORDLEN];
// on entry prefix is 0 length or already matches the beginning of the word.
// So if the remaining root word has positive length
@@ -220,7 +227,10 @@ struct hentry * PfxEntry::check_twosfx(const char * word, int len,
// generate new root word by removing prefix and adding
// back any characters that would have been stripped
- if (stripl) strcpy (tmpword, strip);
+ if (stripl) {
+ strncpy(tmpword, strip, MAXTEMPWORDLEN-1);
+ tmpword[MAXTEMPWORDLEN-1] = '\0';
+ }
strcpy ((tmpword + stripl), (word + appndl));
// now make sure all of the conditions on characters
@@ -252,7 +262,7 @@ char * PfxEntry::check_twosfx_morph(const char * word, int len,
char in_compound, const FLAG needflag)
{
int tmpl; // length of tmpword
- char tmpword[MAXWORDUTF8LEN + 4];
+ char tmpword[MAXTEMPWORDLEN];
// on entry prefix is 0 length or already matches the beginning of the word.
// So if the remaining root word has positive length
@@ -267,7 +277,10 @@ char * PfxEntry::check_twosfx_morph(const char * word, int len,
// generate new root word by removing prefix and adding
// back any characters that would have been stripped
- if (stripl) strcpy (tmpword, strip);
+ if (stripl) {
+ strncpy(tmpword, strip, MAXTEMPWORDLEN-1);
+ tmpword[MAXTEMPWORDLEN-1] = '\0';
+ }
strcpy ((tmpword + stripl), (word + appndl));
// now make sure all of the conditions on characters
@@ -299,7 +312,7 @@ char * PfxEntry::check_morph(const char * word, int len, char in_compound, const
{
int tmpl; // length of tmpword
struct hentry * he; // hash entry of root word or NULL
- char tmpword[MAXWORDUTF8LEN + 4];
+ char tmpword[MAXTEMPWORDLEN];
char result[MAXLNLEN];
char * st;
@@ -318,7 +331,10 @@ char * PfxEntry::check_morph(const char * word, int len, char in_compound, const
// generate new root word by removing prefix and adding
// back any characters that would have been stripped
- if (stripl) strcpy (tmpword, strip);
+ if (stripl) {
+ strncpy(tmpword, strip, MAXTEMPWORDLEN-1);
+ tmpword[MAXTEMPWORDLEN-1] = '\0';
+ }
strcpy ((tmpword + stripl), (word + appndl));
// now make sure all of the conditions on characters
@@ -386,10 +402,15 @@ char * PfxEntry::check_morph(const char * word, int len, char in_compound, const
}
SfxEntry::SfxEntry(AffixMgr * pmgr, affentry* dp)
+ : pmyMgr(pmgr) // register affix manager
+ , next(NULL)
+ , nexteq(NULL)
+ , nextne(NULL)
+ , flgnxt(NULL)
+ , l_morph(NULL)
+ , r_morph(NULL)
+ , eq_morph(NULL)
{
- // register affix manager
- pmyMgr = pmgr;
-
// set up its initial values
aflag = dp->aflag; // char flag
strip = dp->strip; // string to strip
@@ -404,7 +425,6 @@ SfxEntry::SfxEntry(AffixMgr * pmgr, affentry* dp)
memcpy(c.l.conds1, dp->c.l.conds1, MAXCONDLEN_1);
c.l.conds2 = dp->c.l.conds2;
} else memcpy(c.conds, dp->c.conds, MAXCONDLEN);
-
rappnd = myrevstrdup(appnd);
morphcode = dp->morphcode;
contclass = dp->contclass;
@@ -429,15 +449,16 @@ SfxEntry::~SfxEntry()
// add suffix to this word assuming conditions hold
char * SfxEntry::add(const char * word, int len)
{
- char tword[MAXWORDUTF8LEN + 4];
+ char tword[MAXTEMPWORDLEN];
/* make sure all conditions match */
if ((len > stripl || (len == 0 && pmyMgr->get_fullstrip())) &&
(len >= numconds) && test_condition(word + len, word) &&
(!stripl || (strcmp(word + len - stripl, strip) == 0)) &&
- ((MAXWORDUTF8LEN + 4) > (len + appndl - stripl))) {
+ ((MAXTEMPWORDLEN) > (len + appndl - stripl))) {
/* we have a match so add suffix */
- strcpy(tword,word);
+ strncpy(tword, word, MAXTEMPWORDLEN-1);
+ tword[MAXTEMPWORDLEN-1] = '\0';
if (appndl) {
strcpy(tword + len - stripl, appnd);
} else {
@@ -472,24 +493,37 @@ inline int SfxEntry::test_condition(const char * st, const char * beg)
int i = 1;
while (1) {
switch (*p) {
- case '\0': return 1;
- case '[': { p = nextchar(p); pos = st; break; }
- case '^': { p = nextchar(p); neg = true; break; }
- case ']': { if (!neg && !ingroup) return 0;
- i++;
- // skip the next character
- if (!ingroup) {
- for (; (opts & aeUTF8) && (st >= beg) && (*st & 0xc0) == 0x80; st--);
- st--;
- }
- pos = NULL;
- neg = false;
- ingroup = false;
- p = nextchar(p);
- if (st < beg && p) return 0; // word <= condition
- break;
- }
- case '.': if (!pos) { // dots are not metacharacters in groups: [.]
+ case '\0':
+ return 1;
+ case '[':
+ p = nextchar(p);
+ pos = st;
+ break;
+ case '^':
+ p = nextchar(p);
+ neg = true;
+ break;
+ case ']':
+ if (!neg && !ingroup)
+ return 0;
+ i++;
+ // skip the next character
+ if (!ingroup)
+ {
+ for (; (opts & aeUTF8) && (st >= beg) && (*st & 0xc0) == 0x80; st--);
+ st--;
+ }
+ pos = NULL;
+ neg = false;
+ ingroup = false;
+ p = nextchar(p);
+ if (st < beg && p)
+ return 0; // word <= condition
+ break;
+ case '.':
+ if (!pos)
+ {
+ // dots are not metacharacters in groups: [.]
p = nextchar(p);
// skip the next character
for (st--; (opts & aeUTF8) && (st >= beg) && (*st & 0xc0) == 0x80; st--);
@@ -504,6 +538,7 @@ inline int SfxEntry::test_condition(const char * st, const char * beg)
}
break;
}
+ /* FALLTHROUGH */
default: {
if (*st == *p) {
p = nextchar(p);
@@ -524,7 +559,7 @@ inline int SfxEntry::test_condition(const char * st, const char * beg)
if (neg) return 0;
else if (i == numconds) return 1;
ingroup = true;
- while (p && *p != ']' && (p = nextchar(p)));
+ while (p && *p != ']' && ((p = nextchar(p)) != NULL));
st--;
}
if (p && *p != ']') p = nextchar(p);
@@ -532,7 +567,7 @@ inline int SfxEntry::test_condition(const char * st, const char * beg)
if (neg) return 0;
else if (i == numconds) return 1;
ingroup = true;
- while (p && *p != ']' && (p = nextchar(p)));
+ while (p && *p != ']' && ((p = nextchar(p)) != NULL));
// if (p && *p != ']') p = nextchar(p);
st--;
}
@@ -558,7 +593,7 @@ struct hentry * SfxEntry::checkword(const char * word, int len, int optflags,
int tmpl; // length of tmpword
struct hentry * he; // hash entry pointer
unsigned char * cp;
- char tmpword[MAXWORDUTF8LEN + 4];
+ char tmpword[MAXTEMPWORDLEN];
PfxEntry* ep = ppfx;
// if this suffix is being cross checked with a prefix
@@ -583,7 +618,8 @@ struct hentry * SfxEntry::checkword(const char * word, int len, int optflags,
// back any characters that would have been stripped or
// or null terminating the shorter string
- strcpy (tmpword, word);
+ strncpy (tmpword, word, MAXTEMPWORDLEN-1);
+ tmpword[MAXTEMPWORDLEN-1] = '\0';
cp = (unsigned char *)(tmpword + tmpl);
if (stripl) {
strcpy ((char *)cp, strip);
@@ -636,7 +672,10 @@ struct hentry * SfxEntry::checkword(const char * word, int len, int optflags,
} else if (wlst && (*ns < maxSug)) {
int cwrd = 1;
for (int k=0; k < *ns; k++)
- if (strcmp(tmpword, wlst[k]) == 0) cwrd = 0;
+ if (strcmp(tmpword, wlst[k]) == 0) {
+ cwrd = 0;
+ break;
+ }
if (cwrd) {
wlst[*ns] = mystrdup(tmpword);
if (wlst[*ns] == NULL) {
@@ -659,7 +698,7 @@ struct hentry * SfxEntry::check_twosfx(const char * word, int len, int optflags,
int tmpl; // length of tmpword
struct hentry * he; // hash entry pointer
unsigned char * cp;
- char tmpword[MAXWORDUTF8LEN + 4];
+ char tmpword[MAXTEMPWORDLEN];
PfxEntry* ep = ppfx;
@@ -683,7 +722,8 @@ struct hentry * SfxEntry::check_twosfx(const char * word, int len, int optflags,
// back any characters that would have been stripped or
// or null terminating the shorter string
- strcpy (tmpword, word);
+ strncpy(tmpword, word, MAXTEMPWORDLEN-1);
+ tmpword[MAXTEMPWORDLEN-1] = '\0';
cp = (unsigned char *)(tmpword + tmpl);
if (stripl) {
strcpy ((char *)cp, strip);
@@ -720,7 +760,7 @@ char * SfxEntry::check_twosfx_morph(const char * word, int len, int optflags,
{
int tmpl; // length of tmpword
unsigned char * cp;
- char tmpword[MAXWORDUTF8LEN + 4];
+ char tmpword[MAXTEMPWORDLEN];
PfxEntry* ep = ppfx;
char * st;
@@ -748,7 +788,8 @@ char * SfxEntry::check_twosfx_morph(const char * word, int len, int optflags,
// back any characters that would have been stripped or
// or null terminating the shorter string
- strcpy (tmpword, word);
+ strncpy(tmpword, word, MAXTEMPWORDLEN-1);
+ tmpword[MAXTEMPWORDLEN-1] = '\0';
cp = (unsigned char *)(tmpword + tmpl);
if (stripl) {
strcpy ((char *)cp, strip);