You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@corinthia.apache.org by ja...@apache.org on 2015/02/26 19:50:45 UTC
incubator-corinthia git commit: xmalloc patch
Repository: incubator-corinthia
Updated Branches:
refs/heads/master d66c5ca7c -> 70c986172
xmalloc patch
patch from gabriela, added COR-48
Project: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/commit/70c98617
Tree: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/tree/70c98617
Diff: http://git-wip-us.apache.org/repos/asf/incubator-corinthia/diff/70c98617
Branch: refs/heads/master
Commit: 70c986172faea8493e855c51e09be8e1a4d080bb
Parents: d66c5ca
Author: jani <ja...@apache.org>
Authored: Thu Feb 26 19:49:38 2015 +0100
Committer: jani <ja...@apache.org>
Committed: Thu Feb 26 19:49:38 2015 +0100
----------------------------------------------------------------------
DocFormats/core/src/common/DFBDT.c | 2 +-
DocFormats/core/src/css/CSSSelector.c | 4 +-
DocFormats/core/src/html/DFHTML.c | 2 +-
DocFormats/core/src/html/DFHTMLNormalization.c | 2 +-
DocFormats/core/src/html/DFTidyHelper.c | 2 +-
DocFormats/core/src/lib/DFAllocator.c | 6 +--
DocFormats/core/src/lib/DFArray.c | 2 +-
DocFormats/core/src/lib/DFBuffer.c | 2 +-
DocFormats/core/src/lib/DFError.c | 2 +-
DocFormats/core/src/lib/DFFilesystem.c | 4 +-
DocFormats/core/src/lib/DFHashTable.c | 4 +-
DocFormats/core/src/lib/DFStorage.c | 6 +--
DocFormats/core/src/lib/DFString.c | 16 +++----
DocFormats/core/src/xml/DFDOM.c | 2 +-
DocFormats/core/src/xml/DFNameMap.c | 6 +--
DocFormats/core/src/xml/DFXML.c | 8 ++--
DocFormats/headers/DFPlatform.h | 8 ++++
DocFormats/platform/src/Unix.c | 4 +-
DocFormats/platform/src/Win32.c | 6 +--
DocFormats/platform/src/Wrapper.c | 51 ++++++++++++++++++++-
20 files changed, 98 insertions(+), 41 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/70c98617/DocFormats/core/src/common/DFBDT.c
----------------------------------------------------------------------
diff --git a/DocFormats/core/src/common/DFBDT.c b/DocFormats/core/src/common/DFBDT.c
index 3568668..db96e3b 100644
--- a/DocFormats/core/src/common/DFBDT.c
+++ b/DocFormats/core/src/common/DFBDT.c
@@ -51,7 +51,7 @@ void BDTContainerPut(void *ctx, DFLens *theLens, DFNode *abstract, DFNode *concr
for (DFNode *abs = abstract->first; abs != NULL; abs = abs->next)
count++;
- DFNode **conChildren = (DFNode **)malloc(count*sizeof(DFNode*));
+ DFNode **conChildren = (DFNode **)xmalloc(count*sizeof(DFNode*));
count = 0;
for (DFNode *abs = abstract->first; abs != NULL; abs = abs->next) {
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/70c98617/DocFormats/core/src/css/CSSSelector.c
----------------------------------------------------------------------
diff --git a/DocFormats/core/src/css/CSSSelector.c b/DocFormats/core/src/css/CSSSelector.c
index dcd2b81..7c2682f 100644
--- a/DocFormats/core/src/css/CSSSelector.c
+++ b/DocFormats/core/src/css/CSSSelector.c
@@ -116,7 +116,7 @@ char *CSSSelectorCopyElementName(const char *selector)
if (dotPos < 0)
return strdup(selector);
- char *result = (char *)malloc(dotPos+1);
+ char *result = (char *)xmalloc(dotPos+1);
memcpy(result,selector,dotPos);
result[dotPos] = '\0';
return result;
@@ -131,7 +131,7 @@ char *CSSSelectorCopyClassName(const char *selector)
return NULL;
int start = dotPos + 1;
int len = (int)strlen(selector) - start;
- char *result = (char *)malloc(len+1);
+ char *result = (char *)xmalloc(len+1);
memcpy(result,&selector[start],len);
result[len] = '\0';
return result;
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/70c98617/DocFormats/core/src/html/DFHTML.c
----------------------------------------------------------------------
diff --git a/DocFormats/core/src/html/DFHTML.c b/DocFormats/core/src/html/DFHTML.c
index e600517..e75c3e9 100644
--- a/DocFormats/core/src/html/DFHTML.c
+++ b/DocFormats/core/src/html/DFHTML.c
@@ -196,7 +196,7 @@ int HTML_nodeIsHyperlink(DFNode *node)
static char *indentString(int depth)
{
- char *str = (char *)malloc(1+depth*2+1);
+ char *str = (char *)xmalloc(1+depth*2+1);
str[0] = '\n';
memset(&str[1],' ',depth*2);
str[1+depth*2] = '\0';
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/70c98617/DocFormats/core/src/html/DFHTMLNormalization.c
----------------------------------------------------------------------
diff --git a/DocFormats/core/src/html/DFHTMLNormalization.c b/DocFormats/core/src/html/DFHTMLNormalization.c
index 2c91043..ccc7bb6 100644
--- a/DocFormats/core/src/html/DFHTMLNormalization.c
+++ b/DocFormats/core/src/html/DFHTMLNormalization.c
@@ -151,7 +151,7 @@ static void fixParagraphWhitespace(DFNode *paragraph)
uint32_t *oldChars = DFUTF8To32(entry->node->value);
size_t oldLen = DFUTF32Length(oldChars);
- uint32_t *newChars = (uint32_t *)malloc((oldLen+1)*sizeof(uint32_t));
+ uint32_t *newChars = (uint32_t *)xmalloc((oldLen+1)*sizeof(uint32_t));
size_t newLen = 0;
int haveSpace = 0;
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/70c98617/DocFormats/core/src/html/DFTidyHelper.c
----------------------------------------------------------------------
diff --git a/DocFormats/core/src/html/DFTidyHelper.c b/DocFormats/core/src/html/DFTidyHelper.c
index ae4294d..af9689b 100644
--- a/DocFormats/core/src/html/DFTidyHelper.c
+++ b/DocFormats/core/src/html/DFTidyHelper.c
@@ -28,7 +28,7 @@ char *copyTidyNodeValue(TidyNode tnode, TidyDoc tdoc)
tidyBufInit(&buf);
tidyNodeGetValue(tdoc,tnode,&buf);
- char *str = (char *)malloc(buf.size+1);
+ char *str = (char *)xmalloc(buf.size+1);
memcpy(str,buf.bp,buf.size);
str[buf.size] = '\0';
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/70c98617/DocFormats/core/src/lib/DFAllocator.c
----------------------------------------------------------------------
diff --git a/DocFormats/core/src/lib/DFAllocator.c b/DocFormats/core/src/lib/DFAllocator.c
index f6de4ae..27eca5d 100644
--- a/DocFormats/core/src/lib/DFAllocator.c
+++ b/DocFormats/core/src/lib/DFAllocator.c
@@ -37,8 +37,8 @@ struct DFAllocator {
DFAllocator *DFAllocatorNew(void)
{
size_t initialSize = 1;
- DFAllocator *alc = (DFAllocator *)malloc(sizeof(DFAllocator));
- alc->blocks = (DFAllocatorBlock *)malloc(sizeof(DFAllocatorBlock)+initialSize);
+ DFAllocator *alc = (DFAllocator *)xmalloc(sizeof(DFAllocator));
+ alc->blocks = (DFAllocatorBlock *)xmalloc(sizeof(DFAllocatorBlock)+initialSize);
alc->blocks->next = NULL;
alc->blocks->used = 0;
alc->blocks->size = initialSize;
@@ -66,7 +66,7 @@ void *DFAllocatorAlloc(DFAllocator *alc, size_t size)
size_t newSize = block->size*2;
while (size > newSize)
newSize *= 2;
- block = (DFAllocatorBlock *)malloc(sizeof(DFAllocatorBlock)+newSize);
+ block = (DFAllocatorBlock *)xmalloc(sizeof(DFAllocatorBlock)+newSize);
block->used = 0;
block->size = newSize;
block->next = alc->blocks;
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/70c98617/DocFormats/core/src/lib/DFArray.c
----------------------------------------------------------------------
diff --git a/DocFormats/core/src/lib/DFArray.c b/DocFormats/core/src/lib/DFArray.c
index 98b70b2..306a495 100644
--- a/DocFormats/core/src/lib/DFArray.c
+++ b/DocFormats/core/src/lib/DFArray.c
@@ -130,7 +130,7 @@ static void DFSortInternal(char *base, size_t nel, size_t width,
void DFSort(void *base, size_t nel, size_t width, void *thunk, int (*compar)(void *, const void *, const void *))
{
- void *work = malloc(nel*width);
+ void *work = xmalloc(nel*width);
DFSortInternal(base,nel,width,thunk,compar,work);
free(work);
}
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/70c98617/DocFormats/core/src/lib/DFBuffer.c
----------------------------------------------------------------------
diff --git a/DocFormats/core/src/lib/DFBuffer.c b/DocFormats/core/src/lib/DFBuffer.c
index 5527c9b..5e68f60 100644
--- a/DocFormats/core/src/lib/DFBuffer.c
+++ b/DocFormats/core/src/lib/DFBuffer.c
@@ -37,7 +37,7 @@ DFBuffer *DFBufferNew(void)
buf->retainCount = 1;
buf->alloc = 1;
buf->len = 0;
- buf->data = (char *)malloc(buf->alloc*sizeof(char));
+ buf->data = (char *)xmalloc(buf->alloc*sizeof(char));
buf->data[0] = '\0';
return buf;
}
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/70c98617/DocFormats/core/src/lib/DFError.c
----------------------------------------------------------------------
diff --git a/DocFormats/core/src/lib/DFError.c b/DocFormats/core/src/lib/DFError.c
index a03d35f..176fc29 100644
--- a/DocFormats/core/src/lib/DFError.c
+++ b/DocFormats/core/src/lib/DFError.c
@@ -44,7 +44,7 @@ void DFErrorVFormat(DFError **error, const char *format, va_list ap)
size_t nchars = vsnprintf(NULL,0,format,ap2);
va_end(ap2);
- char *message = (char *)malloc(nchars+1);
+ char *message = (char *)xmalloc(nchars+1);
va_copy(ap2,ap);
vsnprintf(message,nchars+1,format,ap2);
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/70c98617/DocFormats/core/src/lib/DFFilesystem.c
----------------------------------------------------------------------
diff --git a/DocFormats/core/src/lib/DFFilesystem.c b/DocFormats/core/src/lib/DFFilesystem.c
index 6a2b493..a96134a 100644
--- a/DocFormats/core/src/lib/DFFilesystem.c
+++ b/DocFormats/core/src/lib/DFFilesystem.c
@@ -297,7 +297,7 @@ char *DFPathWithoutExtension(const char *path)
char *DFPathNormalize(const char *path)
{
size_t len = strlen(path);
- char *result = (char *)malloc(len+1);
+ char *result = (char *)xmalloc(len+1);
size_t outpos = 0;
for (size_t pos = 0; pos < len; pos++) {
if ((path[pos] != '/') || (pos == 0) || (path[pos-1] != '/'))
@@ -374,7 +374,7 @@ static int numFromHex(uint32_t ch)
char *DFRemovePercentEncoding(const char *encoded)
{
size_t inlen = strlen(encoded);
- char *output = (char *)malloc(inlen+1);
+ char *output = (char *)xmalloc(inlen+1);
size_t outpos = 0;
for (size_t inpos = 0; inpos < inlen; inpos++) {
char ch = encoded[inpos];
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/70c98617/DocFormats/core/src/lib/DFHashTable.c
----------------------------------------------------------------------
diff --git a/DocFormats/core/src/lib/DFHashTable.c b/DocFormats/core/src/lib/DFHashTable.c
index 0559f6d..4be2d08 100644
--- a/DocFormats/core/src/lib/DFHashTable.c
+++ b/DocFormats/core/src/lib/DFHashTable.c
@@ -133,7 +133,7 @@ const char **DFHashTableCopyKeys(DFHashTable *table)
numBytes += strlen(entry->key)+1;
}
- void *mem = malloc(numBytes);
+ void *mem = xmalloc(numBytes);
char **pointers = mem;
char *storage = (char *)mem + (count+1)*sizeof(char *);
@@ -208,7 +208,7 @@ void DFHashTableAdd(DFHashTable *table, const char *key, const void *constValue)
}
else {
size_t len = strlen(key);
- DFHashEntry *entry = (DFHashEntry *)malloc(sizeof(DFHashEntry)+len*sizeof(char)+1);
+ DFHashEntry *entry = (DFHashEntry *)xmalloc(sizeof(DFHashEntry)+len*sizeof(char)+1);
entry->value = value;
entry->hash = hash;
memcpy(&entry->key[0],key,len);
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/70c98617/DocFormats/core/src/lib/DFStorage.c
----------------------------------------------------------------------
diff --git a/DocFormats/core/src/lib/DFStorage.c b/DocFormats/core/src/lib/DFStorage.c
index 3087514..3c76ce8 100644
--- a/DocFormats/core/src/lib/DFStorage.c
+++ b/DocFormats/core/src/lib/DFStorage.c
@@ -73,7 +73,7 @@ static int fsRead(DFStorage *storage, const char *path, void **buf, size_t *nbyt
size_t balloc = 4096;
size_t blen = 0;
- char *mem = (char *)malloc(balloc);
+ char *mem = (char *)xmalloc(balloc);
size_t r;
while (0 < (r = fread(&mem[blen],1,4096,file))) {
@@ -190,7 +190,7 @@ static int memRead(DFStorage *storage, const char *path, void **buf, size_t *nby
return 0;
}
- *buf = malloc(buffer->len);
+ *buf = xmalloc(buffer->len);
memcpy(*buf,buffer->data,buffer->len);
*nbytes = buffer->len;
@@ -258,7 +258,7 @@ static int zipRead(DFStorage *storage, const char *path, void **buf, size_t *nby
return 0;
}
- *buf = malloc(buffer->len);
+ *buf = xmalloc(buffer->len);
memcpy(*buf,buffer->data,buffer->len);
*nbytes = buffer->len;
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/70c98617/DocFormats/core/src/lib/DFString.c
----------------------------------------------------------------------
diff --git a/DocFormats/core/src/lib/DFString.c b/DocFormats/core/src/lib/DFString.c
index ca9ac86..e6295ca 100644
--- a/DocFormats/core/src/lib/DFString.c
+++ b/DocFormats/core/src/lib/DFString.c
@@ -59,7 +59,7 @@ static void DFArrayBuilderAdd(DFArrayBuilder *builder, const char *str, size_t s
static void DFArrayBuilderAllocate(DFArrayBuilder *builder)
{
int pointerBytes = (builder->pointerIndex + 1)*sizeof(char *);
- void *mem = malloc(pointerBytes + builder->storageIndex);
+ void *mem = xmalloc(pointerBytes + builder->storageIndex);
builder->pointers = mem;
builder->storage = (char *)mem + pointerBytes;
}
@@ -268,7 +268,7 @@ char *DFStringNormalizeWhitespace(const char *input)
size_t inputLen = strlen(input);
size_t outputLen = 0;
- char *output = (char *)malloc(inputLen+1);
+ char *output = (char *)xmalloc(inputLen+1);
size_t start = 0;
while ((start < inputLen) && isspace(input[start]))
@@ -313,7 +313,7 @@ char *DFSubstring(const char *str, size_t start, size_t end)
if (end < start)
end = start;
- char *substring = (char *)malloc(end-start+1);
+ char *substring = (char *)xmalloc(end-start+1);
memcpy(substring,&str[start],end-start);
substring[end-start] = '\0';
return substring;
@@ -367,7 +367,7 @@ char *DFVFormatString(const char *format, va_list ap)
size_t nchars = vsnprintf(NULL,0,format,ap2);
va_end(ap2);
- char *result = (char *)malloc(nchars+1);
+ char *result = (char *)xmalloc(nchars+1);
va_copy(ap2,ap);
vsnprintf(result,nchars+1,format,ap2);
@@ -547,7 +547,7 @@ char *DFQuote(const char *in)
// UTF-8 characters pass through untouched.
size_t inlen = strlen(in);
- char *out = (char*)malloc(2*inlen+3);
+ char *out = (char*)xmalloc(2*inlen+3);
size_t outlen = 0;
out[outlen++] = '"';
for (size_t i = 0; i < inlen; i++) {
@@ -602,7 +602,7 @@ char *DFUnquote(const char *in)
char quote = in[0];
size_t inlen = strlen(in);
- char *out = (char *)malloc(inlen+1);
+ char *out = (char *)xmalloc(inlen+1);
size_t outlen = 0;
size_t i = 1;
for (; i < inlen; i++) {
@@ -773,7 +773,7 @@ uint32_t *DFUTF8To32(const char *input)
while (DFNextChar(input,&inpos) != 0)
outlen++;
- uint32_t *output = (uint32_t *)malloc((outlen+1)*sizeof(uint32_t));
+ uint32_t *output = (uint32_t *)xmalloc((outlen+1)*sizeof(uint32_t));
inpos = 0;
for (size_t outpos = 0; outpos < outlen; outpos++)
output[outpos] = DFNextChar(input,&inpos);
@@ -851,7 +851,7 @@ char *DFUTF32to8(const uint32_t *input)
}
size_t outlen = DFUTF32to8n(input,NULL);
- char *output = (char *)malloc(outlen+1);
+ char *output = (char *)xmalloc(outlen+1);
DFUTF32to8n(input,output);
output[outlen] = '\0';
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/70c98617/DocFormats/core/src/xml/DFDOM.c
----------------------------------------------------------------------
diff --git a/DocFormats/core/src/xml/DFDOM.c b/DocFormats/core/src/xml/DFDOM.c
index 464cfb6..bab22f4 100644
--- a/DocFormats/core/src/xml/DFDOM.c
+++ b/DocFormats/core/src/xml/DFDOM.c
@@ -71,7 +71,7 @@ DFDocument *DFDocumentNew(void)
doc->nodesCount = 0;
doc->nodesAlloc = 1;
- doc->nodes = (DFNode **)malloc(doc->nodesAlloc*sizeof(DFNode *));
+ doc->nodes = (DFNode **)xmalloc(doc->nodesAlloc*sizeof(DFNode *));
doc->docNode = DocumentCreateNode(doc,DOM_DOCUMENT);
return doc;
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/70c98617/DocFormats/core/src/xml/DFNameMap.c
----------------------------------------------------------------------
diff --git a/DocFormats/core/src/xml/DFNameMap.c b/DocFormats/core/src/xml/DFNameMap.c
index 93430a6..f052020 100644
--- a/DocFormats/core/src/xml/DFNameMap.c
+++ b/DocFormats/core/src/xml/DFNameMap.c
@@ -79,7 +79,7 @@ static void DFNameHashTableAdd(DFNameHashTable *table, const char *name, const c
if (URI == NULL)
URI = "";;
uint32_t hash = DFNameHashTableHash(name,URI)%HASH_TABLE_SIZE;
- DFNameEntry *entry = (DFNameEntry *)malloc(sizeof(DFNameEntry));
+ DFNameEntry *entry = (DFNameEntry *)xmalloc(sizeof(DFNameEntry));
entry->name = strdup(name);
entry->URI = strdup(URI);
entry->tag = tag;
@@ -126,7 +126,7 @@ DFNamespaceInfo *DFNamespaceInfoNew(NamespaceID nsId, const char *URI, const cha
{
DFNamespaceInfo *info = (DFNamespaceInfo *)calloc(1,sizeof(DFNamespaceInfo));
info->nsId = nsId;
- info->decl = (NamespaceDecl *)malloc(sizeof(NamespaceDecl));
+ info->decl = (NamespaceDecl *)xmalloc(sizeof(NamespaceDecl));
info->decl->namespaceURI = strdup(URI);
info->decl->prefix = strdup(prefix);
return info;
@@ -157,7 +157,7 @@ DFTagInfo *DFTagInfoNew(Tag tag, NamespaceID nsId, const char *localName)
{
DFTagInfo *info = (DFTagInfo *)calloc(1,sizeof(DFTagInfo));
info->tag = tag;
- info->decl = (TagDecl *)malloc(sizeof(TagDecl));
+ info->decl = (TagDecl *)xmalloc(sizeof(TagDecl));
info->decl->namespaceID = nsId;
info->decl->localName = strdup(localName);
return info;
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/70c98617/DocFormats/core/src/xml/DFXML.c
----------------------------------------------------------------------
diff --git a/DocFormats/core/src/xml/DFXML.c b/DocFormats/core/src/xml/DFXML.c
index 0f9dfd5..e58fac5 100644
--- a/DocFormats/core/src/xml/DFXML.c
+++ b/DocFormats/core/src/xml/DFXML.c
@@ -143,7 +143,7 @@ static void SAXStartElementNS(void *ctx, const xmlChar *localname,
Tag attrTag = DFNameMapTagForName(parser->document->map,(const char *)attrURI,(const char *)attrLocalName);
const TagDecl *attrTagDecl = DFNameMapNameForTag(parser->document->map,attrTag);
- char *attrValue = (char *)malloc(attrValueLen+1);
+ char *attrValue = (char *)xmalloc(attrValueLen+1);
memcpy(attrValue,attrValueStart,attrValueLen);
attrValue[attrValueLen] = '\0';
if (parser->compatibility != NULL) {
@@ -226,7 +226,7 @@ static void SAXCharacters(void *ctx, const xmlChar *ch, int len)
DFSAXParser *parser = (DFSAXParser *)ctx;
if (parser->ignoreDepth > 0)
return;
- char *data = (char *)malloc(len+1);
+ char *data = (char *)xmalloc(len+1);
memcpy(data,ch,len);
data[len] = '\0';
DFNode *text = DFCreateTextNode(parser->document,data);
@@ -250,7 +250,7 @@ static void SAXCDATABlock(void *ctx, const xmlChar *value, int len)
DFSAXParser *parser = (DFSAXParser *)ctx;
if (parser->ignoreDepth > 0)
return;
- char *data = (char *)malloc(len+1);
+ char *data = (char *)xmalloc(len+1);
memcpy(data,value,len);
data[len] = '\0';
DFNode *cdata = DFCreateTextNode(parser->document,data);
@@ -392,7 +392,7 @@ static void writeAttributes(Serialization *serialization, DFNode *element)
{
// Sort the keys by their tag, to ensure that we always write attributes out in the same order.
// This is important for automated tests which rely on consistent output for a given XML tree.
- DFAttribute *attrs = (DFAttribute *)malloc(element->attrsCount*sizeof(DFAttribute));
+ DFAttribute *attrs = (DFAttribute *)xmalloc(element->attrsCount*sizeof(DFAttribute));
memcpy(attrs,element->attrs,element->attrsCount*sizeof(DFAttribute));
qsort(attrs,element->attrsCount,sizeof(DFAttribute),compareAttrs);
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/70c98617/DocFormats/headers/DFPlatform.h
----------------------------------------------------------------------
diff --git a/DocFormats/headers/DFPlatform.h b/DocFormats/headers/DFPlatform.h
index 3790545..faf5b6b 100755
--- a/DocFormats/headers/DFPlatform.h
+++ b/DocFormats/headers/DFPlatform.h
@@ -99,4 +99,12 @@ int DFextZipWriteCurrentFile(DFextZipHandleP zipHandle,
const void *buf,
const int len);
+void *xmalloc(size_t size);
+
+void xfree(void *ptr);
+
+void *xcalloc(size_t nmemb, size_t size);
+
+void *xrealloc(void *ptr, size_t size);
+
#endif // DocFormats_DFPlatform_h
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/70c98617/DocFormats/platform/src/Unix.c
----------------------------------------------------------------------
diff --git a/DocFormats/platform/src/Unix.c b/DocFormats/platform/src/Unix.c
index a739875..534c27b 100644
--- a/DocFormats/platform/src/Unix.c
+++ b/DocFormats/platform/src/Unix.c
@@ -80,8 +80,8 @@ int DFAddDirContents(const char *absPath, const char *relPath, int recursive, DF
size_t absSubPathLen = strlen(absPath) + 1 + strlen(result->d_name);
size_t relSubPathLen = strlen(relPath) + 1 + strlen(result->d_name);
- char *absSubPath = (char *)malloc(absSubPathLen+1);
- char *relSubPath = (char *)malloc(relSubPathLen+1);
+ char *absSubPath = (char *)xmalloc(absSubPathLen+1);
+ char *relSubPath = (char *)xmalloc(relSubPathLen+1);
snprintf(absSubPath,absSubPathLen+1,"%s/%s",absPath,result->d_name);
snprintf(relSubPath,relSubPathLen+1,"%s/%s",relPath,result->d_name);
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/70c98617/DocFormats/platform/src/Win32.c
----------------------------------------------------------------------
diff --git a/DocFormats/platform/src/Win32.c b/DocFormats/platform/src/Win32.c
index 6ac5215..ec865c5 100755
--- a/DocFormats/platform/src/Win32.c
+++ b/DocFormats/platform/src/Win32.c
@@ -92,7 +92,7 @@ int DFAddDirContents(const char *absPath, const char *relPath, int recursive, DF
HANDLE hFind = INVALID_HANDLE_VALUE;
size_t patternLen = strlen(absPath) + 2;
- char *pattern = (char *)malloc(patternLen+1);
+ char *pattern = (char *)xmalloc(patternLen+1);
snprintf(pattern,patternLen+1,"%s/*",absPath);
hFind = FindFirstFile(pattern,&ffd);
if (hFind == INVALID_HANDLE_VALUE) {
@@ -109,8 +109,8 @@ int DFAddDirContents(const char *absPath, const char *relPath, int recursive, DF
size_t absSubPathLen = strlen(absPath) + 1 + strlen(ffd.cFileName);
size_t relSubPathLen = strlen(relPath) + 1 + strlen(ffd.cFileName);
- char *absSubPath = (char *)malloc(absSubPathLen+1);
- char *relSubPath = (char *)malloc(relSubPathLen+1);
+ char *absSubPath = (char *)xmalloc(absSubPathLen+1);
+ char *relSubPath = (char *)xmalloc(relSubPathLen+1);
snprintf(absSubPath,absSubPathLen+1,"%s/%s",absPath,ffd.cFileName);
snprintf(relSubPath,relSubPathLen+1,"%s/%s",relPath,ffd.cFileName);
http://git-wip-us.apache.org/repos/asf/incubator-corinthia/blob/70c98617/DocFormats/platform/src/Wrapper.c
----------------------------------------------------------------------
diff --git a/DocFormats/platform/src/Wrapper.c b/DocFormats/platform/src/Wrapper.c
index 1c0d897..e788e96 100644
--- a/DocFormats/platform/src/Wrapper.c
+++ b/DocFormats/platform/src/Wrapper.c
@@ -17,13 +17,14 @@
#include <string.h>
#include <stdlib.h>
+#include <stdio.h>
#include "DFPlatform.h"
#include "unzip.h"
#include "zip.h"
DFextZipHandleP DFextZipOpen(const char *zipFilename, int doUnzip) {
- DFextZipHandleP zipHandle = malloc(sizeof(DFextZipHandle));
+ DFextZipHandleP zipHandle = xmalloc(sizeof(DFextZipHandle));
// no more memory
if (!zipHandle)
@@ -148,3 +149,51 @@ int DFextZipWriteCurrentFile(DFextZipHandleP zipHandle, const void *buf, const i
{
return (zipWriteInFileInZip(zipHandle->handle, buf, len) == ZIP_OK) ? 1 : -1;
}
+
+void *xmalloc(size_t size)
+{
+ void *ptr = malloc(size);
+
+ if (ptr == NULL) {
+ perror("xmalloc: out of memory.\n");
+ _exit(EXIT_FAILURE);
+ return NULL;
+ }
+ // uncomment to test this function
+ // else
+ // printf("xmalloc: %zu\n", size);
+
+ return ptr;
+}
+
+void xfree(void *ptr)
+{
+ free(ptr);
+ ptr = NULL;
+}
+
+void *xcalloc(size_t nmemb, size_t size)
+{
+ void *ptr = calloc(nmemb, size);
+
+ if (ptr == NULL) {
+ perror("xcalloc: out of memory.\n");
+ _exit(EXIT_FAILURE);
+ return NULL;
+ }
+
+ return ptr;
+}
+
+void *xrealloc(void *ptr, size_t size)
+{
+ void *ret_ptr = realloc(ptr, size);
+
+ if (ret_ptr == NULL) {
+ perror("xrealloc: out of memory.\n");
+ _exit(EXIT_FAILURE);
+ return NULL;
+ }
+
+ return ret_ptr;
+}