From 3fba5b69a9b36ff33a5496a547d8ac775c210b2f Mon Sep 17 00:00:00 2001 From: tTh Date: Tue, 13 Nov 2018 15:30:55 +0100 Subject: [PATCH] more sanity check, who are untested --- bubulles.c | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/bubulles.c b/bubulles.c index 65d564e..cea23c1 100644 --- a/bubulles.c +++ b/bubulles.c @@ -1,5 +1,7 @@ /* - bubulles.c + ---------- bubulles.c ---------------------------- + + some functions for managing bubulles in a 3D space. */ #include @@ -65,7 +67,7 @@ if (NULL==(array = calloc(sz, sizeof(Bubulle)))) { bblptr->bbs = array; #if DEBUG_LEVEL -fprintf(stderr, "\t\tbblptr is at %p\n", bblptr); +fprintf(stderr, "\tbblptr is at %p\n", bblptr); #endif return bblptr; @@ -76,7 +78,7 @@ int free_bubulles(BBList *bbl, int k) if (NULL == bbl->bbs) { fprintf(stderr, "%s : array ptr is null\n", __func__); -#if MUST_ABORT +#ifdef MUST_ABORT abort(); #endif return 1; @@ -100,7 +102,7 @@ fprintf(stderr, ">>> %s ( %p %d )\n", __func__, where, idx); if ( (idx < 0) || (idx > where->fidx) ) { fprintf(stderr, "%s : idx %d out of range on %p\n", __func__, idx, where); -#if MUST_ABORT +#ifdef MUST_ABORT abort(); #endif return NULL; @@ -181,6 +183,14 @@ return 0; int peek_bubulle(BBList *from, Bubulle *to, int idx) { +if (NULL==from) { + fprintf(stderr, "in %s, *from is null\n", __func__); +#ifdef MUST_ABORT + abort(); +#endif + return -5; + } + if ((idx < 0) || (idx > from->size)) { #if DEBUG_LEVEL fprintf(stderr, "%s : idx %d out of range\n", __func__, idx); @@ -190,7 +200,6 @@ if ((idx < 0) || (idx > from->size)) { memcpy(to, &from->bbs[idx], sizeof(Bubulle)); - return 0; } /* --------------------------------------------------------------------- */ @@ -203,6 +212,14 @@ int fprint_bubulles(FILE *fp, char *title, BBList *bbl, int flags) int idx; Bubulle *ar; +if (NULL == bbl) { + fprintf(stderr, "in %s, *bbl is NULL\n", __func__); +#ifdef MUST_ABORT + abort(); +#endif + return -5; + } + ar = bbl->bbs; #if DEBUG_LEVEL > 1 @@ -243,7 +260,10 @@ int idx; if (NULL == what) { fprintf(stderr, "SHIT HAPPEN IN %s\n", __func__); +#ifdef MUST_ABORT abort(); +#endif + return -5; } ar = what->bbs; /* get the bubble array addr */ @@ -311,6 +331,14 @@ return 0; int print_bbox(BBox *bbox, int k) { +if (NULL==bbox) { + fprintf(stderr, "in %s, *bbox is NULL\n", __func__); +#ifdef MUST_ABORT + abort(); +#endif + return -5; + } + printf("%9.6f %9.6f %9.6f %9.6f %9.6f %9.6f\n", bbox->minX, bbox->minY, bbox->minZ, bbox->maxX, bbox->maxY, bbox->maxZ);