Author: jmb
Date: Sat Sep 22 13:33:28 2007
New Revision: 3563
URL:
http://source.netsurf-browser.org?rev=3563&view=rev
Log:
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.
Modified:
trunk/dom/test/list.c
trunk/dom/test/list.h
Modified: trunk/dom/test/list.c
URL:
http://source.netsurf-browser.org/trunk/dom/test/list.c?rev=3563&r1=3...
==============================================================================
--- trunk/dom/test/list.c (original)
+++ trunk/dom/test/list.c Sat Sep 22 13:33:28 2007
@@ -5,21 +5,26 @@
* Copyright 2007 James Shaw <jshaw(a)netsurf-browser.org>
*/
-#include <malloc.h>
+#include <assert.h>
+
+#include <stdbool.h>
#include <stdio.h>
-#include <stdbool.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 @@
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 @@
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 @@
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)) {
Modified: trunk/dom/test/list.h
URL:
http://source.netsurf-browser.org/trunk/dom/test/list.h?rev=3563&r1=3...
==============================================================================
--- trunk/dom/test/list.h (original)
+++ trunk/dom/test/list.h Sat Sep 22 13:33:28 2007
@@ -30,11 +30,13 @@
/**
* Tests if data is equal to any element in the list.
*/
-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));
/**
* Tests if superlist contains all elements in sublist. Order is not important.
*/
-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));
#endif