libdev.a

C Helper library
Log | Files | Refs | README | LICENSE | git clone https://git.ne02ptzero.me/git/libdev.a

commit 36e85986a2d179275589e2ab8a4bf5aad80425b1
parent b77d4e9c863eabff0a9926b3c9c313085e991e59
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Sat,  8 Oct 2016 17:47:43 +0200

Fix(Assertion): Fix the assertions in lib

Diffstat:
Mlibdev.h | 7+++----
Mlists.c | 6+++---
Mprint.c | 12++++++------
Msingleton.c | 2++
4 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/libdev.h b/libdev.h @@ -1,7 +1,6 @@ #ifndef __LIBDEV__ # define __LIBDEV__ # include <stdlib.h> -# include <assert.h> # include <string.h> # include <execinfo.h> # include <stdarg.h> @@ -30,9 +29,9 @@ #define L_ASSERT(condition)\ {\ if (!condition) {\ - fprintf(stderr, "Assertion (%s) failed at %s:%d\n", #condition, __FILE__, __LINE__);\ - fprintf(stderr, "Function: %s\n", __FUNCTION__);\ - fprintf(stderr, "Backtrace:\n");\ + warning("Assertion (%s) failed at %s:%d\n", #condition, __FILE__, __LINE__);\ + warning("Function: %s\n", __FUNCTION__);\ + warning("Backtrace:\n");\ print_trace();\ }\ } diff --git a/lists.c b/lists.c @@ -5,7 +5,7 @@ t_list *list_add_member(t_list *list, void *member, size_t size) { n_member = malloc(sizeof(t_list)); n_member->member = malloc(size); - assert(n_member && n_member->member); + L_ASSERT(n_member && n_member->member); memcpy(n_member->member, member, size); n_member->size = size; n_member->next = n_member->prev = 0x0; @@ -34,7 +34,7 @@ t_list *list_insert_after(t_list *org, t_list *ptr, void *member, size_t size) n_member = malloc(sizeof(t_list)); n_member->member = malloc(size); - assert(n_member && n_member->member); + L_ASSERT(n_member && n_member->member); memcpy(n_member->member, member, size); n_member->size = size; n_member->next = n_member->prev = 0x0; @@ -61,7 +61,7 @@ t_list *list_insert_before(t_list *org, t_list *ptr, void *member, size_t size) n_member = malloc(sizeof(t_list)); n_member->member = malloc(size); - assert(n_member && n_member->member); + L_ASSERT(n_member && n_member->member); memcpy(n_member->member, member, size); n_member->size = size; n_member->next = n_member->prev = 0x0; diff --git a/print.c b/print.c @@ -17,12 +17,12 @@ void print_trace(void) { void error(char *str, ...) { va_list ap; - write(1, "\033[0;31m> \033[0m", 13); + write(2, "\033[0;31m> \033[0m", 13); va_start(ap, str); - vprintf(str, ap); + vfprintf(stderr, str, ap); if (str[strlen(str) - 1] != '\n') - printf("\n"); - printf("\033[0;31m> Program must stop: Backtrace:\033[0m\n"); + fprintf(stderr, "\n"); + fprintf(stderr, "\033[0;31m> Program must stop: Backtrace:\033[0m\n"); print_trace(); _exit(1); } @@ -38,7 +38,7 @@ void info(char *str, ...) { void warning(char *str, ...) { va_list ap; - write(1, "\033[0;31m> \033[0m", 13); + write(2, "\033[0;31m> \033[0m", 13); va_start(ap, str); - vprintf(str, ap); + vfprintf(stderr, str, ap); } diff --git a/singleton.c b/singleton.c @@ -8,6 +8,7 @@ t_list *singleton_lists(u_char list_type, t_list *ptr) { if (ptr) { if (!list_size(index)) { member = malloc(sizeof(t_singleton)); + L_ASSERT(member); member->ptr = ptr; member->type = list_type; list_add(index, member, sizeof(t_singleton)); @@ -19,6 +20,7 @@ t_list *singleton_lists(u_char list_type, t_list *ptr) { } } member = malloc(sizeof(t_singleton)); + L_ASSERT(member); member->ptr = ptr; member->type = list_type; list_add(index, member, sizeof(t_singleton));