From e7131cfd854a54e59459bc8fa1a98e867cf0ac2b Mon Sep 17 00:00:00 2001 From: Loic Dachary Date: Mon, 1 Dec 2014 21:50:17 +0100 Subject: use assert(0) instead of exit(1) When a fatal error (unaligned memory etc.) is detected, gf-complete should assert(3) instead of exit(3) to give a chance to the calling program to catch the exception and display a stack trace. Although it is possible for gdb to display the stack trace and break on exit, libraries are not usually expected to terminate the calling program in this way. Signed-off-by: Loic Dachary (cherry picked from commit 29427efac2ce362fce8e4f5f5f1030feba942b73) --- src/gf.c | 13 +++++++------ src/gf_general.c | 3 ++- src/gf_w8.c | 3 ++- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/gf.c b/src/gf.c index 6d34c46..01a385b 100644 --- a/src/gf.c +++ b/src/gf.c @@ -11,6 +11,7 @@ #include "gf_int.h" #include #include +#include int _gf_errno = GF_E_DEFAULT; @@ -528,7 +529,7 @@ void gf_alignment_error(char *s, int a) fprintf(stderr, "Alignment error in %s:\n", s); fprintf(stderr, " The source and destination buffers must be aligned to each other,\n"); fprintf(stderr, " and they must be aligned to a %d-byte address.\n", a); - exit(1); + assert(0); } static @@ -551,7 +552,7 @@ void gf_invert_binary_matrix(uint32_t *mat, uint32_t *inv, int rows) { for (j = i+1; j < rows && (mat[j] & (1 << i)) == 0; j++) ; if (j == rows) { fprintf(stderr, "galois_invert_matrix: Matrix not invertible!!\n"); - exit(1); + assert(0); } tmp = mat[i]; mat[i] = mat[j]; mat[j] = tmp; tmp = inv[i]; inv[i] = inv[j]; inv[j] = tmp; @@ -812,7 +813,7 @@ void gf_set_region_data(gf_region_data *rd, if (h != NULL && bytes % h->w != 0) { fprintf(stderr, "Error in region multiply operation.\n"); fprintf(stderr, "The size must be a multiple of %d bytes.\n", h->w); - exit(1); + assert(0); } rd->s_start = src; @@ -828,7 +829,7 @@ void gf_set_region_data(gf_region_data *rd, fprintf(stderr, "to each other along a %d byte boundary.\n", a); fprintf(stderr, "Src = 0x%lx. Dest = 0x%lx\n", (unsigned long) src, (unsigned long) dest); - exit(1); + assert(0); } if (uls % wb != 0) { @@ -836,13 +837,13 @@ void gf_set_region_data(gf_region_data *rd, fprintf(stderr, "The pointers must be aligned along a %d byte boundary.\n", wb); fprintf(stderr, "Src = 0x%lx. Dest = 0x%lx\n", (unsigned long) src, (unsigned long) dest); - exit(1); + assert(0); } if (bytes % wb != 0) { fprintf(stderr, "Error in region multiply operation.\n"); fprintf(stderr, "The size must be a multiple of %d bytes.\n", wb); - exit(1); + assert(0); } uls %= a; diff --git a/src/gf_general.c b/src/gf_general.c index 8fcc737..7f187b5 100644 --- a/src/gf_general.c +++ b/src/gf_general.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "gf_complete.h" #include "gf_int.h" @@ -311,7 +312,7 @@ void gf_general_do_region_check(gf_t *gf, gf_general_t *a, void *orig_a, void *o if (xor) fprintf(stderr," XOR with target word: %s\n", sot); fprintf(stderr," Product word: %s\n", sft); fprintf(stderr," It should be: %s\n", ssb); - exit(0); + assert(0); } } } diff --git a/src/gf_w8.c b/src/gf_w8.c index 8449298..276799f 100644 --- a/src/gf_w8.c +++ b/src/gf_w8.c @@ -12,6 +12,7 @@ #include "gf_w8.h" #include #include +#include #define AB2(ip, am1 ,am2, b, t1, t2) {\ t1 = (b << 1) & am1;\ @@ -1168,7 +1169,7 @@ int gf_w8_table_init(gf_t *gf) scase = 2; } else { fprintf(stderr, "Internal error in gf_w8_table_init\n"); - exit(0); + assert(0); } for (a = 1; a < GF_FIELD_SIZE; a++) { -- cgit v1.2.1