1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-01-29 21:46:59 +03:00

Use UPDATE_COMPAT() consistently in buf.c

* buf.c:
(xmlBufCreate):
(xmlBufCreateSize):
(xmlBufDetach):
(xmlBufCreateStatic):
(xmlBufFromBuffer):
This commit is contained in:
David Kilzer 2022-04-08 12:16:51 -07:00 committed by Nick Wellnhofer
parent 41afa89fc9
commit a15f2abef1

20
buf.c
View File

@ -123,12 +123,11 @@ xmlBufCreate(void) {
xmlBufMemoryError(NULL, "creating buffer");
return(NULL);
}
ret->compat_use = 0;
ret->use = 0;
ret->error = 0;
ret->buffer = NULL;
ret->size = xmlDefaultBufferSize;
ret->compat_size = xmlDefaultBufferSize;
UPDATE_COMPAT(ret);
ret->alloc = xmlBufferAllocScheme;
ret->content = (xmlChar *) xmlMallocAtomic(ret->size * sizeof(xmlChar));
if (ret->content == NULL) {
@ -157,13 +156,12 @@ xmlBufCreateSize(size_t size) {
xmlBufMemoryError(NULL, "creating buffer");
return(NULL);
}
ret->compat_use = 0;
ret->use = 0;
ret->error = 0;
ret->buffer = NULL;
ret->alloc = xmlBufferAllocScheme;
ret->size = (size ? size+2 : 0); /* +1 for ending null */
ret->compat_size = (int) ret->size;
UPDATE_COMPAT(ret);
if (ret->size){
ret->content = (xmlChar *) xmlMallocAtomic(ret->size * sizeof(xmlChar));
if (ret->content == NULL) {
@ -205,8 +203,7 @@ xmlBufDetach(xmlBufPtr buf) {
buf->content = NULL;
buf->size = 0;
buf->use = 0;
buf->compat_use = 0;
buf->compat_size = 0;
UPDATE_COMPAT(buf);
return ret;
}
@ -235,15 +232,9 @@ xmlBufCreateStatic(void *mem, size_t size) {
xmlBufMemoryError(NULL, "creating buffer");
return(NULL);
}
if (size < INT_MAX) {
ret->compat_use = size;
ret->compat_size = size;
} else {
ret->compat_use = INT_MAX;
ret->compat_size = INT_MAX;
}
ret->use = size;
ret->size = size;
UPDATE_COMPAT(ret);
ret->alloc = XML_BUFFER_ALLOC_IMMUTABLE;
ret->content = (xmlChar *) mem;
ret->error = 0;
@ -1173,8 +1164,7 @@ xmlBufFromBuffer(xmlBufferPtr buffer) {
}
ret->use = buffer->use;
ret->size = buffer->size;
ret->compat_use = buffer->use;
ret->compat_size = buffer->size;
UPDATE_COMPAT(ret);
ret->error = 0;
ret->buffer = buffer;
ret->alloc = buffer->alloc;