[cairo-commit] src/cairo-pdf-interchange.c test/pdf-tagged-text.c

Adrian Johnson ajohnson at kemper.freedesktop.org
Thu Oct 6 21:11:40 UTC 2016


 src/cairo-pdf-interchange.c |   12 ++++++++++--
 test/pdf-tagged-text.c      |    6 +++++-
 2 files changed, 15 insertions(+), 3 deletions(-)

New commits:
commit 4790a3663d12cfbbe643023713477204d61b1c4a
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Fri Oct 7 07:38:37 2016 +1030

    strndup is not avuilable with MSVC

diff --git a/src/cairo-pdf-interchange.c b/src/cairo-pdf-interchange.c
index fc21b32..18dd4d8 100644
--- a/src/cairo-pdf-interchange.c
+++ b/src/cairo-pdf-interchange.c
@@ -627,8 +627,16 @@ split_label (const char* label, int *num)
     if (i < len)
 	sscanf (label + i, "%d", num);
 
-    if (i > 0)
-	return strndup (label, i);
+    if (i > 0) {
+	char *s;
+	s = _cairo_malloc (i + 1);
+	if (!s)
+	    return NULL;
+
+	memcpy (s, label, i);
+	s[i] = 0;
+	return s;
+    }
 
     return NULL;
 }
diff --git a/test/pdf-tagged-text.c b/test/pdf-tagged-text.c
index e8484f0..14dbad1 100644
--- a/test/pdf-tagged-text.c
+++ b/test/pdf-tagged-text.c
@@ -134,7 +134,11 @@ layout_paragraph (cairo_t *cr)
 	cairo_text_extents (cr, begin, &text_extents);
 	*end = ' ';
 	if (text_extents.width + 2*MARGIN > PAGE_WIDTH) {
-	    paragraph_text[paragraph_num_lines++] = strndup (begin, prev_end - begin);
+	    int len = prev_end - begin;
+	    char *s = malloc (len);
+	    memcpy (s, begin, len);
+	    s[0] = 0;
+	    paragraph_text[paragraph_num_lines++] = s;
 	    begin = prev_end + 1;
 	}
 	prev_end = end;


More information about the cairo-commit mailing list