This is an automated email from the git hooks/post-receive script. rene pushed a commit to branch master in repository hunspell.
commit e01549c1930134330f8f8d3be208b8ac735aa676 Author: Rene Engelhard <[email protected]> Date: Thu Apr 21 14:45:16 2016 +0200 Imported Upstream version 1.1.8 --- ChangeLog | 62 ++++++++++++++++++++++++++++++++++-- NEWS | 8 +++++ README | 2 ++ THANKS | 2 ++ configure | 20 ++++++------ configure.ac | 4 +-- src/hunspell/affentry.cxx | 5 +-- src/hunspell/affixmgr.cxx | 2 +- src/hunspell/atypes.hxx | 2 +- src/hunspell/csutil.cxx | 28 +++++++++------- src/hunspell/dictmgr.cxx | 18 +++++++---- src/hunspell/hashmgr.cxx | 48 +++++++++++++++++++++------- src/hunspell/hunspell.cxx | 28 ++++++++-------- src/hunspell/hunspell.hxx | 16 +++++++--- src/hunspell/suggestmgr.cxx | 15 +++++++-- src/tools/hunspell.cxx | 26 +++++++++------ src/win_api/hunspelldll.c | 8 +++-- src/win_api/hunspelldll.h | 10 +++++- tests/Makefile.am | 7 ++++ tests/Makefile.in | 7 ++++ tests/base.aff | 2 +- tests/base.dic | 3 +- tests/base.good | 7 +++- tests/base.sug | 1 + tests/base.wrong | 2 +- tests/{base.aff => base_utf.aff} | 5 +-- tests/{base.dic => base_utf.dic} | 3 +- tests/{base.good => base_utf.good} | 7 +++- tests/{base.sug => base_utf.sug} | 1 + tests/base_utf.test | 4 +++ tests/{base.wrong => base_utf.wrong} | 2 +- tests/test.sh | 4 +-- 32 files changed, 264 insertions(+), 95 deletions(-) diff --git a/ChangeLog b/ChangeLog index b4058ba..ef72bb7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,60 @@ +2007-07-16 Németh László <nemeth at OOo>: + * hunspell.cxx: fix dot removing from UTF-8 encoded words in cleanword2() + (Capitalised words with dots, as "Something." were not recognised + using Unicode encoded dictionaries.) + * tests/{base.*,base_utf.*}: extended and new test files for + dot removing and Unicode support. + + * tools/hunspell.cxx: fix Cygwin, OS X compatibility using platform + specifics iconv() header by ICONV_CONST macro of Autoconf. + Sf.net Bug ID 1746030, reported by Mike Tian-Jian Jiang. + Sf.net Bug ID 1753939, reported by Jean-Christophe Helary. + + * tools/hunspell.cxx: fix missing global path setting with -d option. + + * tests/test.sh: fix broken Valgrind checking (missing warnings + with VALGRIND=memcheck make check). + + * csutil.cxx: fix condition in u8_u16() to avoid invalid read + of not null-terminated character arrays (detected by Valgrind + in Hunspell executable: associated with 8-bit character table + conversion in tools/hunspell.cxx). + + * csutil.cxx: free_utf_tbl(): use utf_tbl_count-- instead of utf_tbl--. + Memory leak in Hunspell executable detected by Valgrind. + + * hashmgr.cxx: add missing free_utf_tbl(), memory leak in Hunspell + executable detected by Valgrind. + + * hashmgr.cxx: load_tables(): fix memory error in spec. capitalization. + Use sizeof(unsigned short) instead of bad sizeof(unsigned short*). + Invalid memory read detected by Valgrind. + + * hashmgr.cxx: add_word(): fix memory error in spec. capitalization. + Update also affix array length of capitalized homonyms. Invalid + memory read detected by Valgrind. + + * hunspell.cxx: suggest(): fix invalid memory write and leak. + Bad realloc() and missing free() detected by Valgrind associated + with suggestions for "something.The" type spelling errors. + + * {dictmgr,csutil,hashmgr,suggestmgr}.cxx: check memory allocation. + Sf.net Bug ID 1747507, based on the patch by Jose da Silva. + +2007-07-13 Ingo H. De Boer <idb_winshell at SF.net>: + * atypes.cxx: fix Visual C compatibility: Using + "HUNSPELL_WARNING(a,b,...} {}" macro instead of empty "X(a,b...)". + + * hunspell.cxx: changes for Windows API. + * win_api/Hunspell.*: new resource files + * win_api/hunspelldll.*: set optional Hunspell and Borland spec. codes + Sf.net Bug ID 1753802, patch by Ingo H. de Boer. + See also Sf.net Bug ID 1751406, patch by Mike Tian-Jian Jiang. + +2007-07-09 Caolan McNamara <cmc at OO.o>: + * {hunspell,hashmgr,affentry}.cxx: fix warnings of Coverity program + analyzer. Sf.net Bug ID, 1750219. + 2007-07-06 Németh László <nemeth at OOo>: * atypes.cxx: warning-free swallowing of conditional warning messages and their parameters using empty HUNSPELL_WARNING(a,b...) macro. @@ -95,9 +152,8 @@ fixes: Sf.net Bug ID 1693875, reported by Ingo H. de Boer. * affixmgr.cxx, suggestmgr.cxx, license.hunspell: convert to ASCII. - - locale dependent compiling problems reported by Thomas Lange - in OOo Issue 78018. - Sf.net Bug ID 694379, reported by user B6s on Sourceforge.net. + Locale dependent compiling problems. Sf.net Bug ID 1694379, reported + by Mike Tian-Jian Jiang. OOo Issue 78018 reported by Thomas Lange. * tests/test.sh: compatibility issues - fix Valgrind support (check shared library instead of shell wrapper) diff --git a/NEWS b/NEWS index 9898c54..b5e12d0 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,11 @@ +2007-07-16: Hunspell 1.1.8 release: + - better Mac OS X/Cygwin and Windows compatibility + + - fix Hunspell's Valgrind environment and memory handling errors + detected by Valgrind + + - other bug fixes (see ChangeLog) + 2007-07-06: Hunspell 1.1.7 release: - fix warning messages of OpenOffice.org build diff --git a/README b/README index 5d397cc..a718501 100644 --- a/README +++ b/README @@ -67,10 +67,12 @@ make check or with Valgrind debugger: +make check VALGRIND=[Valgrind_tool] make check For example: +make check VALGRIND=memcheck make check Documentation diff --git a/THANKS b/THANKS index 360a1bd..02bb5e3 100644 --- a/THANKS +++ b/THANKS @@ -18,8 +18,10 @@ Chris Halls Khaled Hosny Izsók András Björn Jacke +Mike Tian-Jian Jiang Dafydd Jones Ryan Jones +Jean-Christophe Helary Kevin Hendricks Martin Hollmichel Kéménczy Kálmán diff --git a/configure b/configure index b747a19..0b3be98 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.59 for hunspell 1.1.7. +# Generated by GNU Autoconf 2.59 for hunspell 1.1.8. # # Report bugs to <[email protected]>. # @@ -423,8 +423,8 @@ SHELL=${CONFIG_SHELL-/bin/sh} # Identity of this package. PACKAGE_NAME='hunspell' PACKAGE_TARNAME='hunspell' -PACKAGE_VERSION='1.1.7' -PACKAGE_STRING='hunspell 1.1.7' +PACKAGE_VERSION='1.1.8' +PACKAGE_STRING='hunspell 1.1.8' PACKAGE_BUGREPORT='[email protected]' ac_unique_file="config.h.in" @@ -954,7 +954,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures hunspell 1.1.7 to adapt to many kinds of systems. +\`configure' configures hunspell 1.1.8 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1021,7 +1021,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of hunspell 1.1.7:";; + short | recursive ) echo "Configuration of hunspell 1.1.8:";; esac cat <<\_ACEOF @@ -1171,7 +1171,7 @@ fi test -n "$ac_init_help" && exit 0 if $ac_init_version; then cat <<\_ACEOF -hunspell configure 1.1.7 +hunspell configure 1.1.8 generated by GNU Autoconf 2.59 Copyright (C) 2003 Free Software Foundation, Inc. @@ -1185,7 +1185,7 @@ cat >&5 <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by hunspell $as_me 1.1.7, which was +It was created by hunspell $as_me 1.1.8, which was generated by GNU Autoconf 2.59. Invocation command line was $ $0 $@ @@ -1916,7 +1916,7 @@ fi # Define the identity of the package. PACKAGE=hunspell - VERSION=1.1.7 + VERSION=1.1.8 cat >>confdefs.h <<_ACEOF @@ -23886,7 +23886,7 @@ _ASBOX } >&5 cat >&5 <<_CSEOF -This file was extended by hunspell $as_me 1.1.7, which was +This file was extended by hunspell $as_me 1.1.8, which was generated by GNU Autoconf 2.59. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -23949,7 +23949,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF ac_cs_version="\\ -hunspell config.status 1.1.7 +hunspell config.status 1.1.8 configured by $0, generated by GNU Autoconf 2.59, with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\" diff --git a/configure.ac b/configure.ac index 19afbcd..4e2e38c 100644 --- a/configure.ac +++ b/configure.ac @@ -5,7 +5,7 @@ m4_pattern_allow AC_PREREQ(2.59) -AC_INIT([hunspell],[1.1.7],[[email protected]]) +AC_INIT([hunspell],[1.1.8],[[email protected]]) AC_CANONICAL_SYSTEM case "$host" in @@ -13,7 +13,7 @@ arm*) XFAILED="flagutf8.test maputf.test";; esac AC_SUBST(XFAILED) -AM_INIT_AUTOMAKE(hunspell, 1.1.7) +AM_INIT_AUTOMAKE(hunspell, 1.1.8) HUNSPELL_VERSION_MAJOR=`echo $VERSION | cut -d"." -f1` HUNSPELL_VERSION_MINOR=`echo $VERSION | cut -d"." -f2` AC_SUBST(HUNSPELL_VERSION_MAJOR) diff --git a/src/hunspell/affentry.cxx b/src/hunspell/affentry.cxx index 308aeb5..6c98112 100644 --- a/src/hunspell/affentry.cxx +++ b/src/hunspell/affentry.cxx @@ -722,14 +722,15 @@ struct hentry * SfxEntry::get_next_homonym(struct hentry * he, int optflags, Aff const FLAG cclass, const FLAG needflag) { PfxEntry* ep = (PfxEntry *) ppfx; + FLAG eFlag = ep ? ep->getFlag() : FLAG_NULL; while (he->next_homonym) { he = he->next_homonym; if ((TESTAFF(he->astr, aflag, he->alen) || (ep && ep->getCont() && TESTAFF(ep->getCont(), aflag, ep->getContLen()))) && ((optflags & aeXPRODUCT) == 0 || - TESTAFF(he->astr, ep->getFlag(), he->alen) || + TESTAFF(he->astr, eFlag, he->alen) || // handle conditional suffix - ((contclass) && TESTAFF(contclass, ep->getFlag(), contclasslen)) + ((contclass) && TESTAFF(contclass, eFlag, contclasslen)) ) && // handle cont. class ((!cclass) || diff --git a/src/hunspell/affixmgr.cxx b/src/hunspell/affixmgr.cxx index e18788f..033c6e7 100644 --- a/src/hunspell/affixmgr.cxx +++ b/src/hunspell/affixmgr.cxx @@ -2940,7 +2940,7 @@ int AffixMgr::get_checksharps() char * AffixMgr::get_ignore() { if (!ignorechars) return NULL; - return mystrdup(ignorechars); + return ignorechars; } // return the preferred ignore string for suggestions diff --git a/src/hunspell/atypes.hxx b/src/hunspell/atypes.hxx index c636b85..35d64bf 100644 --- a/src/hunspell/atypes.hxx +++ b/src/hunspell/atypes.hxx @@ -6,7 +6,7 @@ #define HUNSPELL_WARNING fprintf #define WARNVAR warnvar #else -#define HUNSPELL_WARNING(a,b...) +#define HUNSPELL_WARNING(a,b,...) {} #define WARNVAR #endif #endif diff --git a/src/hunspell/csutil.cxx b/src/hunspell/csutil.cxx index 673f2d1..1afdd93 100644 --- a/src/hunspell/csutil.cxx +++ b/src/hunspell/csutil.cxx @@ -48,8 +48,8 @@ using namespace std; #endif #endif -struct unicode_info2 * utf_tbl = NULL; -int utf_tbl_count = 0; // utf_tbl can be used by multiple Hunspell instances +static struct unicode_info2 * utf_tbl = NULL; +static int utf_tbl_count = 0; // utf_tbl can be used by multiple Hunspell instances /* only UTF-16 (BMP) implementation */ char * u16_u8(char * dest, int size, const w_char * src, int srclen) { @@ -105,7 +105,7 @@ int u8_u16(w_char * dest, int size, const char * src) { w_char * u2 = dest; w_char * u2_max = u2 + size; - while (*u8 && (u2 < u2_max)) { + while ((u2 < u2_max) && *u8) { switch ((*u8) & 0xf0) { case 0x00: case 0x10: @@ -236,15 +236,19 @@ int flag_bsearch(unsigned short flags[], unsigned short flag, int length) { *stringp = dp+1; int nc = (int)((unsigned long)dp - (unsigned long)mp); rv = (char *) malloc(nc+1); - memcpy(rv,mp,nc); - *(rv+nc) = '\0'; - return rv; + if (rv) { + memcpy(rv,mp,nc); + *(rv+nc) = '\0'; + return rv; + } } else { - rv = (char *) malloc(n+1); - memcpy(rv, mp, n); - *(rv+n) = '\0'; - *stringp = mp + n; - return rv; + rv = (char *) malloc(n+1); + if (rv) { + memcpy(rv, mp, n); + *(rv+n) = '\0'; + *stringp = mp + n; + return rv; + } } } return NULL; @@ -5133,7 +5137,7 @@ int initialize_utf_tbl() { #endif void free_utf_tbl() { - if (utf_tbl_count > 0) utf_tbl--; + if (utf_tbl_count > 0) utf_tbl_count--; if (utf_tbl && (utf_tbl_count == 0)) { free(utf_tbl); utf_tbl = NULL; diff --git a/src/hunspell/dictmgr.cxx b/src/hunspell/dictmgr.cxx index 34736a6..5594582 100644 --- a/src/hunspell/dictmgr.cxx +++ b/src/hunspell/dictmgr.cxx @@ -135,15 +135,19 @@ char * DictMgr::mystrsep(char ** stringp, const char delim) *stringp = dp+1; int nc = (int)((unsigned long)dp - (unsigned long)mp); rv = (char *) malloc(nc+1); - memcpy(rv,mp,nc); - *(rv+nc) = '\0'; - return rv; + if (rv) { + memcpy(rv,mp,nc); + *(rv+nc) = '\0'; + return rv; + } } else { rv = (char *) malloc(n+1); - memcpy(rv, mp, n); - *(rv+n) = '\0'; - *stringp = mp + n; - return rv; + if (rv) { + memcpy(rv, mp, n); + *(rv+n) = '\0'; + *stringp = mp + n; + return rv; + } } } return NULL; diff --git a/src/hunspell/hashmgr.cxx b/src/hunspell/hashmgr.cxx index 5cdb543..90bb5f7 100644 --- a/src/hunspell/hashmgr.cxx +++ b/src/hunspell/hashmgr.cxx @@ -107,6 +107,12 @@ HashMgr::~HashMgr() aliasm = NULL; } +#ifndef OPENOFFICEORG +#ifndef MOZILLA_CLIENT + if (utf8) free_utf_tbl(); +#endif +#endif + if (enc) free(enc); if (lang) free(lang); @@ -173,7 +179,11 @@ desc #endif } else { struct hentry* hp = (struct hentry *) malloc (sizeof(struct hentry)); - if (!hp) return 1; + if (!hp) + { + if (st) free(st); + return 1; + } hp->wlen = (short) wl; hp->alen = (short) al; hp->word = st; @@ -185,7 +195,13 @@ desc hp->description = (desc) ? get_aliasm(atoi(desc)) : mystrdup(desc); } else { hp->description = mystrdup(desc); - if (desc && !hp->description) return 1; + if (desc && !hp->description) + { + free(hp->word); + free(hp->astr); + free(hp); + return 1; + } if (dp->description && complexprefixes) { if (utf8) reverseword_utf(hp->description); else reverseword(hp->description); } @@ -198,6 +214,7 @@ desc if ((dp->astr) && TESTAFF(dp->astr, ONLYUPCASEFLAG, dp->alen)) { free(dp->astr); dp->astr = hp->astr; + dp->alen = hp->alen; free(hp->word); free(hp); return 0; @@ -216,6 +233,7 @@ desc if ((dp->astr) && TESTAFF(dp->astr, ONLYUPCASEFLAG, dp->alen)) { free(dp->astr); dp->astr = hp->astr; + dp->alen = hp->alen; free(hp->word); free(hp); return 0; @@ -259,9 +277,12 @@ int HashMgr::put_word_pattern(const char * word, int wl, const char * pattern) struct hentry * dp = lookup(pattern); if (!dp || !dp->astr) return 1; flags = (unsigned short *) malloc (dp->alen * sizeof(short)); - memcpy((void *) flags, (void *) dp->astr, dp->alen * sizeof(short)); - add_word(word, wl, flags, dp->alen, NULL, false); - return 0; + if (flags) { + memcpy((void *) flags, (void *) dp->astr, dp->alen * sizeof(short)); + add_word(word, wl, flags, dp->alen, NULL, false); + return 0; + } + return 1; } // walk the hash table entry by entry - null at end @@ -391,15 +412,16 @@ int HashMgr::load_tables(const char * tpath) return 5; } - // add decapizatalized forms to handle following cases - // OpenOffice.org -> OPENOFFICE.ORG - // CIA's -> CIA'S + // add inner capitalized forms to handle the following allcap forms: + // Mixed caps: OpenOffice.org -> OPENOFFICE.ORG + // Allcaps with suffixes: CIA's -> CIA'S captype = utf8 ? get_captype_utf8(ts, wl, langnum) : get_captype(ts, wl, csconv); if (((captype == HUHCAP) || (captype == HUHINITCAP) || ((captype == ALLCAP) && (flags != NULL))) && !((flags != NULL) && TESTAFF(flags, forbiddenword, al))) { - unsigned short * flags2 = (unsigned short *) malloc (sizeof(unsigned short *)* (al + 1)); - memcpy(flags2, flags, al * sizeof(unsigned short *)); + unsigned short * flags2 = (unsigned short *) malloc (sizeof(unsigned short) * (al+1)); + if (!flags2) return 6; + if (al) memcpy(flags2, flags, al * sizeof(unsigned short)); flags2[al] = ONLYUPCASEFLAG; if (utf8) { char st[MAXDELEN]; @@ -449,8 +471,9 @@ int HashMgr::decode_flags(unsigned short ** result, char * flags) { case FLAG_LONG: { // two-character flags (1x2yZz -> 1x 2y Zz) len = strlen(flags); if (len%2 == 1) HUNSPELL_WARNING(stderr, "error: length of FLAG_LONG flagvector is odd: %s\n", flags); - len = len/2; + len /= 2; *result = (unsigned short *) malloc(len * sizeof(short)); + if (!*result) return -1; for (int i = 0; i < len; i++) { (*result)[i] = (((unsigned short) flags[i * 2]) << 8) + (unsigned short) flags[i * 2 + 1]; } @@ -465,6 +488,7 @@ int HashMgr::decode_flags(unsigned short ** result, char * flags) { if (*p == ',') len++; } *result = (unsigned short *) malloc(len * sizeof(short)); + if (!*result) return -1; dest = *result; for (p = flags; *p; p++) { if (*p == ',') { @@ -482,6 +506,7 @@ int HashMgr::decode_flags(unsigned short ** result, char * flags) { w_char w[MAXDELEN/2]; len = u8_u16(w, MAXDELEN/2, flags); *result = (unsigned short *) malloc(len * sizeof(short)); + if (!*result) return -1; memcpy(*result, w, len * sizeof(short)); break; } @@ -489,6 +514,7 @@ int HashMgr::decode_flags(unsigned short ** result, char * flags) { unsigned short * dest; len = strlen(flags); *result = (unsigned short *) malloc(len * sizeof(short)); + if (!*result) return -1; dest = *result; for (unsigned char * p = (unsigned char *) flags; *p; p++) { *dest = (unsigned short) *p; diff --git a/src/hunspell/hunspell.cxx b/src/hunspell/hunspell.cxx index 800473e..fb48517 100644 --- a/src/hunspell/hunspell.cxx +++ b/src/hunspell/hunspell.cxx @@ -102,7 +102,7 @@ int Hunspell::cleanword2(char * dest, const char * src, *(dest + nl) = '\0'; nl = strlen(dest); if (utf8) { - *nc = u8_u16(dest_utf, MAXWORDLEN, (const char *) q); + *nc = u8_u16(dest_utf, MAXWORDLEN, dest); // don't check too long words if (*nc >= MAXWORDLEN) return 0; if (*nc == -1) { // big Unicode character (non BMP area) @@ -382,7 +382,8 @@ int Hunspell::spell(const char * word, int * info, char ** root) rv = checkword(wspace, info, root); if (rv) break; } - // spec. prefix handling for Italian, etc. (SANT'ELIA -> Sant'+Elia) + // Spec. prefix handling for Catalan, French, Italian: + // prefixes separated by apostrophe (SANT'ELIA -> Sant'+Elia). if (pAMgr && strchr(cw, '\'')) { wl = mkallsmall2(cw, unicw, nc); char * apostrophe = strchr(cw, '\''); @@ -444,8 +445,10 @@ int Hunspell::spell(const char * word, int * info, char ** root) } if (rv && is_keepcase(rv) && (captype == ALLCAP)) rv = NULL; if (rv) break; + rv = checkword(wspace, info, root); if (abbv && !rv) { + *(wspace+wl) = '.'; *(wspace+wl+1) = '\0'; rv = checkword(wspace, info, root); @@ -471,11 +474,6 @@ int Hunspell::spell(const char * word, int * info, char ** root) } } - // check ONLYUPCASE and return -// if (rv && !((captype==INITCAP) && (rv->astr) && (pAMgr) && -// TESTAFF(rv->astr, ONLYUPCASEFLAG, rv->alen))) { -// return 1; -// } if (rv) return 1; // recursive breaking at break points (not good for morphological analysis) @@ -485,7 +483,8 @@ int Hunspell::spell(const char * word, int * info, char ** root) int corr = 0; // German words beginning with "-" are not accepted if (langnum == LANG_de) corr = 1; - for (int j = 0; j < pAMgr->get_numbreak(); j++) { + int numbreak = pAMgr ? pAMgr->get_numbreak() : 0; + for (int j = 0; j < numbreak; j++) { s=(char *) strstr(cw + corr, wordbreak[j]); if (s) { r = *s; @@ -711,10 +710,13 @@ int Hunspell::suggest(char*** slst, const char * word) get_captype(dot+1, strlen(dot+1), csconv); if (captype_ == INITCAP) { char * st = mystrdup(cw); - st = (char *) realloc(st, wl + 1); - st[(dot - cw) + 1] = ' '; - strcpy(st + (dot - cw) + 2, dot + 1); - ns = insert_sug(slst, st, ns); + st = (char *) realloc(st, wl + 2); + if (st) { + st[(dot - cw) + 1] = ' '; + strcpy(st + (dot - cw) + 2, dot + 1); + ns = insert_sug(slst, st, ns); + free(st); + } } } if (captype == HUHINITCAP) { @@ -861,7 +863,7 @@ int Hunspell::suggest(char*** slst, const char * word) } // remove bad capitalized and forbidden forms - if (pAMgr->get_keepcase() || pAMgr->get_forbiddenword()) { + if (pAMgr && (pAMgr->get_keepcase() || pAMgr->get_forbiddenword())) { switch (captype) { case INITCAP: case ALLCAP: { diff --git a/src/hunspell/hunspell.hxx b/src/hunspell/hunspell.hxx index 9edddd0..6d3f092 100644 --- a/src/hunspell/hunspell.hxx +++ b/src/hunspell/hunspell.hxx @@ -13,15 +13,21 @@ #define MAXSUGGESTION 15 #define MAXSHARPS 5 -#ifdef W32 -#define DLLTEST2_API __declspec(dllexport) -#endif - #ifndef _MYSPELLMGR_HXX_ #define _MYSPELLMGR_HXX_ +#ifdef HUNSPELL_STATIC + #define DLLEXPORT +#else + #ifdef HUNSPELL_EXPORTS + #define DLLEXPORT __declspec( dllexport ) + #else + #define DLLEXPORT __declspec( dllimport ) + #endif +#endif + #ifdef W32 -class DLLTEST2_API Hunspell +class DLLEXPORT Hunspell #else class Hunspell #endif diff --git a/src/hunspell/suggestmgr.cxx b/src/hunspell/suggestmgr.cxx index d972d79..bc908d7 100644 --- a/src/hunspell/suggestmgr.cxx +++ b/src/hunspell/suggestmgr.cxx @@ -56,7 +56,7 @@ SuggestMgr::SuggestMgr(const char * tryme, int maxn, w_char t[MAXSWL]; ctryl = u8_u16(t, MAXSWL, tryme); ctry_utf = (w_char *) malloc(ctryl * sizeof(w_char)); - memcpy(ctry_utf, t, ctryl * sizeof(w_char)); + if (ctry_utf) memcpy(ctry_utf, t, ctryl * sizeof(w_char)); } else { ctry = mystrdup(tryme); ctryl = strlen(ctry); @@ -766,6 +766,7 @@ int SuggestMgr::longswapchar_utf(char ** wlst, const w_char * word, int wl, int tmpc = *p; *p = *q; *q = tmpc; + u16_u8(candidate, MAXSWUTF8L, candidate_utf, wl); ns = testsug(wlst, candidate, strlen(candidate), ns, cpdsuggest, NULL, NULL); if (ns == -1) return -1; *q = *p; @@ -1413,6 +1414,7 @@ char * SuggestMgr::suggest_morph_for_spelling_error(const char * word) { char * p = NULL; char ** wlst = (char **) calloc(maxSug, sizeof(char *)); + if (!**wlst) return NULL; // we will use only the first suggestion for (int i = 0; i < maxSug - 1; i++) wlst[i] = ""; int ns = suggest(&wlst, word, maxSug - 1); @@ -1421,7 +1423,7 @@ char * SuggestMgr::suggest_morph_for_spelling_error(const char * word) free(wlst[maxSug - 1]); } if (wlst) free(wlst); - return p; + return p; } #endif // END OF HUNSPELL_EXPERIMENTAL CODE @@ -1614,6 +1616,12 @@ void SuggestMgr::lcs(const char * s, const char * s2, int * l1, int * l2, char * } c = (char *) malloc((m + 1) * (n + 1)); b = (char *) malloc((m + 1) * (n + 1)); + if (!c || !b) { + if (c) free(c); + if (b) free(b); + *result = NULL; + return; + } for (i = 1; i <= m; i++) c[i*(n+1)] = 0; for (j = 0; j <= n; j++) c[j] = 0; for (i = 1; i <= m; i++) { @@ -1645,6 +1653,7 @@ int SuggestMgr::lcslen(const char * s, const char* s2) { char * result; int len = 0; lcs(s, s2, &m, &n, &result); + if (!result) return 0; i = m; j = n; while ((i != 0) && (j != 0)) { @@ -1656,6 +1665,6 @@ int SuggestMgr::lcslen(const char * s, const char* s2) { i--; } else j--; } - if (result) free(result); + free(result); return len; } diff --git a/src/tools/hunspell.cxx b/src/tools/hunspell.cxx index d8917e1..be1f3f9 100644 --- a/src/tools/hunspell.cxx +++ b/src/tools/hunspell.cxx @@ -168,7 +168,7 @@ char * chenc(char * st, const char * enc1, const char * enc2) { char * source = st; char * dest = text_conv; iconv_t conv = iconv_open(enc2, enc1); - size_t res = iconv(conv, &source, &c1, &dest, &c2); + size_t res = iconv(conv, (ICONV_CONST char **) &source, &c1, &dest, &c2); iconv_close(conv); if (res != (size_t) -1) out = text_conv; } @@ -180,8 +180,8 @@ TextParser * get_parser(int format, char * extension, Hunspell * pMS) { TextParser * p = NULL; int io_utf8 = 0; dic_enc = pMS->get_dic_encoding(); - initialize_utf_tbl(); // also need for 8-bit tokenization #ifdef HAVE_ICONV + initialize_utf_tbl(); // also need for 8-bit tokenization if (io_enc) { if ((strcmp(io_enc, "UTF-8") == 0) || (strcmp(io_enc, "utf-8") == 0) || @@ -207,7 +207,7 @@ TextParser * get_parser(int format, char * extension, Hunspell * pMS) { size_t c2 = MAXLNLEN; char * dest = text_conv; iconv_t conv = iconv_open("UTF-8", dic_enc); - iconv(conv, &wchars, &c1, &dest, &c2); + iconv(conv, (ICONV_CONST char **) &wchars, &c1, &dest, &c2); iconv_close(conv); wordchars_utf16 = (unsigned short *) malloc(sizeof(unsigned short) * wlen); int n = u8_u16((w_char *) wordchars_utf16, wlen, text_conv); @@ -220,19 +220,22 @@ TextParser * get_parser(int format, char * extension, Hunspell * pMS) { char letters[MAXLNLEN]; char * pletters = letters; char ch[2]; - ch[1] = '\0'; char u8[10]; iconv_t conv = iconv_open("UTF-8", io_enc); for (int i = 32; i < 256; i++) { size_t c1 = 1; size_t c2 = 10; char * dest = u8; + u8[0] = '\0'; char * ch8bit = ch; ch[0] = (char) i; - size_t res = iconv(conv, &ch8bit, &c1, &dest, &c2); + ch[1] = '\0'; + size_t res = iconv(conv, (ICONV_CONST char **) &ch8bit, &c1, &dest, &c2); if (res != (size_t) -1) { unsigned short idx; w_char w; + w.l = 0; + w.h = 0; u8_u16(&w, 1, u8); idx = (w.h << 8) + w.l; if (unicodeisalpha(idx)) { @@ -257,7 +260,7 @@ TextParser * get_parser(int format, char * extension, Hunspell * pMS) { size_t c1 = len + 1; size_t c2 = len + 1; iconv_t conv = iconv_open(io_enc, dic_enc); - iconv(conv, &wchars, &c1, &dest, &c2); + iconv(conv, (ICONV_CONST char **) &wchars, &c1, &dest, &c2); iconv_close(conv); } @@ -1183,9 +1186,10 @@ char * add(char * dest, char * st) { char * exist2(char * dir, int len, char * name, char * ext) { char buf[MAXLNLEN]; + const char * sep = (len == 0) ? "": DIRSEP; strncpy(buf, dir, len); - strcpy(buf + len, DIRSEP); - strcpy(buf + len + 1, name); + strcpy(buf + len, sep); + strcat(buf, name); strcat(buf, ext); if (exist(buf)) return mystrdup(buf); return NULL; @@ -1352,8 +1356,8 @@ int main(int argc, char** argv) dicname = mystrdup(dicname); } } - path = add(mystrdup("."), PATHSEP); // <- check path in local directory + path = add(path, PATHSEP); // <- check path in root directory if (getenv("DICPATH")) path = add(add(path, getenv("DICPATH")), PATHSEP); path = add(add(path, LIBDIR), PATHSEP); path = add(add(add(add(path, HOME), DIRSEP), USEROOODIR), PATHSEP); @@ -1441,7 +1445,9 @@ int main(int argc, char** argv) if (aff) free(aff); if (dic) free(dic); if (wordchars) free(wordchars); - delete pMS; // not need, because time-consuming +#ifdef HAVE_ICONV free_utf_tbl(); +#endif + delete pMS; // not need, because time-consuming return 0; } diff --git a/src/win_api/hunspelldll.c b/src/win_api/hunspelldll.c index f3e275e..583d96e 100644 --- a/src/win_api/hunspelldll.c +++ b/src/win_api/hunspelldll.c @@ -33,14 +33,14 @@ * ***** END LICENSE BLOCK ***** **/ #include "hunspelldll.h" #include <windows.h> + +#ifdef BORLAND #include <stdio.h> #include <stdlib.h> - #include <cstring> #include <cstdlib> #include <cstdio> - -#include "hunspell.hxx" +#endif DLLEXPORT void * hunspell_initialize(char *aff_file, char *dict_file) { @@ -63,10 +63,12 @@ DLLEXPORT int hunspell_suggest(Hunspell *pMS, char *word, char ***slst) return pMS->suggest(slst, word); } +#ifdef HUNSPELL_EXPERIMENTAL DLLEXPORT int hunspell_suggest_auto(Hunspell *pMS, char *word, char ***slst) { return pMS->suggest_auto(slst, word); } +#endif DLLEXPORT void hunspell_suggest_free(Hunspell *pMS, char **slst, int len) { diff --git a/src/win_api/hunspelldll.h b/src/win_api/hunspelldll.h index c5962f0..f67ea4f 100644 --- a/src/win_api/hunspelldll.h +++ b/src/win_api/hunspelldll.h @@ -36,7 +36,15 @@ #ifndef _DLL_H_ #define _DLL_H_ -# define DLLEXPORT __declspec (dllexport) +#ifdef HUNSPELL_STATIC + #define DLLEXPORT +#else + #ifdef HUNSPELL_EXPORTS + #define DLLEXPORT __declspec( dllexport ) + #else + #define DLLEXPORT __declspec( dllimport ) + #endif +#endif #ifdef __cplusplus extern "C" { diff --git a/tests/Makefile.am b/tests/Makefile.am index 9d4aaec..8e9e524 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -5,6 +5,7 @@ XFAIL_TESTS = @XFAILED@ TESTS = \ affixes.test \ base.test \ +base_utf.test \ allcaps.test \ allcaps_utf.test \ allcaps2.test \ @@ -95,6 +96,12 @@ base.good \ base.sug \ base.test \ base.wrong \ +base_utf.aff \ +base_utf.dic \ +base_utf.good \ +base_utf.sug \ +base_utf.test \ +base_utf.wrong \ allcaps.aff \ allcaps.dic \ allcaps.good \ diff --git a/tests/Makefile.in b/tests/Makefile.in index c270017..955712a 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -187,6 +187,7 @@ XFAIL_TESTS = @XFAILED@ TESTS = \ affixes.test \ base.test \ +base_utf.test \ allcaps.test \ allcaps_utf.test \ allcaps2.test \ @@ -273,6 +274,12 @@ base.good \ base.sug \ base.test \ base.wrong \ +base_utf.aff \ +base_utf.dic \ +base_utf.good \ +base_utf.sug \ +base_utf.test \ +base_utf.wrong \ allcaps.aff \ allcaps.dic \ allcaps.good \ diff --git a/tests/base.aff b/tests/base.aff index f0c4dd0..70e292d 100644 --- a/tests/base.aff +++ b/tests/base.aff @@ -3,7 +3,7 @@ SET ISO8859-1 TRY esianrtolcdugmphbyfvkwzESIANRTOLCDUGMPHBYFVKWZ' -WORDCHARS ' +WORDCHARS .' PFX A Y 1 PFX A 0 re . diff --git a/tests/base.dic b/tests/base.dic index 9d78959..5d9b8a2 100644 --- a/tests/base.dic +++ b/tests/base.dic @@ -1,4 +1,4 @@ -27 +28 created/U create/XKVNGADS imply/GNSDX @@ -26,3 +26,4 @@ horrifying speech suggest uncreate/V +Hunspell diff --git a/tests/base.good b/tests/base.good index cf2d6cf..8e7f88e 100644 --- a/tests/base.good +++ b/tests/base.good @@ -19,4 +19,9 @@ etc. etc HELLO lip. -text. \ No newline at end of file +text. +NASA. +Text. +TEXT. +Hunspell. +HUNSPELL. diff --git a/tests/base.sug b/tests/base.sug index a4a8186..4ba0b1a 100644 --- a/tests/base.sug +++ b/tests/base.sug @@ -4,6 +4,7 @@ hello said rotten day tomorrow +seven NASA horrifying speech diff --git a/tests/base.wrong b/tests/base.wrong index 667a895..88a6e25 100644 --- a/tests/base.wrong +++ b/tests/base.wrong @@ -4,7 +4,7 @@ hlelo seid rottenday tomorow -sezzven +seeeven Nasa horrorfying peech diff --git a/tests/base.aff b/tests/base_utf.aff similarity index 98% copy from tests/base.aff copy to tests/base_utf.aff index f0c4dd0..93f90c2 100644 --- a/tests/base.aff +++ b/tests/base_utf.aff @@ -1,9 +1,10 @@ # OpenOffice.org's en_US.aff file -SET ISO8859-1 +SET UTF-8 TRY esianrtolcdugmphbyfvkwzESIANRTOLCDUGMPHBYFVKWZ' -WORDCHARS ' +MAXNGRAMSUGS 1 +WORDCHARS .' PFX A Y 1 PFX A 0 re . diff --git a/tests/base.dic b/tests/base_utf.dic similarity index 94% copy from tests/base.dic copy to tests/base_utf.dic index 9d78959..5d9b8a2 100644 --- a/tests/base.dic +++ b/tests/base_utf.dic @@ -1,4 +1,4 @@ -27 +28 created/U create/XKVNGADS imply/GNSDX @@ -26,3 +26,4 @@ horrifying speech suggest uncreate/V +Hunspell diff --git a/tests/base.good b/tests/base_utf.good similarity index 76% copy from tests/base.good copy to tests/base_utf.good index cf2d6cf..8e7f88e 100644 --- a/tests/base.good +++ b/tests/base_utf.good @@ -19,4 +19,9 @@ etc. etc HELLO lip. -text. \ No newline at end of file +text. +NASA. +Text. +TEXT. +Hunspell. +HUNSPELL. diff --git a/tests/base.sug b/tests/base_utf.sug similarity index 92% copy from tests/base.sug copy to tests/base_utf.sug index a4a8186..4ba0b1a 100644 --- a/tests/base.sug +++ b/tests/base_utf.sug @@ -4,6 +4,7 @@ hello said rotten day tomorrow +seven NASA horrifying speech diff --git a/tests/base_utf.test b/tests/base_utf.test new file mode 100755 index 0000000..7f44369 --- /dev/null +++ b/tests/base_utf.test @@ -0,0 +1,4 @@ +#!/bin/sh +DIR="`dirname $0`" +NAME="`basename $0 .test`" +$DIR/test.sh $NAME diff --git a/tests/base.wrong b/tests/base_utf.wrong similarity index 90% copy from tests/base.wrong copy to tests/base_utf.wrong index 667a895..88a6e25 100644 --- a/tests/base.wrong +++ b/tests/base_utf.wrong @@ -4,7 +4,7 @@ hlelo seid rottenday tomorow -sezzven +seeeven Nasa horrorfying peech diff --git a/tests/test.sh b/tests/test.sh index 62873e9..90080f6 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -41,8 +41,8 @@ if [ "$VALGRIND" != "" ]; then if [ ! -d $TEMPDIR/badlogs ]; then mkdir $TEMPDIR/badlogs fi - alias hunspell='valgrind --tool=$VALGRIND --leak-check=yes --show-reachable=yes --log-file=$TEMPDIR/test ../src/tools/.libs/lt-hunspell' - alias hunmorph='valgrind --tool=$VALGRIND --leak-check=yes --show-reachable=yes --log-file=$TEMPDIR/test ../src/tools/.libs/lt-hunmorph' + alias hunspell='valgrind --tool=$VALGRIND --leak-check=yes --show-reachable=yes --log-file=$TEMPDIR/test.pid ../src/tools/.libs/lt-hunspell' + alias hunmorph='valgrind --tool=$VALGRIND --leak-check=yes --show-reachable=yes --log-file=$TEMPDIR/test.pid ../src/tools/.libs/lt-hunmorph' fi # Tests good words -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-openoffice/hunspell.git

