summaryrefslogtreecommitdiffabout
path: root/src/ellinika
Side-by-side diff
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
@@ -40,13 +40,16 @@ static void
_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;
int acc = 0;
- 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;
for (i = 0; i < elstr->len; i++) {
@@ -67,11 +70,11 @@ _elstr_syllabize(struct elstr *elstr)
}
if (dstate)
sylmap[nsyl++] = i - 1;
- else
+ else if (nsyl)
sylmap[nsyl-1] = i - 1;
elstr->nsyl = nsyl;
elstr->acc_pos = accchr;
- elstr->acc_syl = nsyl - accsyl;
+ elstr->acc_syl = (accsyl >= 0) ? nsyl - accsyl : 0;
}
static SCM
@@ -114,11 +117,14 @@ _elstr_dup(struct elstr *elstr)
elnew->str = calloc(elstr->len, sizeof(elnew->str[0]));
if (!elnew->str)
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);
elnew->len = elstr->len;
elnew->nsyl = elstr->nsyl;
@@ -151,7 +157,7 @@ _elstr_free(SCM smob)
struct elstr *elstr = (struct elstr *) SCM_CDR(smob);
free(elstr->str);
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.