summaryrefslogtreecommitdiffabout
path: root/src/ellinika
authorSergey Poznyakoff <gray@gnu.org.ua>2011-06-05 10:56:34 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2011-06-05 10:56:34 (GMT)
commitdaca71a486490125471d0fb8d596d004485179bf (patch) (side-by-side diff)
treed31ef54152a5ae3a20e53ff4c5a505ce4f7612fa /src/ellinika
parent618724bfda07dfb1f8b61212da8f43e2eace95ba (diff)
downloadellinika-daca71a486490125471d0fb8d596d004485179bf.tar.gz
ellinika-daca71a486490125471d0fb8d596d004485179bf.tar.bz2
Fix memory corruption, improve conjugator
* data/db.struct: Revamp conjugation support tables. * scm/conjugator.scm: Improve irregular conjugation support. * src/ellinika/elmorph.c (_elstr_syllabize): Use calloc. Fix memory corruption. (_elstr_dup): Don't allocate new sylmap if the source one is NULL. (_elstr_free): Call scm_gc_free on elstr.
Diffstat (limited to 'src/ellinika') (more/less context) (ignore whitespace changes)
-rw-r--r--src/ellinika/elmorph.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/src/ellinika/elmorph.c b/src/ellinika/elmorph.c
index 75e42f9..faeeb49 100644
--- a/src/ellinika/elmorph.c
+++ b/src/ellinika/elmorph.c
@@ -42,3 +42,4 @@ _elstr_syllabize(struct elstr *elstr)
unsigned *sylmap;
- unsigned i, nsyl = 0, accsyl = 0, accchr = 0;
+ unsigned i, nsyl = 0, accchr = 0;
+ int accsyl = -1;
int dstate = 0;
@@ -46,5 +47,7 @@ _elstr_syllabize(struct elstr *elstr)
- if (!elstr->sylmap)
- elstr->sylmap = scm_gc_malloc(sizeof(sylmap[0])*elstr->len,
- "syllable map");
+ if (!elstr->sylmap) {
+ elstr->sylmap = calloc(elstr->len, sizeof(sylmap[0]));
+ if (!elstr->sylmap)
+ scm_memory_error("_elstr_syllabize");
+ }
sylmap = elstr->sylmap;
@@ -69,3 +72,3 @@ _elstr_syllabize(struct elstr *elstr)
sylmap[nsyl++] = i - 1;
- else
+ else if (nsyl)
sylmap[nsyl-1] = i - 1;
@@ -73,3 +76,3 @@ _elstr_syllabize(struct elstr *elstr)
elstr->acc_pos = accchr;
- elstr->acc_syl = nsyl - accsyl;
+ elstr->acc_syl = (accsyl >= 0) ? nsyl - accsyl : 0;
}
@@ -116,7 +119,10 @@ _elstr_dup(struct elstr *elstr)
scm_memory_error("_elstr_dup");
- elnew->sylmap = calloc(elstr->nsyl, sizeof(elnew->sylmap[0]));
- if (!elnew->sylmap) {
- free(elnew->str);
- scm_memory_error("_elstr_dup");
- }
+ if (elstr->sylmap) {
+ elnew->sylmap = calloc(elstr->nsyl, sizeof(elnew->sylmap[0]));
+ if (!elnew->sylmap) {
+ free(elnew->str);
+ scm_memory_error("_elstr_dup");
+ }
+ } else
+ elnew->sylmap = NULL;
memcpy(elnew->str, elstr->str, sizeof(elstr->str[0]) * elstr->len);
@@ -153,3 +159,3 @@ _elstr_free(SCM smob)
free(elstr->sylmap);
- free(elstr);
+ scm_gc_free(elstr, sizeof(struct elstr), "elstr");
return 0;

Return to:

Send suggestions and report system problems to the System administrator.