[poppler] configure.ac goo/gmem.cc goo/gmem.h poppler/GfxFont.cc

Albert Astals Cid aacid at kemper.freedesktop.org
Tue Jan 29 11:23:24 PST 2008


 configure.ac       |    1 -
 goo/gmem.cc        |    7 +++++++
 goo/gmem.h         |    5 +++++
 poppler/GfxFont.cc |    8 +-------
 4 files changed, 13 insertions(+), 8 deletions(-)

New commits:
commit 90f0e6bc1e96d9f1666cb8476a92e127f5b927d4
Author: Jonathan Kew <jonathan_kew at sil.org>
Date:   Tue Jan 29 20:23:08 2008 +0100

    Provide gstrndup as a portable substitue of strndup

diff --git a/configure.ac b/configure.ac
index dd56ea4..99ffbda 100644
--- a/configure.ac
+++ b/configure.ac
@@ -17,7 +17,6 @@ AC_PROG_CXX
 AC_PROG_INSTALL
 AC_CHECK_FUNC(gettimeofday, AC_DEFINE(HAVE_GETTIMEOFDAY, 1, [Defines if gettimeofday is available on your system]))
 AC_CHECK_FUNC(localtime_r, AC_DEFINE(HAVE_LOCALTIME_R, 1, [Defines if localtime_r is available on your system]))
-AC_CHECK_FUNC(strndup, AC_DEFINE(HAVE_STRNDUP, 1, [Defines if strndup is available on your system]))
 
 dnl Enable these unconditionally.
 AC_DEFINE([OPI_SUPPORT], [1], [Generate OPI comments in PS output.])
diff --git a/goo/gmem.cc b/goo/gmem.cc
index 3dce8ea..b11f2f4 100644
--- a/goo/gmem.cc
+++ b/goo/gmem.cc
@@ -280,3 +280,10 @@ char *copyString(char *s) {
   strcpy(s1, s);
   return s1;
 }
+
+char *gstrndup(const char *s, size_t n) {
+  char *s1 = (char*)gmalloc(n + 1); /* cannot return NULL for size > 0 */
+  s1[n] = '\0';
+  memcpy(s1, s, n);
+  return s1;
+}
diff --git a/goo/gmem.h b/goo/gmem.h
index 39c2334..b1d175d 100644
--- a/goo/gmem.h
+++ b/goo/gmem.h
@@ -75,6 +75,11 @@ extern void gMemReport(FILE *f);
  */
 extern char *copyString(char *s);
 
+/*
+ * Allocate memory and copy a limited-length string to it.
+ */
+extern char *gstrndup(const char *s, size_t n);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/poppler/GfxFont.cc b/poppler/GfxFont.cc
index 533904b..2d9abd4 100644
--- a/poppler/GfxFont.cc
+++ b/poppler/GfxFont.cc
@@ -974,13 +974,7 @@ static int parseCharName(char *charName, Unicode *uBuf, int uLen,
       return 0;	// .notdef or similar
     } else if (var_part != NULL) {
       // parse names of the form 7.oldstyle, P.swash, s.sc, etc.
-#ifdef HAVE_STRNDUP
-      char *main_part = strndup(charName, var_part - charName);
-#else
-      char *main_part = (char*)gmalloc(var_part - charName + 1);
-      main_part[var_part - charName] = '\0';
-      memcpy(main_part, charName, var_part - charName);
-#endif
+      char *main_part = gstrndup(charName, var_part - charName);
       GBool namesRecurse = gTrue, variantsRecurse = gFalse;
       int n = parseCharName(main_part, uBuf, uLen, namesRecurse, ligatures,
 			    numeric, hex, variantsRecurse);


More information about the poppler mailing list