aboutsummaryrefslogtreecommitdiff
path: root/include/list.h
diff options
context:
space:
mode:
authorAndrea Fioraldi <andreafioraldi@gmail.com>2020-04-03 09:39:12 +0200
committerAndrea Fioraldi <andreafioraldi@gmail.com>2020-04-03 09:39:12 +0200
commit8610b0e40677846ba65de55fcaedd2ebee66a511 (patch)
treef5b6409fe840ac69417e348795b69cbeb0a072fc /include/list.h
parentffb4767fc1adf2383173e5655d4f1fcf7e0982b6 (diff)
parent97cae2df9975589eb05a543f92c6ba232242fd7b (diff)
downloadafl++-8610b0e40677846ba65de55fcaedd2ebee66a511.tar.gz
Merge branch 'dev' of github.com:vanhauser-thc/AFLplusplus into dev
Diffstat (limited to 'include/list.h')
-rw-r--r--include/list.h49
1 files changed, 25 insertions, 24 deletions
diff --git a/include/list.h b/include/list.h
index 1190931f..e93b4e8f 100644
--- a/include/list.h
+++ b/include/list.h
@@ -34,8 +34,8 @@
#include "debug.h"
#include "afl-prealloc.h"
-#define LIST_PREALLOC_SIZE \
- (64) /* How many elements to allocate before malloc is needed */
+/* How many elements to allocate before malloc is needed */
+#define LIST_PREALLOC_SIZE (64)
typedef struct list_element {
@@ -56,17 +56,18 @@ typedef struct list {
static inline element_t *get_head(list_t *list) {
- return &list->element_prealloc_buf[0];
+ /* The first element is the head */
+ return list->element_prealloc_buf;
}
-static void list_free_el(list_t *list, element_t *el) {
+static inline void list_free_el(list_t *list, element_t *el) {
PRE_FREE(el, list->element_prealloc_count);
}
-static void list_append(list_t *list, void *el) {
+static inline void list_append(list_t *list, void *el) {
element_t *head = get_head(list);
if (!head->next) {
@@ -97,23 +98,23 @@ static void list_append(list_t *list, void *el) {
A return from this block will return from calling func.
*/
-#define LIST_FOREACH(list, type, block) \
- do { \
- \
- list_t * li = (list); \
- element_t *head = get_head((li)); \
- element_t *el_box = (head)->next; \
- if (!el_box) FATAL("foreach over uninitialized list"); \
- while (el_box != head) { \
- \
- type *el = (type *)((el_box)->data); \
- /* get next so el_box can be unlinked */ \
- element_t *next = el_box->next; \
- {block}; \
- el_box = next; \
- \
- } \
- \
+#define LIST_FOREACH(list, type, block) \
+ do { \
+ \
+ list_t * li = (list); \
+ element_t *head = get_head((li)); \
+ element_t *el_box = (head)->next; \
+ if (!el_box) FATAL("foreach over uninitialized list"); \
+ while (el_box != head) { \
+ \
+ __attribute__((unused)) type *el = (type *)((el_box)->data); \
+ /* get next so el_box can be unlinked */ \
+ element_t *next = el_box->next; \
+ {block}; \
+ el_box = next; \
+ \
+ } \
+ \
} while (0);
/* In foreach: remove the current el from the list */
@@ -143,7 +144,7 @@ static void list_append(list_t *list, void *el) {
/* remove an item from the list */
-static void list_remove(list_t *list, void *remove_me) {
+static inline void list_remove(list_t *list, void *remove_me) {
LIST_FOREACH(list, void, {
@@ -165,7 +166,7 @@ static void list_remove(list_t *list, void *remove_me) {
/* Returns true if el is in list */
-static bool list_contains(list_t *list, void *contains_me) {
+static inline bool list_contains(list_t *list, void *contains_me) {
LIST_FOREACH(list, void, {