summaryrefslogtreecommitdiff
path: root/test/list.c
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2007-09-22 12:33:28 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2007-09-22 12:33:28 +0000
commit1a81ac77b1b9fd38a5f3ea7bd2125fdcd9b953dd (patch)
treee9b6f87f33b38bd0b9749667c85a0ba424580215 /test/list.c
parentfb21e068ad55fc128fa0fab53ee3326a9f5fc271 (diff)
downloadlibdom-1a81ac77b1b9fd38a5f3ea7bd2125fdcd9b953dd.tar.gz
libdom-1a81ac77b1b9fd38a5f3ea7bd2125fdcd9b953dd.tar.bz2
s/malloc.h/stdlib.h/ (malloc.h is non-standard, though common)
Sprinkle some assertions about so as to catch malloc failure at the earliest opportunity. Pedantic line length and brace position changes. svn path=/trunk/dom/; revision=3563
Diffstat (limited to 'test/list.c')
-rw-r--r--test/list.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/test/list.c b/test/list.c
index 3204237..f94b408 100644
--- a/test/list.c
+++ b/test/list.c
@@ -5,21 +5,26 @@
* Copyright 2007 James Shaw <jshaw@netsurf-browser.org>
*/
-#include <malloc.h>
-#include <stdio.h>
+#include <assert.h>
+
#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
#include "list.h"
-struct list* list_new(void) {
+struct list* list_new(void)
+{
struct list* list = malloc(sizeof(struct list));
+ assert(list != NULL);
list->size = 0;
list->head = NULL;
list->tail = NULL;
return list;
}
-void list_destroy(struct list* list) {
+void list_destroy(struct list* list)
+{
struct list_elt* elt = list->head;
while (elt != NULL) {
struct list_elt* nextElt = elt->next;
@@ -29,8 +34,10 @@ void list_destroy(struct list* list) {
free(list);
}
-void list_add(struct list* list, void* data) {
+void list_add(struct list* list, void* data)
+{
struct list_elt* elt = malloc(sizeof(struct list_elt));
+ assert(elt != NULL);
elt->data = data;
elt->next = NULL;
struct list_elt* tail = list->tail;
@@ -51,7 +58,9 @@ void list_add(struct list* list, void* data) {
list->size++;
}
-bool list_contains(struct list* list, void* data, int (*comparator)(const void* a, const void* b)) {
+bool list_contains(struct list* list, void* data,
+ int (*comparator)(const void* a, const void* b))
+{
struct list_elt* elt = list->head;
while (elt != NULL) {
if (comparator(elt->data, data) == 0) {
@@ -62,7 +71,9 @@ bool list_contains(struct list* list, void* data, int (*comparator)(const void*
return false;
}
-bool list_contains_all(struct list* superList, struct list* subList, int (*comparator)(const void* a, const void* b)) {
+bool list_contains_all(struct list* superList, struct list* subList,
+ int (*comparator)(const void* a, const void* b))
+{
struct list_elt* elt = subList->head;
while (elt != NULL) {
if (!list_contains(superList, elt->data, comparator)) {