diff options
author | Adrian Johnson <ajohnson@redneon.com> | 2023-03-03 22:07:25 +1030 |
---|---|---|
committer | Adrian Johnson <ajohnson@redneon.com> | 2023-04-18 18:27:12 +0930 |
commit | de9452438e25f6f8ba63c769a5663014fdbb699d (patch) | |
tree | 2a2f466e85fe8fd139430549c5a9ced662366973 | |
parent | b53b48116e610d61cdf630c24a11b59a18345e16 (diff) | |
download | cairo-de9452438e25f6f8ba63c769a5663014fdbb699d.tar.gz |
pdf: Don't use snprintf() to print floats
It is not locale independent.
-rw-r--r-- | src/cairo-pdf-surface.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c index ca83e61ed..459f90a8f 100644 --- a/src/cairo-pdf-surface.c +++ b/src/cairo-pdf-surface.c @@ -2476,7 +2476,6 @@ _cairo_pdf_surface_open_content_stream (cairo_pdf_surface_t *surface, int struct_parents) { cairo_int_status_t status; - char buf[1000]; assert (surface->pdf_stream.active == FALSE); assert (surface->group_stream.active == FALSE); @@ -2488,9 +2487,9 @@ _cairo_pdf_surface_open_content_stream (cairo_pdf_surface_t *surface, if (is_form) { assert (bbox != NULL); + cairo_output_stream_t *mem_stream = _cairo_memory_stream_create (); if (is_group) { - snprintf(buf, - sizeof(buf), + _cairo_output_stream_printf (mem_stream, " /Type /XObject\n" " /Subtype /Form\n" " /BBox [ %f %f %f %f ]\n" @@ -2507,8 +2506,7 @@ _cairo_pdf_surface_open_content_stream (cairo_pdf_surface_t *surface, bbox->p2.y, surface->content_resources.id); } else { - snprintf(buf, - sizeof(buf), + _cairo_output_stream_printf (mem_stream, " /Type /XObject\n" " /Subtype /Form\n" " /BBox [ %f %f %f %f ]\n" @@ -2520,15 +2518,25 @@ _cairo_pdf_surface_open_content_stream (cairo_pdf_surface_t *surface, surface->content_resources.id); } if (struct_parents >= 0) { - snprintf(buf + strlen(buf), - sizeof(buf) - strlen(buf), + _cairo_output_stream_printf (mem_stream, " /StructParents %d\n", struct_parents); } + + unsigned char *data; + unsigned long length; + status = _cairo_memory_stream_destroy (mem_stream, &data, &length); + if (unlikely (status)) + return status; + + char *str = _cairo_strndup ((const char*)data, length); /* Add NULL terminator */ + status = _cairo_pdf_surface_open_stream (surface, resource, surface->compress_streams, - buf); + str); + free (str); + free (data); } else { status = _cairo_pdf_surface_open_stream (surface, |