diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2016-12-28 13:19:47 +0100 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2017-01-09 13:21:40 +0100 |
commit | bbcc85a9f746c161b2e23c6057e69ec7b967252b (patch) | |
tree | 8ead60bd762cc0cbf945c002c769e74699594c0b /source/html | |
parent | e9667e7f8ab7c154d8932916a22c33cf2bad0445 (diff) | |
download | mupdf-bbcc85a9f746c161b2e23c6057e69ec7b967252b.tar.xz |
Add fz_terminate_buffer function.
Non-destructively zero terminate a fz_buffer for use as a C string.
Diffstat (limited to 'source/html')
-rw-r--r-- | source/html/epub-doc.c | 7 | ||||
-rw-r--r-- | source/html/html-doc.c | 8 | ||||
-rw-r--r-- | source/html/html-layout.c | 7 |
3 files changed, 6 insertions, 16 deletions
diff --git a/source/html/epub-doc.c b/source/html/epub-doc.c index 590004f6..cf7f1ecf 100644 --- a/source/html/epub-doc.c +++ b/source/html/epub-doc.c @@ -256,7 +256,6 @@ epub_parse_chapter(fz_context *ctx, epub_document *doc, const char *path) fz_dirname(base_uri, path, sizeof base_uri); buf = fz_read_archive_entry(ctx, zip, path); - fz_write_buffer_byte(ctx, buf, 0); ch = fz_malloc_struct(ctx, epub_chapter); ch->path = fz_strdup(ctx, path); @@ -316,7 +315,7 @@ epub_parse_ncx(fz_context *ctx, epub_document *doc, const char *path) fz_dirname(base_uri, path, sizeof base_uri); buf = fz_read_archive_entry(ctx, zip, path); - fz_write_buffer_byte(ctx, buf, 0); + fz_terminate_buffer(ctx, buf); len = fz_buffer_storage(ctx, buf, &data); ncx = fz_parse_xml(ctx, data, len, 0); fz_drop_buffer(ctx, buf); @@ -359,7 +358,7 @@ epub_parse_header(fz_context *ctx, epub_document *doc) /* parse META-INF/container.xml to find OPF */ buf = fz_read_archive_entry(ctx, zip, "META-INF/container.xml"); - fz_write_buffer_byte(ctx, buf, 0); + fz_terminate_buffer(ctx, buf); len = fz_buffer_storage(ctx, buf, &data); container_xml = fz_parse_xml(ctx, data, len, 0); fz_drop_buffer(ctx, buf); @@ -376,7 +375,7 @@ epub_parse_header(fz_context *ctx, epub_document *doc) /* parse OPF to find NCX and spine */ buf = fz_read_archive_entry(ctx, zip, full_path); - fz_write_buffer_byte(ctx, buf, 0); + fz_terminate_buffer(ctx, buf); len = fz_buffer_storage(ctx, buf, &data); content_opf = fz_parse_xml(ctx, data, len, 0); fz_drop_buffer(ctx, buf); diff --git a/source/html/html-doc.c b/source/html/html-doc.c index 05a86d83..c19d5049 100644 --- a/source/html/html-doc.c +++ b/source/html/html-doc.c @@ -139,12 +139,8 @@ htdoc_open_document_with_stream(fz_context *ctx, fz_stream *file) doc->set = fz_new_html_font_set(ctx); buf = fz_read_all(ctx, file, 0); - fz_try(ctx) - { - fz_write_buffer_byte(ctx, buf, 0); doc->html = fz_parse_html(ctx, doc->set, doc->zip, ".", buf, fz_user_css(ctx)); - } fz_always(ctx) fz_drop_buffer(ctx, buf); fz_catch(ctx) @@ -175,12 +171,8 @@ htdoc_open_document(fz_context *ctx, const char *filename) doc->set = fz_new_html_font_set(ctx); buf = fz_read_file(ctx, filename); - fz_try(ctx) - { - fz_write_buffer_byte(ctx, buf, 0); doc->html = fz_parse_html(ctx, doc->set, doc->zip, ".", buf, fz_user_css(ctx)); - } fz_always(ctx) fz_drop_buffer(ctx, buf); fz_catch(ctx) diff --git a/source/html/html-layout.c b/source/html/html-layout.c index 91297f10..ff2102d1 100644 --- a/source/html/html-layout.c +++ b/source/html/html-layout.c @@ -406,10 +406,7 @@ static fz_image *load_html_image(fz_context *ctx, fz_archive *zip, const char *b buf = fz_read_archive_entry(ctx, zip, path); #if FZ_ENABLE_SVG if (strstr(path, ".svg")) - { - fz_write_buffer_byte(ctx, buf, 0); img = fz_new_image_from_svg(ctx, buf); - } else #endif img = fz_new_image_from_buffer(ctx, buf); @@ -2552,7 +2549,7 @@ fz_parse_html(fz_context *ctx, fz_html_font_set *set, fz_archive *zip, const cha fz_xml *xml; fz_html *html; unsigned char *data; - size_t len = fz_buffer_storage(ctx, buf, &data); + size_t len; fz_css_match match; struct genstate g; @@ -2565,6 +2562,8 @@ fz_parse_html(fz_context *ctx, fz_html_font_set *set, fz_archive *zip, const cha g.emit_white = 0; g.last_brk_cls = UCDN_LINEBREAK_CLASS_OP; + fz_terminate_buffer(ctx, buf); + len = fz_buffer_storage(ctx, buf, &data); xml = fz_parse_xml(ctx, data, len, 1); g.css = fz_new_css(ctx); |