]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Add Safe version of DynBuf_Enlarge
authorOliver Kurth <okurth@vmware.com>
Tue, 5 Jun 2018 22:47:38 +0000 (15:47 -0700)
committerOliver Kurth <okurth@vmware.com>
Tue, 5 Jun 2018 22:47:38 +0000 (15:47 -0700)
This change adds the "safe" variant of the enlarge interface. Similar to
DynBuf_SafeAppend, this panics when the buffer enlargement fails due to
memory allocation failures.

open-vm-tools/lib/include/dynbuf.h
open-vm-tools/lib/misc/dynbuf.c

index b2541ee1bf32dd5e9b3d317f0a0b349e0c5d0728..f9978cc243ace4b8df34db5f8326e1face36e443 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 1998-2017 VMware, Inc. All rights reserved.
+ * Copyright (C) 1998-2018 VMware, Inc. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published
@@ -88,6 +88,15 @@ DynBuf_SafeInternalAppend(DynBuf *b,            // IN/OUT
 #define DynBuf_SafeAppend(_buf, _data, _size) \
    DynBuf_SafeInternalAppend(_buf, _data, _size, __FILE__, __LINE__)
 
+void
+DynBuf_SafeInternalEnlarge(DynBuf *b,            // IN/OUT
+                           size_t min_size,      // IN
+                           char const *file,     // IN
+                           unsigned int lineno); // IN
+
+#define DynBuf_SafeEnlarge(_buf, _min_size) \
+   DynBuf_SafeInternalEnlarge(_buf,  _min_size, __FILE__, __LINE__)
+
 
 /*
  *-----------------------------------------------------------------------------
index 76b250a5d09b253b8ccee7e892bd9b7b175d4bac..dc36d07086e03e117ed87decdf612f034c86e564 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 1998-2017 VMware, Inc. All rights reserved.
+ * Copyright (C) 1998-2018 VMware, Inc. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published
@@ -313,6 +313,36 @@ DynBuf_Enlarge(DynBuf *b,       // IN/OUT:
 }
 
 
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * DynBuf_SafeInternalEnlarge --
+ *
+ *      Enlarge 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_SafeInternalEnlarge(DynBuf *b,           // IN/OUT:
+                           size_t minSize,      // IN:
+                           char const *file,    // IN:
+                           unsigned int lineno) // IN:
+{
+   if (!DynBuf_Enlarge(b, minSize)) {
+      Panic("Unrecoverable memory allocation failure at %s:%u\n",
+            file, lineno);
+   }
+}
+
+
 /*
  *-----------------------------------------------------------------------------
  *