diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2016-10-29 17:57:16 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2016-10-29 17:58:20 +0300 |
commit | 64d80b6254d38de81e3b087ae28f354f77ca3e30 (patch) | |
tree | c79fd994d709e561f4245f2ee252083103211424 | |
parent | e4fa1add62d698ef5ae33ac09b61581e9d044c47 (diff) | |
download | dico-64d80b6254d38de81e3b087ae28f354f77ca3e30.tar.gz dico-64d80b6254d38de81e3b087ae28f354f77ca3e30.tar.bz2 |
Fix coredump in gcide.
The coredump occurred when the requested headword matched the
entry at the start of the index page.
* modules/gcide/idx.c (gcide_idx_locate): Fix improper dereference.
* modules/gcide/tests/Makefile.am: Add def06.at
* modules/gcide/tests/testsuite.at: Include def06.at
-rw-r--r-- | modules/gcide/idx.c | 9 | ||||
-rw-r--r-- | modules/gcide/tests/Makefile.am | 1 | ||||
-rw-r--r-- | modules/gcide/tests/def06.at | 36 | ||||
-rw-r--r-- | modules/gcide/tests/testsuite.at | 1 |
4 files changed, 44 insertions, 3 deletions
diff --git a/modules/gcide/idx.c b/modules/gcide/idx.c index 5fc0787..bb496b2 100644 --- a/modules/gcide/idx.c +++ b/modules/gcide/idx.c @@ -392,9 +392,12 @@ gcide_idx_locate(struct gcide_idx_file *file, char *headword, size_t hwlen) return NULL; for (;;) { - if (_compare(file, headword, &page->ipg_ref[refno-1], hwlen) > 0) - break; - if (--refno==0) { + if (refno > 0) { + if (_compare(file, headword, &page->ipg_ref[refno-1], hwlen) > 0) + break; + --refno; + } + if (refno == 0) { if (pageno == 0) break; page = _idx_get_page(file, --pageno); diff --git a/modules/gcide/tests/Makefile.am b/modules/gcide/tests/Makefile.am index d792157..2047088 100644 --- a/modules/gcide/tests/Makefile.am +++ b/modules/gcide/tests/Makefile.am @@ -71,6 +71,7 @@ TESTSUITE_AT = \ def03.at\ def04.at\ def05.at\ + def06.at\ descr.at\ exact.at\ greek.at\ diff --git a/modules/gcide/tests/def06.at b/modules/gcide/tests/def06.at new file mode 100644 index 0000000..0372bfd --- /dev/null +++ b/modules/gcide/tests/def06.at @@ -0,0 +1,36 @@ +# This file is part of GNU Dico -*- Autotest -*- +# Copyright (C) 2012-2016 Sergey Poznyakoff +# +# GNU Dico is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Dico is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Dico. If not, see <http://www.gnu.org/licenses/>. + +AT_SETUP([first entry in page]) +AT_KEYWORDS([define def06]) +AT_DICOD([define gcide aardvark +quit +], +[[220 +150 1 definitions found: list follows +151 "aardvark" gcide "A mock GCIDE dictionary for GNU Dico test suite" +aardvark (ärdvärk), n. [D., earth-pig.] (Zoöl.) Aardvark is an animal. + +[Dico testsuite] + + +. +250 +221 +]]) +AT_CLEANUP + + diff --git a/modules/gcide/tests/testsuite.at b/modules/gcide/tests/testsuite.at index caf18be..2ca04f9 100644 --- a/modules/gcide/tests/testsuite.at +++ b/modules/gcide/tests/testsuite.at @@ -49,5 +49,6 @@ m4_include(def01.at) m4_include(def02.at) m4_include(def04.at) m4_include(def05.at) +m4_include(def06.at) m4_popdef([AT_DICOD]) |