diff --git a/goo/PNGWriter.cc b/goo/PNGWriter.cc index b775600..456bf49 100644 --- a/goo/PNGWriter.cc +++ b/goo/PNGWriter.cc @@ -64,7 +64,7 @@ void PNGWriter::setICCProfile(const char *name, unsigned char *data, int size) priv->icc_data = (unsigned char *)gmalloc(size); memcpy(priv->icc_data, data, size); priv->icc_data_size = size; - priv->icc_name = strdup(name); + priv->icc_name = gstrdup(name); } void PNGWriter::setSRGBProfile() diff --git a/goo/gmem.cc b/goo/gmem.cc index c1c607a..595fc10 100644 --- a/goo/gmem.cc +++ b/goo/gmem.cc @@ -324,3 +324,8 @@ char *gstrndup(const char *s, size_t n) { memcpy(s1, s, n); return s1; } + +char *gstrdup(const char *s) { + size_t n = strlen(s); + return gstrndup(s, n); +} diff --git a/goo/gmem.h b/goo/gmem.h index 898f339..625c89d 100644 --- a/goo/gmem.h +++ b/goo/gmem.h @@ -85,6 +85,11 @@ extern char *copyString(const char *s); */ extern char *gstrndup(const char *s, size_t n); +/* + * Allocate memory and copy a unlimited string to it. + */ +extern char *gstrdup(const char *s); + #ifdef __cplusplus } #endif diff --git a/poppler/Annot.cc b/poppler/Annot.cc index f0cce6d..6c6796f 100644 --- a/poppler/Annot.cc +++ b/poppler/Annot.cc @@ -4990,7 +4990,7 @@ void AnnotWidget::generateFieldAppearance() { } // build the appearance stream - appearStream = new MemStream(strdup(appearBuf->getCString()), 0, + appearStream = new MemStream(gstrdup(appearBuf->getCString()), 0, appearBuf->getLength(), &appearDict); appearance.free(); appearance.initStream(appearStream); diff --git a/poppler/Dict.cc b/poppler/Dict.cc index 3f3c022..91c2579 100644 --- a/poppler/Dict.cc +++ b/poppler/Dict.cc @@ -96,7 +96,7 @@ Dict::Dict(Dict* dictA) { sorted = dictA->sorted; entries = (DictEntry *)gmallocn(size, sizeof(DictEntry)); for (int i=0; ientries[i].key); + entries[i].key = gstrdup(dictA->entries[i].key); dictA->entries[i].val.copy(&entries[i].val); } } diff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc index 4fe5d7b..c7056de 100644 --- a/poppler/PSOutputDev.cc +++ b/poppler/PSOutputDev.cc @@ -1409,7 +1409,7 @@ void PSOutputDev::writeHeader(int firstPage, int lastPage, obj1.free(); info.free(); if(psTitle) { - char *sanitizedTile = strdup(psTitle); + char *sanitizedTile = gstrdup(psTitle); for (Guint i = 0; i < strlen(sanitizedTile); ++i) { if (sanitizedTile[i] == '\n' || sanitizedTile[i] == '\r') { sanitizedTile[i] = ' ';