summaryrefslogtreecommitdiff
path: root/src/test/mock_queue.c
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2021-09-28 22:44:30 -0500
committersanine <sanine.not@pm.me>2021-09-28 22:44:30 -0500
commit0e8f26743214b903f66eb732e4a8c151213d61e1 (patch)
tree03a0398894cd39fbd9d2d46a42f8176ef3943cd0 /src/test/mock_queue.c
parentbedf73313c8f19ff1b19217d989b1886c8f809ae (diff)
add mock_queue_cleanup() function and move queue malloc call inside mock_queue_data
Diffstat (limited to 'src/test/mock_queue.c')
-rw-r--r--src/test/mock_queue.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/test/mock_queue.c b/src/test/mock_queue.c
index 10ce834..7a36b65 100644
--- a/src/test/mock_queue.c
+++ b/src/test/mock_queue.c
@@ -1,5 +1,6 @@
#include <stdlib.h>
#include <stdio.h>
+#include <string.h>
#include "mock_queue.h"
@@ -35,7 +36,13 @@ void mock_queue_data(size_t size, void *data)
return;
}
- node->data = data;
+ node->data = malloc(size);
+ if (node->data == NULL) {
+ fprintf(stderr, "WARNING: memory allocation of %zu bytes for mock queue data failed!\n", size);
+ return;
+ }
+
+ memcpy(node->data, data, size);
node->next = NULL;
mock_queue_tail->next = node;
mock_queue_tail = node;
@@ -67,3 +74,10 @@ void mock_pop()
mock_queue_tail = &mock_queue_head;
mock_queue_length -= 1;
}
+
+
+void mock_queue_cleanup()
+{
+ while(mock_queue_length != 0)
+ mock_pop();
+}