From 1671ca8d670ed03a7d53d0fc4e097746373ab637 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Mon, 21 Dec 2020 15:16:16 +0100 Subject: [PATCH] Add more assertions --- m-deque.h | 4 ++-- m-dict.h | 1 + m-string.h | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/m-deque.h b/m-deque.h index 89f47b3b..84dd76a2 100644 --- a/m-deque.h +++ b/m-deque.h @@ -373,7 +373,7 @@ M_C(name, _node_list_push_front)(d->list, next); \ } \ n = M_C(name, _node_list_previous_obj)(d->list, n); \ - M_ASSERT (n != NULL); \ + M_ASSERT (n != NULL && n->size > 1); \ d->back->node = n; \ index = n->size-1; \ } \ @@ -543,7 +543,7 @@ it->deque = d; \ if (M_UNLIKELY (it->index >= it->node->size)) { \ it->node = M_C(name, _node_list_previous_obj)(d->list, it->node); \ - M_ASSERT (it->node != NULL); \ + M_ASSERT (it->node != NULL && it->node->size > 1); \ it->index = it->node->size-1; \ } \ } \ diff --git a/m-dict.h b/m-dict.h index e4beb773..9e41ad71 100644 --- a/m-dict.h +++ b/m-dict.h @@ -490,6 +490,7 @@ if (M_UNLIKELY (new_size <= old_size)) { \ M_MEMORY_FULL((size_t)-1); \ } \ + M_ASSERT (old_size > 1 && new_size > 1); \ /* Resize the table of the dictionnary */ \ M_C(name, _array_list_pair_resize)(map->table, new_size); \ /* Move the items to the new upper part */ \ diff --git a/m-string.h b/m-string.h index 88843abe..a9bff87a 100644 --- a/m-string.h +++ b/m-string.h @@ -826,6 +826,7 @@ stringi_replace_all_str_1ge2 (string_t v, const char str1[], size_t str1len, con static inline char * stringi_strstr_r(char org[], char src[], const char pattern[], size_t pattern_size) { + M_ASSERT(pattern_size >= 1); src -= pattern_size - 1; while (org <= src) { if (src[0] == pattern[0] @@ -1005,6 +1006,7 @@ string_fgets(string_t v, FILE *f, string_fgets_t arg) retcode = true; /* Something has been read */ // fgets doesn't return the number of characters read, so we need to count. size += strlen(&ptr[size]); + assert(size >= 1); if (arg != STRING_READ_FILE && ptr[size-1] == '\n') { if (arg == STRING_READ_PURE_LINE) { size --;