Commit d1d71515 authored by Brad Hards's avatar Brad Hards

Merge the gmalloc -> gmallocn changes from xpdf 3.0.1. This change is

based on martink's work (13-xpdf-3.01-goo-allocn.patch) with some
tweaking by me. There may be some residual gmallocn changes still to
be merged.
parent feb82c60
2005-08-27 Brad Hards <bradh@frogmouth.net>
* Merge the gmalloc -> gmallocn changes from xpdf 3.0.1. This
change is based on martink's work (13-xpdf-3.01-goo-allocn.patch)
with some tweaking by me. There may be some residual gmallocn
changes still to be merged.
2005-08-24 Martin Kretzschmar <martink@gnome.org>
* configure.ac: add /usr/include/qt4 to qt4_incdirs. That's what
......
......@@ -667,7 +667,7 @@ void FoFiTrueType::writeTTF(FoFiOutputFunc outputFunc,
missingPost = seekTable("post") < 0;
// read the loca table, check to see if it's sorted
locaTable = (TrueTypeLoca *)gmalloc((nGlyphs + 1) * sizeof(TrueTypeLoca));
locaTable = (TrueTypeLoca *)gmallocn(nGlyphs + 1, sizeof(TrueTypeLoca));
unsortedLoca = gFalse;
i = seekTable("loca");
pos = tables[i].offset;
......@@ -751,7 +751,7 @@ void FoFiTrueType::writeTTF(FoFiOutputFunc outputFunc,
nNewTables = nTables - nZeroLengthTables +
(missingCmap ? 1 : 0) + (missingName ? 1 : 0) +
(missingPost ? 1 : 0);
newTables = (TrueTypeTable *)gmalloc(nNewTables * sizeof(TrueTypeTable));
newTables = (TrueTypeTable *)gmallocn(nNewTables, sizeof(TrueTypeTable));
j = 0;
for (i = 0; i < nTables; ++i) {
if (tables[i].len > 0) {
......@@ -1001,7 +1001,7 @@ void FoFiTrueType::cvtSfnts(FoFiOutputFunc outputFunc,
// table, cmpTrueTypeLocaPos uses offset as its primary sort key,
// and idx as its secondary key (ensuring that adjacent entries with
// the same pos value remain in the same order)
locaTable = (TrueTypeLoca *)gmalloc((nGlyphs + 1) * sizeof(TrueTypeLoca));
locaTable = (TrueTypeLoca *)gmallocn(nGlyphs + 1, sizeof(TrueTypeLoca));
i = seekTable("loca");
pos = tables[i].offset;
ok = gTrue;
......@@ -1031,7 +1031,7 @@ void FoFiTrueType::cvtSfnts(FoFiOutputFunc outputFunc,
}
// construct the new 'loca' table
locaData = (Guchar *)gmalloc((nGlyphs + 1) * (locaFmt ? 4 : 2));
locaData = (Guchar *)gmallocn(nGlyphs + 1, (locaFmt ? 4 : 2));
for (i = 0; i <= nGlyphs; ++i) {
pos = locaTable[i].newOffset;
if (locaFmt) {
......@@ -1272,7 +1272,7 @@ void FoFiTrueType::parse() {
if (!parsedOk) {
return;
}
tables = (TrueTypeTable *)gmalloc(nTables * sizeof(TrueTypeTable));
tables = (TrueTypeTable *)gmallocn(nTables, sizeof(TrueTypeTable));
pos = 12;
for (i = 0; i < nTables; ++i) {
tables[i].tag = getU32BE(pos, &parsedOk);
......@@ -1309,7 +1309,7 @@ void FoFiTrueType::parse() {
if (!parsedOk) {
return;
}
cmaps = (TrueTypeCmap *)gmalloc(nCmaps * sizeof(TrueTypeCmap));
cmaps = (TrueTypeCmap *)gmallocn(nCmaps, sizeof(TrueTypeCmap));
for (j = 0; j < nCmaps; ++j) {
cmaps[j].platform = getU16BE(pos, &parsedOk);
cmaps[j].encoding = getU16BE(pos + 2, &parsedOk);
......
......@@ -156,7 +156,7 @@ void FoFiType1::parse() {
encoding = fofiType1StandardEncoding;
} else if (!encoding &&
!strncmp(line, "/Encoding 256 array", 19)) {
encoding = (char **)gmalloc(256 * sizeof(char *));
encoding = (char **)gmallocn(256, sizeof(char *));
for (j = 0; j < 256; ++j) {
encoding[j] = NULL;
}
......
......@@ -120,7 +120,7 @@ Gushort *FoFiType1C::getCIDToGIDMap(int *nCIDs) {
}
}
++n;
map = (Gushort *)gmalloc(n * sizeof(Gushort));
map = (Gushort *)gmallocn(n, sizeof(Gushort));
memset(map, 0, n * sizeof(Gushort));
for (i = 0; i < nGlyphs; ++i) {
map[charset[i]] = i;
......@@ -403,7 +403,7 @@ void FoFiType1C::convertToCIDType0(char *psName,
nCIDs = charset[i] + 1;
}
}
cidMap = (int *)gmalloc(nCIDs * sizeof(int));
cidMap = (int *)gmallocn(nCIDs, sizeof(int));
for (i = 0; i < nCIDs; ++i) {
cidMap[i] = -1;
}
......@@ -413,7 +413,7 @@ void FoFiType1C::convertToCIDType0(char *psName,
// build the charstrings
charStrings = new GooString();
charStringOffsets = (int *)gmalloc((nCIDs + 1) * sizeof(int));
charStringOffsets = (int *)gmallocn(nCIDs + 1, sizeof(int));
for (i = 0; i < nCIDs; ++i) {
charStringOffsets[i] = charStrings->getLength();
if ((gid = cidMap[i]) >= 0) {
......@@ -670,7 +670,7 @@ void FoFiType1C::convertToType0(char *psName,
nCIDs = charset[i] + 1;
}
}
cidMap = (int *)gmalloc(nCIDs * sizeof(int));
cidMap = (int *)gmallocn(nCIDs, sizeof(int));
for (i = 0; i < nCIDs; ++i) {
cidMap[i] = -1;
}
......@@ -1692,7 +1692,7 @@ GBool FoFiType1C::parse() {
}
nFDs = fdIdx.len;
privateDicts = (Type1CPrivateDict *)
gmalloc(nFDs * sizeof(Type1CPrivateDict));
gmallocn(nFDs, sizeof(Type1CPrivateDict));
for (i = 0; i < nFDs; ++i) {
getIndexVal(&fdIdx, i, &val, &parsedOk);
if (!parsedOk) {
......@@ -2049,7 +2049,7 @@ void FoFiType1C::buildEncoding() {
encoding = fofiType1ExpertEncoding;
} else {
encoding = (char **)gmalloc(256 * sizeof(char *));
encoding = (char **)gmallocn(256, sizeof(char *));
for (i = 0; i < 256; ++i) {
encoding[i] = NULL;
}
......@@ -2136,7 +2136,7 @@ GBool FoFiType1C::readCharset() {
} else if (topDict.charsetOffset == 2) {
charset = fofiType1CExpertSubsetCharset;
} else {
charset = (Gushort *)gmalloc(nGlyphs * sizeof(Gushort));
charset = (Gushort *)gmallocn(nGlyphs, sizeof(Gushort));
for (i = 0; i < nGlyphs; ++i) {
charset[i] = 0;
}
......
......@@ -135,6 +135,28 @@ void *grealloc(void *p, size_t size) {
#endif
}
void *gmallocn(int nObjs, int objSize) {
int n;
n = nObjs * objSize;
if (objSize == 0 || n / objSize != nObjs) {
fprintf(stderr, "Bogus memory allocation size\n");
exit(1);
}
return gmalloc(n);
}
void *greallocn(void *p, int nObjs, int objSize) {
int n;
n = nObjs * objSize;
if (objSize == 0 || n / objSize != nObjs) {
fprintf(stderr, "Bogus memory allocation size\n");
exit(1);
}
return grealloc(p, n);
}
void gfree(void *p) {
#ifdef DEBUG_MEM
size_t size;
......
......@@ -27,6 +27,15 @@ extern void *gmalloc(size_t size);
*/
extern void *grealloc(void *p, size_t size);
/*
* These are similar to gmalloc and grealloc, but take an object count
* and size. The result is similar to allocating nObjs * objSize
* bytes, but there is an additional error check that the total size
* doesn't overflow an int.
*/
extern void *gmallocn(int nObjs, int objSize);
extern void *greallocn(void *p, int nObjs, int objSize);
/*
* Same as free, but checks for and ignores NULL pointers.
*/
......
......@@ -115,7 +115,7 @@ Annots::Annots(XRef *xref, Object *annotsObj) {
if (annot->isOk()) {
if (nAnnots >= size) {
size += 16;
annots = (Annot **)grealloc(annots, size * sizeof(Annot *));
annots = (Annot **)greallocn(annots, size, sizeof(Annot *));
}
annots[nAnnots++] = annot;
} else {
......
......@@ -44,7 +44,7 @@ void Array::add(Object *elem) {
} else {
size *= 2;
}
elems = (Object *)grealloc(elems, size * sizeof(Object));
elems = (Object *)greallocn(elems, size, sizeof(Object));
}
elems[length] = *elem;
++length;
......
......@@ -24,7 +24,7 @@ BuiltinFontWidths::BuiltinFontWidths(BuiltinFontWidth *widths, int sizeA) {
int i, h;
size = sizeA;
tab = (BuiltinFontWidth **)gmalloc(size * sizeof(BuiltinFontWidth *));
tab = (BuiltinFontWidth **)gmallocn(size, sizeof(BuiltinFontWidth *));
for (i = 0; i < size; ++i) {
tab[i] = NULL;
}
......
......@@ -138,7 +138,7 @@ CMap::CMap(GooString *collectionA, GooString *cMapNameA) {
collection = collectionA;
cMapName = cMapNameA;
wMode = 0;
vector = (CMapVectorEntry *)gmalloc(256 * sizeof(CMapVectorEntry));
vector = (CMapVectorEntry *)gmallocn(256, sizeof(CMapVectorEntry));
for (i = 0; i < 256; ++i) {
vector[i].isVector = gFalse;
vector[i].cid = 0;
......@@ -182,7 +182,7 @@ void CMap::copyVector(CMapVectorEntry *dest, CMapVectorEntry *src) {
if (!dest[i].isVector) {
dest[i].isVector = gTrue;
dest[i].vector =
(CMapVectorEntry *)gmalloc(256 * sizeof(CMapVectorEntry));
(CMapVectorEntry *)gmallocn(256, sizeof(CMapVectorEntry));
for (j = 0; j < 256; ++j) {
dest[i].vector[j].isVector = gFalse;
dest[i].vector[j].cid = 0;
......@@ -213,7 +213,7 @@ void CMap::addCodeSpace(CMapVectorEntry *vec, Guint start, Guint end,
if (!vec[i].isVector) {
vec[i].isVector = gTrue;
vec[i].vector =
(CMapVectorEntry *)gmalloc(256 * sizeof(CMapVectorEntry));
(CMapVectorEntry *)gmallocn(256, sizeof(CMapVectorEntry));
for (j = 0; j < 256; ++j) {
vec[i].vector[j].isVector = gFalse;
vec[i].vector[j].cid = 0;
......
......@@ -76,8 +76,8 @@ Catalog::Catalog(XRef *xrefA) {
return;
}
pages = (Page **)gmalloc(pagesSize * sizeof(Page *));
pageRefs = (Ref *)gmalloc(pagesSize * sizeof(Ref));
pages = (Page **)gmallocn(pagesSize, sizeof(Page *));
pageRefs = (Ref *)gmallocn(pagesSize, sizeof(Ref));
for (i = 0; i < pagesSize; ++i) {
pages[i] = NULL;
pageRefs[i].num = -1;
......@@ -248,8 +248,8 @@ int Catalog::readPageTree(Dict *pagesDict, PageAttrs *attrs, int start) {
error(-1, "Invalid 'pagesSize' parameter.");
goto err3;
}
pages = (Page **)grealloc(pages, pagesSize * sizeof(Page *));
pageRefs = (Ref *)grealloc(pageRefs, pagesSize * sizeof(Ref));
pages = (Page **)greallocn(pages, pagesSize, sizeof(Page *));
pageRefs = (Ref *)greallocn(pageRefs, pagesSize, sizeof(Ref));
for (j = pagesSize - 32; j < pagesSize; ++j) {
pages[j] = NULL;
pageRefs[j].num = -1;
......
......@@ -70,13 +70,13 @@ CharCodeToUnicode *CharCodeToUnicode::parseCIDToUnicode(GooString *fileName,
}
size = 32768;
mapA = (Unicode *)gmalloc(size * sizeof(Unicode));
mapA = (Unicode *)gmallocn(size, sizeof(Unicode));
mapLenA = 0;
while (getLine(buf, sizeof(buf), f)) {
if (mapLenA == size) {
size *= 2;
mapA = (Unicode *)grealloc(mapA, size * sizeof(Unicode));
mapA = (Unicode *)greallocn(mapA, size, sizeof(Unicode));
}
if (sscanf(buf, "%x", &u) == 1) {
mapA[mapLenA] = u;
......@@ -115,7 +115,7 @@ CharCodeToUnicode *CharCodeToUnicode::parseUnicodeToUnicode(
}
size = 4096;
mapA = (Unicode *)gmalloc(size * sizeof(Unicode));
mapA = (Unicode *)gmallocn(size, sizeof(Unicode));
memset(mapA, 0, size * sizeof(Unicode));
len = 0;
sMapA = NULL;
......@@ -152,7 +152,7 @@ CharCodeToUnicode *CharCodeToUnicode::parseUnicodeToUnicode(
while (u0 >= size) {
size *= 2;
}
mapA = (Unicode *)grealloc(mapA, size * sizeof(Unicode));
mapA = (Unicode *)greallocn(mapA, size, sizeof(Unicode));
memset(mapA + oldSize, 0, (size - oldSize) * sizeof(Unicode));
}
if (n == 1) {
......@@ -162,7 +162,7 @@ CharCodeToUnicode *CharCodeToUnicode::parseUnicodeToUnicode(
if (sMapLenA == sMapSizeA) {
sMapSizeA += 16;
sMapA = (CharCodeToUnicodeString *)
grealloc(sMapA, sMapSizeA * sizeof(CharCodeToUnicodeString));
greallocn(sMapA, sMapSizeA, sizeof(CharCodeToUnicodeString));
}
sMapA[sMapLenA].c = u0;
for (i = 0; i < n; ++i) {
......@@ -320,7 +320,7 @@ void CharCodeToUnicode::addMapping(CharCode code, char *uStr, int n,
if (code >= mapLen) {
oldLen = mapLen;
mapLen = (code + 256) & ~255;
map = (Unicode *)grealloc(map, mapLen * sizeof(Unicode));
map = (Unicode *)greallocn(map, mapLen, sizeof(Unicode));
for (i = oldLen; i < mapLen; ++i) {
map[i] = 0;
}
......@@ -335,7 +335,7 @@ void CharCodeToUnicode::addMapping(CharCode code, char *uStr, int n,
if (sMapLen >= sMapSize) {
sMapSize = sMapSize + 16;
sMap = (CharCodeToUnicodeString *)
grealloc(sMap, sMapSize * sizeof(CharCodeToUnicodeString));
greallocn(sMap, sMapSize, sizeof(CharCodeToUnicodeString));
}
map[code] = 0;
sMap[sMapLen].c = code;
......@@ -357,7 +357,7 @@ CharCodeToUnicode::CharCodeToUnicode(GooString *tagA) {
tag = tagA;
mapLen = 256;
map = (Unicode *)gmalloc(mapLen * sizeof(Unicode));
map = (Unicode *)gmallocn(mapLen, sizeof(Unicode));
for (i = 0; i < mapLen; ++i) {
map[i] = 0;
}
......@@ -376,7 +376,7 @@ CharCodeToUnicode::CharCodeToUnicode(GooString *tagA, Unicode *mapA,
tag = tagA;
mapLen = mapLenA;
if (copyMap) {
map = (Unicode *)gmalloc(mapLen * sizeof(Unicode));
map = (Unicode *)gmallocn(mapLen, sizeof(Unicode));
memcpy(map, mapA, mapLen * sizeof(Unicode));
} else {
map = mapA;
......@@ -442,7 +442,7 @@ void CharCodeToUnicode::setMapping(CharCode c, Unicode *u, int len) {
if (sMapLen == sMapSize) {
sMapSize += 8;
sMap = (CharCodeToUnicodeString *)
grealloc(sMap, sMapSize * sizeof(CharCodeToUnicodeString));
greallocn(sMap, sMapSize, sizeof(CharCodeToUnicodeString));
}
sMap[sMapLen].c = c;
sMap[sMapLen].len = len;
......@@ -480,7 +480,7 @@ CharCodeToUnicodeCache::CharCodeToUnicodeCache(int sizeA) {
int i;
size = sizeA;
cache = (CharCodeToUnicode **)gmalloc(size * sizeof(CharCodeToUnicode *));
cache = (CharCodeToUnicode **)gmallocn(size, sizeof(CharCodeToUnicode *));
for (i = 0; i < size; ++i) {
cache[i] = NULL;
}
......
......@@ -47,7 +47,7 @@ void Dict::add(char *key, Object *val) {
} else {
size *= 2;
}
entries = (DictEntry *)grealloc(entries, size * sizeof(DictEntry));
entries = (DictEntry *)greallocn(entries, size, sizeof(DictEntry));
}
entries[length].key = key;
entries[length].val = *val;
......
......@@ -297,7 +297,7 @@ SampledFunction::SampledFunction(Object *funcObj, Dict *dict) {
nSamples = n;
for (i = 0; i < m; ++i)
nSamples *= sampleSize[i];
samples = (double *)gmalloc(nSamples * sizeof(double));
samples = (double *)gmallocn(nSamples, sizeof(double));
buf = 0;
bits = 0;
bitMask = (1 << sampleBits) - 1;
......@@ -351,7 +351,7 @@ SampledFunction::SampledFunction(SampledFunction *func) {
for (i = 0; i < m; ++i) {
nSamples *= sampleSize[i];
}
samples = (double *)gmalloc(nSamples * sizeof(double));
samples = (double *)gmallocn(nSamples, sizeof(double));
memcpy(samples, func->samples, nSamples * sizeof(double));
}
......@@ -554,9 +554,9 @@ StitchingFunction::StitchingFunction(Object *funcObj, Dict *dict) {
goto err1;
}
k = obj1.arrayGetLength();
funcs = (Function **)gmalloc(k * sizeof(Function *));
bounds = (double *)gmalloc((k + 1) * sizeof(double));
encode = (double *)gmalloc(2 * k * sizeof(double));
funcs = (Function **)gmallocn(k, sizeof(Function *));
bounds = (double *)gmallocn(k + 1, sizeof(double));
encode = (double *)gmallocn(2 * k, sizeof(double));
for (i = 0; i < k; ++i) {
funcs[i] = NULL;
}
......@@ -620,13 +620,13 @@ StitchingFunction::StitchingFunction(StitchingFunction *func) {
int i;
k = func->k;
funcs = (Function **)gmalloc(k * sizeof(Function *));
funcs = (Function **)gmallocn(k, sizeof(Function *));
for (i = 0; i < k; ++i) {
funcs[i] = func->funcs[i]->copy();
}
bounds = (double *)gmalloc((k + 1) * sizeof(double));
bounds = (double *)gmallocn(k + 1, sizeof(double));
memcpy(bounds, func->bounds, (k + 1) * sizeof(double));
encode = (double *)gmalloc(2 * k * sizeof(double));
encode = (double *)gmallocn(2 * k, sizeof(double));
memcpy(encode, func->encode, 2 * k * sizeof(double));
ok = gTrue;
}
......@@ -1016,7 +1016,7 @@ PostScriptFunction::PostScriptFunction(Object *funcObj, Dict *dict) {
PostScriptFunction::PostScriptFunction(PostScriptFunction *func) {
memcpy(this, func, sizeof(PostScriptFunction));
code = (PSObject *)gmalloc(codeSize * sizeof(PSObject));
code = (PSObject *)gmallocn(codeSize, sizeof(PSObject));
memcpy(code, func->code, codeSize * sizeof(PSObject));
}
......@@ -1207,7 +1207,7 @@ GooString *PostScriptFunction::getToken(Stream *str) {
void PostScriptFunction::resizeCode(int newSize) {
if (newSize >= codeSize) {
codeSize += 64;
code = (PSObject *)grealloc(code, codeSize * sizeof(PSObject));
code = (PSObject *)greallocn(code, codeSize, sizeof(PSObject));
}
}
......
......@@ -764,7 +764,7 @@ void Gfx::opSetDash(Object args[], int numArgs) {
if (length == 0) {
dash = NULL;
} else {
dash = (double *)gmalloc(length * sizeof(double));
dash = (double *)gmallocn(length, sizeof(double));
for (i = 0; i < length; ++i) {
dash[i] = a->get(i, &obj)->getNum();
obj.free();
......
......@@ -940,7 +940,7 @@ Gushort *Gfx8BitFont::getCodeToGIDMap(FoFiTrueType *ff) {
Unicode u;
int code, i, n;
map = (Gushort *)gmalloc(256 * sizeof(Gushort));
map = (Gushort *)gmallocn(256, sizeof(Gushort));
for (i = 0; i < 256; ++i) {
map[i] = 0;
}
......@@ -1198,13 +1198,13 @@ GfxCIDFont::GfxCIDFont(XRef *xref, char *tagA, Ref idA, GooString *nameA,
if (obj1.isStream()) {
cidToGIDLen = 0;
i = 64;
cidToGID = (Gushort *)gmalloc(i * sizeof(Gushort));
cidToGID = (Gushort *)gmallocn(i, sizeof(Gushort));
obj1.streamReset();
while ((c1 = obj1.streamGetChar()) != EOF &&
(c2 = obj1.streamGetChar()) != EOF) {
if (cidToGIDLen == i) {
i *= 2;
cidToGID = (Gushort *)grealloc(cidToGID, i * sizeof(Gushort));
cidToGID = (Gushort *)greallocn(cidToGID, i, sizeof(Gushort));
}
cidToGID[cidToGIDLen++] = (Gushort)((c1 << 8) + c2);
}
......@@ -1234,8 +1234,8 @@ GfxCIDFont::GfxCIDFont(XRef *xref, char *tagA, Ref idA, GooString *nameA,
if (widths.nExceps == excepsSize) {
excepsSize += 16;
widths.exceps = (GfxFontCIDWidthExcep *)
grealloc(widths.exceps,
excepsSize * sizeof(GfxFontCIDWidthExcep));
greallocn(widths.exceps,
excepsSize, sizeof(GfxFontCIDWidthExcep));
}
widths.exceps[widths.nExceps].first = obj2.getInt();
widths.exceps[widths.nExceps].last = obj3.getInt();
......@@ -1250,8 +1250,8 @@ GfxCIDFont::GfxCIDFont(XRef *xref, char *tagA, Ref idA, GooString *nameA,
if (widths.nExceps + obj3.arrayGetLength() > excepsSize) {
excepsSize = (widths.nExceps + obj3.arrayGetLength() + 15) & ~15;
widths.exceps = (GfxFontCIDWidthExcep *)
grealloc(widths.exceps,
excepsSize * sizeof(GfxFontCIDWidthExcep));
greallocn(widths.exceps,
excepsSize, sizeof(GfxFontCIDWidthExcep));
}
j = obj2.getInt();
for (k = 0; k < obj3.arrayGetLength(); ++k) {
......@@ -1307,8 +1307,8 @@ GfxCIDFont::GfxCIDFont(XRef *xref, char *tagA, Ref idA, GooString *nameA,
if (widths.nExcepsV == excepsSize) {
excepsSize += 16;
widths.excepsV = (GfxFontCIDWidthExcepV *)
grealloc(widths.excepsV,
excepsSize * sizeof(GfxFontCIDWidthExcepV));
greallocn(widths.excepsV,
excepsSize, sizeof(GfxFontCIDWidthExcepV));
}
widths.excepsV[widths.nExcepsV].first = obj2.getInt();
widths.excepsV[widths.nExcepsV].last = obj3.getInt();
......@@ -1328,8 +1328,8 @@ GfxCIDFont::GfxCIDFont(XRef *xref, char *tagA, Ref idA, GooString *nameA,
excepsSize =
(widths.nExcepsV + obj3.arrayGetLength() / 3 + 15) & ~15;
widths.excepsV = (GfxFontCIDWidthExcepV *)
grealloc(widths.excepsV,
excepsSize * sizeof(GfxFontCIDWidthExcepV));
greallocn(widths.excepsV,
excepsSize, sizeof(GfxFontCIDWidthExcepV));
}
j = obj2.getInt();
for (k = 0; k < obj3.arrayGetLength(); k += 3) {
......@@ -1492,7 +1492,7 @@ GfxFontDict::GfxFontDict(XRef *xref, Ref *fontDictRef, Dict *fontDict) {
Ref r;
numFonts = fontDict->getLength();
fonts = (GfxFont **)gmalloc(numFonts * sizeof(GfxFont *));
fonts = (GfxFont **)gmallocn(numFonts, sizeof(GfxFont *));
for (i = 0; i < numFonts; ++i) {
fontDict->getValNF(i, &obj1);
obj1.fetch(xref, &obj2);
......
......@@ -907,8 +907,8 @@ GfxIndexedColorSpace::GfxIndexedColorSpace(GfxColorSpace *baseA,
int indexHighA) {
base = baseA;
indexHigh = indexHighA;
lookup = (Guchar *)gmalloc((indexHigh + 1) * base->getNComps() *
sizeof(Guchar));
lookup = (Guchar *)gmallocn((indexHigh + 1) * base->getNComps(),
sizeof(Guchar));
}
GfxIndexedColorSpace::~GfxIndexedColorSpace() {
......@@ -2176,7 +2176,7 @@ GfxImageColorMap::GfxImageColorMap(int bitsA, Object *decode,
colorSpace2 = indexedCS->getBase();
indexHigh = indexedCS->getIndexHigh();
nComps2 = colorSpace2->getNComps();
lookup = (double *)gmalloc((maxPixel + 1) * nComps2 * sizeof(double));
lookup = (double *)gmallocn((maxPixel + 1) * nComps2, sizeof(double));
lookup2 = indexedCS->getLookup();
colorSpace2->getDefaultRanges(x, y, indexHigh);
byte_lookup = (Guchar *)gmalloc ((maxPixel + 1) * nComps2);
......@@ -2200,8 +2200,8 @@ GfxImageColorMap::GfxImageColorMap(int bitsA, Object *decode,
sepCS = (GfxSeparationColorSpace *)colorSpace;
colorSpace2 = sepCS->getAlt();
nComps2 = colorSpace2->getNComps();
lookup = (double *)gmalloc((maxPixel + 1) * nComps2 * sizeof(double));
byte_lookup = (Guchar *)gmalloc ((maxPixel + 1) * nComps2);
lookup = (double *)gmallocn((maxPixel + 1) * nComps2, sizeof(double));
byte_lookup = (Guchar *)gmallocn ((maxPixel + 1), nComps2);
sepFunc = sepCS->getFunc();
for (i = 0; i <= maxPixel; ++i) {
x[0] = decodeLow[0] + (i * decodeRange[0]) / maxPixel;
......@@ -2212,8 +2212,8 @@ GfxImageColorMap::GfxImageColorMap(int bitsA, Object *decode,
}
}
} else {
lookup = (double *)gmalloc((maxPixel + 1) * nComps * sizeof(double));
byte_lookup = (Guchar *)gmalloc ((maxPixel + 1) * nComps);
lookup = (double *)gmallocn((maxPixel + 1) * nComps, sizeof(double));
byte_lookup = (Guchar *)gmallocn ((maxPixel + 1), nComps);
for (i = 0; i <= maxPixel; ++i) {
for (k = 0; k < nComps; ++k) {
......@@ -2380,9 +2380,9 @@ void GfxImageColorMap::getColor(Guchar *x, GfxColor *color) {
GfxSubpath::GfxSubpath(double x1, double y1) {
size = 16;
x = (double *)gmalloc(size * sizeof(double));
y = (double *)gmalloc(size * sizeof(double));
curve = (GBool *)gmalloc(size * sizeof(GBool));
x = (double *)gmallocn(size, sizeof(double));
y = (double *)gmallocn(size, sizeof(double));
curve = (GBool *)gmallocn(size, sizeof(GBool));
n = 1;
x[0] = x1;
y[0] = y1;
......@@ -2400,9 +2400,9 @@ GfxSubpath::~GfxSubpath() {
GfxSubpath::GfxSubpath(GfxSubpath *subpath) {
size = subpath->size;
n = subpath->n;
x = (double *)gmalloc(size * sizeof(double));
y = (double *)gmalloc(size * sizeof(double));
curve = (GBool *)gmalloc(size * sizeof(GBool));
x = (double *)gmallocn(size, sizeof(double));
y = (double *)gmallocn(size, sizeof(double));
curve = (GBool *)gmallocn(size, sizeof(GBool));
memcpy(x, subpath->x, n * sizeof(double));
memcpy(y, subpath->y, n * sizeof(double));
memcpy(curve, subpath->curve, n * sizeof(GBool));
......@@ -2412,9 +2412,9 @@ GfxSubpath::GfxSubpath(GfxSubpath *subpath) {
void GfxSubpath::lineTo(double x1, double y1) {
if (n >= size) {
size += 16;
x = (double *)grealloc(x, size * sizeof(double));
y = (double *)grealloc(y, size * sizeof(double));
curve = (GBool *)grealloc(curve, size * sizeof(GBool));
x = (double *)greallocn(x, size, sizeof(double));
y = (double *)greallocn(y, size, sizeof(double));
curve = (GBool *)greallocn(curve, size, sizeof(GBool));
}
x[n] = x1;
y[n] = y1;
......@@ -2426,9 +2426,9 @@ void GfxSubpath::curveTo(double x1, double y1, double x2, double y2,
double x3, double y3) {
if (n+3 > size) {
size += 16;
x = (double *)grealloc(x, size * sizeof(double));
y = (double *)grealloc(y, size * sizeof(double));
curve = (GBool *)grealloc(curve, size * sizeof(GBool));
x = (double *)greallocn(x, size, sizeof(double));
y = (double *)greallocn(y, size, sizeof(double));
curve = (GBool *)greallocn(curve, size, sizeof(GBool));
}
x[n] = x1;
y[n] = y1;
......@@ -2462,7 +2462,7 @@ GfxPath::GfxPath() {
size = 16;
n = 0;
firstX = firstY = 0;
subpaths = (GfxSubpath **)gmalloc(size * sizeof(GfxSubpath *));
subpaths = (GfxSubpath **)gmallocn(size, sizeof(GfxSubpath *));
}
GfxPath::~GfxPath() {
......@@ -2483,7 +2483,7 @@ GfxPath::GfxPath(GBool justMoved1, double firstX1, double firstY1,
firstY = firstY1;
size = size1;
n = n1;
subpaths = (GfxSubpath **)gmalloc(size * sizeof(GfxSubpath *));
subpaths = (GfxSubpath **)gmallocn(size, sizeof(GfxSubpath *));
for (i = 0; i < n; ++i)
subpaths[i] = subpaths1[i]->copy();
}
......@@ -2499,7 +2499,7 @@ void GfxPath::lineTo(double x, double y) {
if (n >= size) {
size += 16;
subpaths = (GfxSubpath **)
grealloc(subpaths, size * sizeof(GfxSubpath *));
greallocn(subpaths, size, sizeof(GfxSubpath *));
}
subpaths[n] = new GfxSubpath(firstX, firstY);
++n;
......@@ -2513,8 +2513,8 @@ void GfxPath::curveTo(double x1, double y1, double x2, double y2,
if (justMoved) {
if (n >= size) {
size += 16;
subpaths = (GfxSubpath **)
grealloc(subpaths, size * sizeof(GfxSubpath *));
subpaths = (GfxSubpath **)
greallocn(subpaths, size, sizeof(GfxSubpath *));
}
subpaths[n] = new GfxSubpath(firstX, firstY);
++n;
......@@ -2530,7 +2530,7 @@ void GfxPath::close() {
if (n >= size) {
size += 16;
subpaths = (GfxSubpath **)
grealloc(subpaths, size * sizeof(GfxSubpath *));
greallocn(subpaths, size, sizeof(GfxSubpath *));
}
subpaths[n] = new GfxSubpath(firstX, firstY);
++n;
......@@ -2545,7 +2545,7 @@ void GfxPath::append(GfxPath *path) {
if (n + path->n > size) {
size = n + path->n;
subpaths = (GfxSubpath **)
grealloc(subpaths, size * sizeof(GfxSubpath *));
greallocn(subpaths, size, sizeof(GfxSubpath *));
}
for (i = 0; i < path->n; ++i) {
subpaths[n++] = path->subpaths[i]->copy();
......@@ -2694,7 +2694,7 @@ GfxState::GfxState(GfxState *state) {
strokePattern = state->strokePattern->copy();
}
if (lineDashLength > 0) {
lineDash = (double *)gmalloc(lineDashLength * sizeof(double));
lineDash = (double *)gmallocn(lineDashLength, sizeof(double));
memcpy(lineDash, state->lineDash, lineDashLength * sizeof(double));
}
saved = NULL;
......
......@@ -22,7 +22,7 @@
JArithmeticDecoderStats::JArithmeticDecoderStats(int contextSizeA) {
contextSize = contextSizeA;
cxTab = (Guchar *)gmalloc(contextSize * sizeof(Guchar));
cxTab = (Guchar *)gmallocn(contextSize, sizeof(Guchar));
reset();
}
......
......@@ -993,7 +993,7 @@ JBIG2SymbolDict::JBIG2SymbolDict(Guint segNumA, Guint sizeA):
JBIG2Segment(segNumA)
{
size = sizeA;
bitmaps = (JBIG2Bitmap **)gmalloc(size * sizeof(JBIG2Bitmap *));
bitmaps = (JBIG2Bitmap **)gmallocn(size, sizeof(JBIG2Bitmap *));