summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mupdf/fitz/buffer.h6
-rw-r--r--source/fitz/buffer.c9
-rw-r--r--source/tools/murun.c2
3 files changed, 16 insertions, 1 deletions
diff --git a/include/mupdf/fitz/buffer.h b/include/mupdf/fitz/buffer.h
index 54c1078b..251a5943 100644
--- a/include/mupdf/fitz/buffer.h
+++ b/include/mupdf/fitz/buffer.h
@@ -69,6 +69,12 @@ fz_buffer *fz_new_buffer_from_data(fz_context *ctx, unsigned char *data, size_t
fz_buffer *fz_new_buffer_from_shared_data(fz_context *ctx, const unsigned char *data, size_t size);
/*
+ fz_new_buffer_from_copied_data: Create a new buffer containing a copy of the passed data.
+*/
+fz_buffer *
+fz_new_buffer_from_copied_data(fz_context *ctx, const unsigned char *data, size_t size);
+
+/*
fz_new_buffer_from_base64: Create a new buffer with data decoded from a base64 input string.
*/
fz_buffer *fz_new_buffer_from_base64(fz_context *ctx, const char *data, size_t size);
diff --git a/source/fitz/buffer.c b/source/fitz/buffer.c
index a43ff296..7068803a 100644
--- a/source/fitz/buffer.c
+++ b/source/fitz/buffer.c
@@ -68,6 +68,15 @@ fz_new_buffer_from_shared_data(fz_context *ctx, const unsigned char *data, size_
}
fz_buffer *
+fz_new_buffer_from_copied_data(fz_context *ctx, const unsigned char *data, size_t size)
+{
+ fz_buffer *b = fz_new_buffer(ctx, size);
+ b->len = size;
+ memcpy(b->data, data, size);
+ return b;
+}
+
+fz_buffer *
fz_new_buffer_from_base64(fz_context *ctx, const char *data, size_t size)
{
fz_buffer *buf = fz_new_buffer(ctx, size);
diff --git a/source/tools/murun.c b/source/tools/murun.c
index dd93b138..5925ba4f 100644
--- a/source/tools/murun.c
+++ b/source/tools/murun.c
@@ -763,7 +763,7 @@ static fz_buffer *ffi_tobuffer(js_State *J, int idx)
else {
const char *str = js_tostring(J, idx);
fz_try(ctx)
- buf = fz_new_buffer_from_shared_data(ctx, (const unsigned char *)str, strlen(str));
+ buf = fz_new_buffer_from_copied_data(ctx, (const unsigned char *)str, strlen(str));
fz_catch(ctx)
rethrow(J);
}