]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
DynBuf: Implement new function DynBuf_SafeInternalInsert().
authorJohn Wolfe <jwolfe@vmware.com>
Mon, 4 Apr 2022 19:58:41 +0000 (12:58 -0700)
committerJohn Wolfe <jwolfe@vmware.com>
Mon, 4 Apr 2022 19:58:41 +0000 (12:58 -0700)
open-vm-tools/lib/include/dynbuf.h
open-vm-tools/lib/misc/dynbuf.c

index 0d87d87cb8ac18f57e556c56787491de07a116c4..9ffd2b8af44af8f37af7d69da4dc243230c04223 100644 (file)
@@ -75,7 +75,7 @@ DynBuf_Append(DynBuf *b,        // IN/OUT
               void const *data, // IN
               size_t size);     // IN
 
-Bool
+MUST_CHECK_RETURN Bool
 DynBuf_Insert(DynBuf *b,        // IN/OUT
               size_t offset,    // IN
               void const *data, // IN
@@ -98,6 +98,17 @@ DynBuf_SafeInternalAppend(DynBuf *b,            // IN/OUT
 #define DynBuf_SafeAppend(_buf, _data, _size) \
    DynBuf_SafeInternalAppend(_buf, _data, _size, __FILE__, __LINE__)
 
+void
+DynBuf_SafeInternalInsert(DynBuf *b,            // IN/OUT
+                          size_t offset,        // IN
+                          void const *data,     // IN
+                          size_t size,          // IN
+                          char const *file,     // IN
+                          unsigned int lineno); // IN
+
+#define DynBuf_SafeInsert(_buf, _offset, _data, _size) \
+   DynBuf_SafeInternalInsert(_buf, _offset, _data, _size, __FILE__, __LINE__)
+
 void
 DynBuf_SafeInternalEnlarge(DynBuf *b,            // IN/OUT
                            size_t min_size,      // IN
index ef7663e1a056aa218c99d2af6d82bb4c512ecfe6..91b87f4532d8618edf5461b0a11de1c7ecfb3ac9 100644 (file)
@@ -429,6 +429,39 @@ DynBuf_Insert(DynBuf *b,        // IN/OUT:
 }
 
 
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * DynBuf_SafeInternalInsert --
+ *
+ *      Insert data at a given offset within a dynamic buffer. Memory
+ *      allocation failure is handled the same way as Util_SafeMalloc, that is
+ *      to say, with a Panic.
+ *
+ * Results:
+ *      None
+ *
+ * Side effects:
+ *      None
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+void
+DynBuf_SafeInternalInsert(DynBuf *b,            // IN/OUT:
+                          size_t offset,        // IN:
+                          void const *data,     // IN:
+                          size_t size,          // IN:
+                          char const *file,     // IN:
+                          unsigned int lineno)  // IN:
+{
+   if (!DynBuf_Insert(b, offset, data, size)) {
+      Panic("Unrecoverable memory allocation failure at %s:%u\n",
+            file, lineno);
+   }
+}
+
+
 /*
  *-----------------------------------------------------------------------------
  *
@@ -462,7 +495,7 @@ DynBuf_Append(DynBuf *b,        // IN/OUT:
  * DynBuf_SafeInternalAppend --
  *
  *      Append data at the end of a dynamic buffer. Memory allocation failure
- *      are handled the same way as Util_SafeMalloc, that is to say, with a
+ *      is handled the same way as Util_SafeMalloc, that is to say, with a
  *      Panic.
  *
  * Results: