|
@@ -32,6 +32,7 @@
|
|
|
#include <stdlib.h>
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <misc/debug.h>
|
|
#include <misc/debug.h>
|
|
|
|
|
+#include <misc/bsize.h>
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Allocates memory.
|
|
* Allocates memory.
|
|
@@ -51,6 +52,16 @@ static void * BAlloc (size_t bytes);
|
|
|
*/
|
|
*/
|
|
|
static void BFree (void *m);
|
|
static void BFree (void *m);
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * Allocates memory, with size given as a {@link bsize_t}.
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param bytes number of bytes to allocate. If the size is overflow,
|
|
|
|
|
+ * this function will return NULL.
|
|
|
|
|
+ * @return a non-NULL pointer to the memory, or NULL on failure.
|
|
|
|
|
+ * The memory allocated can be freed using {@link BFree}.
|
|
|
|
|
+ */
|
|
|
|
|
+static void * BAllocSize (bsize_t bytes);
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* Allocates memory for an array.
|
|
* Allocates memory for an array.
|
|
|
* A check is first done to make sure the multiplication doesn't overflow;
|
|
* A check is first done to make sure the multiplication doesn't overflow;
|
|
@@ -91,6 +102,15 @@ void BFree (void *m)
|
|
|
free(m);
|
|
free(m);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+void * BAllocSize (bsize_t bytes)
|
|
|
|
|
+{
|
|
|
|
|
+ if (bytes.is_overflow) {
|
|
|
|
|
+ return NULL;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return BAlloc(bytes.value);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
void * BAllocArray (size_t count, size_t bytes)
|
|
void * BAllocArray (size_t count, size_t bytes)
|
|
|
{
|
|
{
|
|
|
if (count == 0 || bytes == 0) {
|
|
if (count == 0 || bytes == 0) {
|