From c36a503c272f243a34a9d6aa6578acce36d0b94a Mon Sep 17 00:00:00 2001 From: vdvo Date: Mon, 27 May 2002 15:07:32 +0000 Subject: [PATCH] Fixed "String Table Error" occurences in some (not all) empty cells --- xlhtml/ChangeLog | 1 + xlhtml/xlhtml.c | 48 ++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/xlhtml/ChangeLog b/xlhtml/ChangeLog index 8fd04f6..cdef68f 100644 --- a/xlhtml/ChangeLog +++ b/xlhtml/ChangeLog @@ -18,6 +18,7 @@ HEAD * Enabled compilation warnings, made sure there are none * More code modularization * Fixed handling of fonts (fixes some segfaults, closes bug 529044) + * Fixed "String Table Error" occurences in some (not all) empty cells * Added some Alpha portability fixes. 0.5 04/13/02 diff --git a/xlhtml/xlhtml.c b/xlhtml/xlhtml.c index a37af5c..175c9f0 100644 --- a/xlhtml/xlhtml.c +++ b/xlhtml/xlhtml.c @@ -1134,10 +1134,17 @@ void main_line_processor(U16 opcode, U16 version, U32 count, U16 last, U8 data) r, c, f, opcode, str_array[i]->uni, str_array[i]->str, str_array[i]->len, str_array[i]->crun_cnt, str_array[i]->fmt_run); + else /* Error - probably OOM in add_str_array() */ + add_wb_array( r, c, f, opcode, + (U16)0, (U8 *)"String Table Error", 18, 0, 0); } - else /* Error, so just set it empty */ + else + { /* the string table entry can legally + * be NULL, see start of add_str_array() + */ add_wb_array( r, c, f, opcode, - (U16)0, (U8 *)"String Table Error", 18, 0, 0); + (U16)0, (U8 *)"", 0, 0, 0); + } } else MaxStringsExceeded = 1; @@ -2196,8 +2203,18 @@ void add_str_array(U8 uni, U8 *str, U16 len, U8 *fmt_run, U8 crun_cnt) if (next_string >= max_strings) { uni_string **tstr_array; - size_t new_size = (max_strings + STRINGS_INCR) * sizeof(uni_string *); + unsigned long new_max_str; + size_t new_size; + new_max_str = max_strings + STRINGS_INCR; + while (next_string >= new_max_str) + { /* who knows how many empty strings (see above) we got in a row + * - better make sure there's enough space allocated + */ + new_max_str += STRINGS_INCR; + } + + new_size = new_max_str * sizeof(uni_string *); tstr_array = (uni_string **)realloc(str_array, new_size); if (tstr_array == NULL) @@ -2214,15 +2231,15 @@ void add_str_array(U8 uni, U8 *str, U16 len, U8 *fmt_run, U8 crun_cnt) str_array = tstr_array; /* Clear the new string slots */ - for (i=max_strings; i<(max_strings + STRINGS_INCR); i++) + for (i = max_strings; i < new_max_str; i++) str_array[i] = 0; - - max_strings += STRINGS_INCR; + + max_strings = new_max_str; } } - + if (str_array[next_string] == 0) - { + { /* Can this ever be false? If yes, wouldn't that be a bug? -- VDv */ str_array[next_string] = (uni_string *)malloc(sizeof(uni_string)); if (str_array[next_string]) { @@ -2244,7 +2261,10 @@ void add_str_array(U8 uni, U8 *str, U16 len, U8 *fmt_run, U8 crun_cnt) str_array[next_string]->crun_cnt = crun_cnt; } else + { str_array[next_string]->crun_cnt = 0; + MaxStringsExceeded = 1; + } } else { @@ -2252,6 +2272,18 @@ void add_str_array(U8 uni, U8 *str, U16 len, U8 *fmt_run, U8 crun_cnt) str_array[next_string]->crun_cnt = 0; } } + else + { + MaxStringsExceeded = 1; +/* fprintf(stderr, "%s: cannot allocate %d bytes for string storage %d: %s", + PRGNAME, len+1, errno, strerror(errno)); */ + } + } + else + { + MaxStringsExceeded = 1; +/* fprintf(stderr, "%s: cannot allocate %d bytes for string storage %d: %s", + PRGNAME, sizeof(uni_string), errno, strerror(errno)); */ } } next_string++;