MCPcopy Create free account
hub / github.com/Kitware/VTK / xmlMemoryStrdup

Function xmlMemoryStrdup

ThirdParty/libxml2/vtklibxml2/xmlmemory.c:257–288  ·  view source on GitHub ↗

* xmlMemoryStrdup: * @str: the initial string pointer * * a strdup() equivalent, with logging of the allocation info. * * Returns a pointer to the new string or NULL if allocation error occurred. */

Source from the content-addressed store, hash-verified

255 * Returns a pointer to the new string or NULL if allocation error occurred.
256 */
257char *
258xmlMemoryStrdup(const char *str) {
259 char *s;
260 size_t size = strlen(str) + 1;
261 MEMHDR *p;
262
263 xmlInitParser();
264
265 if (size > (MAX_SIZE_T - RESERVE_SIZE)) {
266 fprintf(stderr, "xmlMemoryStrdup: Unsigned overflow\n");
267 return(NULL);
268 }
269
270 p = (MEMHDR *) malloc(RESERVE_SIZE + size);
271 if (!p) {
272 fprintf(stderr, "xmlMemoryStrdup: Out of memory\n");
273 return(NULL);
274 }
275 p->mh_tag = MEMTAG;
276 p->mh_size = size;
277
278 xmlMutexLock(&xmlMemMutex);
279 debugMemSize += size;
280 debugMemBlocks++;
281 xmlMutexUnlock(&xmlMemMutex);
282
283 s = (char *) HDR_2_CLIENT(p);
284
285 memcpy(s, str, size);
286
287 return(s);
288}
289
290/**
291 * xmlMemSize:

Callers 2

xmlMemStrdupLocFunction · 0.85
myStrdupFuncFunction · 0.85

Calls 4

xmlInitParserFunction · 0.85
fprintfFunction · 0.85
xmlMutexLockFunction · 0.85
xmlMutexUnlockFunction · 0.85

Tested by

no test coverage detected