--- psiconv/trunk/lib/psiconv/parse_texted.c 2000/12/13 16:30:21 63 +++ psiconv/trunk/lib/psiconv/parse_texted.c 2000/12/15 00:21:51 64 @@ -38,59 +38,73 @@ int leng; psiconv_progress(lev+1,off,"Going to read a texted section"); - (*result) = malloc(sizeof(**result)); + if (!((*result) = malloc(sizeof(**result)))) + goto ERROR1; psiconv_progress(lev+2,off+len,"Going to read section id"); - temp = psiconv_read_u32(buf,lev+2,off+len); + temp = psiconv_read_u32(buf,lev+2,off+len,&res); + if (res) + goto ERROR2; if (temp != PSICONV_ID_TEXTED_BODY) { psiconv_warn(lev+2,off+len, "Page header section body id not found"); psiconv_debug(lev+2,off+len, "Page body id: read %08x, expected %08x",temp, PSICONV_ID_TEXTED); - res = -1; + res = -PSICONV_E_PARSE; + goto ERROR2; } len += 4; psiconv_progress(lev+2,off+len,"Going to read the section jumptable"); - while (temp = psiconv_read_u32(buf,lev+3,off+len), - temp != PSICONV_ID_TEXTED_TEXT) { + while (temp = psiconv_read_u32(buf,lev+3,off+len,&res), + !res && temp != PSICONV_ID_TEXTED_TEXT) { len += 4; if (temp == PSICONV_ID_TEXTED_LAYOUT) { - layout_sec = psiconv_read_u32(buf,lev+3,off+len); + layout_sec = psiconv_read_u32(buf,lev+3,off+len,&res); + if (res) + goto ERROR2; psiconv_debug(lev+3,off+len,"Found Layout section at %08x",layout_sec); } else if (temp == PSICONV_ID_TEXTED_REPLACEMENT) { - replacement_sec = psiconv_read_u32(buf,lev+3,off+len); + replacement_sec = psiconv_read_u32(buf,lev+3,off+len,&res); + if (res) + goto ERROR2; psiconv_debug(lev+3,off+len,"Found Replacement section at %08x", replacement_sec); } else if (temp == PSICONV_ID_TEXTED_UNKNOWN) { - unknown_sec= psiconv_read_u32(buf,lev+3,off+len); + unknown_sec= psiconv_read_u32(buf,lev+3,off+len,&res); + if (res) + goto ERROR2; if (unknown_sec) { psiconv_warn(lev+3,off+len, - "Unknown section in TextEd jumptable has real offset"); - res = -1; + "Unknown section in TextEd jumptable has real offset (ignoring)"); } psiconv_debug(lev+3,off+len,"Found Unknown section at %08x", unknown_sec); } else { - psiconv_warn(lev+3,off+len,"Unknown section in TextEd jumptable"); + psiconv_warn(lev+3,off+len, + "Unknown section in TextEd jumptable (ignoring)"); psiconv_debug(lev+3,off+len,"Section ID %08x at offset %08x",temp, - psiconv_read_u32(buf,lev+3,off+len)); - res = -1; + psiconv_read_u32(buf,lev+3,off+len,NULL)); } len += 4; } + if (res) + goto ERROR2; len += 4; psiconv_progress(lev+2,off+len,"Going to read the text"); - psiconv_parse_text_section(buf,lev+2,off+len,&leng,&(*result)->paragraphs); + if ((res = psiconv_parse_text_section(buf,lev+2,off+len,&leng, + &(*result)->paragraphs))) + goto ERROR2; len += leng; if (layout_sec) { psiconv_progress(lev+2,off+len,"Going to read the layout"); - psiconv_parse_styleless_layout_section(buf,lev+2,layout_sec,NULL, + if ((res = psiconv_parse_styleless_layout_section(buf,lev+2,layout_sec,NULL, (*result)->paragraphs, - base_char,base_para); + base_char,base_para))) + goto ERROR3; } #if 0 @@ -106,7 +120,20 @@ psiconv_progress(lev+1,off+len-1,"End of TextEd section " "(total length: %08x", len); - return res; + return 0; + +ERROR3: + psiconv_free_text_and_layout((*result)->paragraphs); +ERROR2: + free (*result); +ERROR1: + psiconv_warn(lev+1,off,"Reading of TextEd Section failed"); + if (length) + *length = 0; + if (!res) + return -PSICONV_E_NOMEM; + else + return res; }