From a15f2abef1463c20bc62a455e983e34b2278f279 Mon Sep 17 00:00:00 2001
From: David Kilzer <ddkilzer@webkit.org>
Date: Fri, 8 Apr 2022 12:16:51 -0700
Subject: [PATCH 260/300] Use UPDATE_COMPAT() consistently in buf.c

* buf.c:
(xmlBufCreate):
(xmlBufCreateSize):
(xmlBufDetach):
(xmlBufCreateStatic):
(xmlBufFromBuffer):

Reference:https://github.com/GNOME/libxml2/commit/a15f2abef1463c20bc62a455e983e34b2278f279
Conflict:Context adaptation

---
 buf.c | 20 +++++---------------
 1 file changed, 5 insertions(+), 15 deletions(-)

diff --git a/buf.c b/buf.c
index 40a5ee0..d341750 100644
--- a/buf.c
+++ b/buf.c
@@ -131,12 +131,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) {
@@ -167,13 +166,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 + 1 : 0);         /* +1 for ending null */
-    ret->compat_size = (ret->size > INT_MAX ? INT_MAX : ret->size);
+    UPDATE_COMPAT(ret);
     if (ret->size){
         ret->content = (xmlChar *) xmlMallocAtomic(ret->size * sizeof(xmlChar));
         if (ret->content == NULL) {
@@ -215,8 +213,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;
 }
@@ -245,15 +242,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;
@@ -1159,8 +1150,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;
-- 
2.27.0

