fixed a bug with string-initializers

This commit is contained in:
ceriel 1988-01-25 16:14:01 +00:00
parent a7cdd16125
commit b19a178e2e

View file

@ -544,29 +544,26 @@ ch_array(tpp, ex)
register struct type *tp = *tpp; register struct type *tp = *tpp;
register arith length = ex->SG_LEN; register arith length = ex->SG_LEN;
char *s; char *s;
arith ntopad;
ASSERT(ex->ex_class == String); ASSERT(ex->ex_class == String);
if (tp->tp_size == (arith)-1) { if (tp->tp_size == (arith)-1) {
/* set the dimension */ /* set the dimension */
tp = *tpp = construct_type(ARRAY, tp->tp_up, length); tp = *tpp = construct_type(ARRAY, tp->tp_up, length);
ntopad = align(tp->tp_size, (int) word_size) - tp->tp_size;
} }
else { else {
arith dim = tp->tp_size / tp->tp_up->tp_size; arith dim = tp->tp_size / tp->tp_up->tp_size;
if (length > dim) { if (length > dim) {
expr_warning(ex, "too many initialisers"); expr_warning(ex, "too many initialisers");
length = dim;
} }
ntopad = align(dim,(int) word_size) - length; length = dim;
} }
/* throw out the characters of the already prepared string */ /* throw out the characters of the already prepared string */
s = Malloc((unsigned) (length + ntopad)); s = Malloc((unsigned) (length));
clear(s, (int) (length + ntopad)); clear(s, (int) (length));
strncpy(s, ex->SG_VALUE, (int) length); strncpy(s, ex->SG_VALUE, (int) length);
free(ex->SG_VALUE); free(ex->SG_VALUE);
str_cst(s, (int) (length + ntopad)); str_cst(s, (int) (length));
free(s); free(s);
} }