diff --git a/src/err.c b/src/err.c index 69dd166..567f36e 100644 --- a/src/err.c +++ b/src/err.c @@ -34,9 +34,6 @@ static struct error_stack_t stack = {files, funcs, lines, errors, messages, 0}; void push_error_stack(const char *file, const char *func, int line, int err, const char *message) { if (stack.size >= ERR_MAX_STACK_SIZE) return; /* unfortunate */ int idx = stack.size; - stack.files[idx] = files_buffer + (idx * ERR_MAX_FILENAME_LENGTH); - stack.funcs[idx] = funcs_buffer + (idx * ERR_MAX_FUNCNAME_LENGTH); - stack.messages[idx] = messages_buffer + (idx * ERR_MAX_MESSAGE_LENGTH); /* subtract 1 to ensure room for null byte in buffer */ sprintf(stack.funcs[idx], "%.*s", ERR_MAX_FUNCNAME_LENGTH - 1, func); @@ -107,3 +104,15 @@ int init_h5_error_handling() { done: return retval; } + +int init_error_handling() { + int retval = 0; + int idx = 0; + while (idx < ERR_MAX_STACK_SIZE) { + stack.files[idx] = files_buffer + (idx * ERR_MAX_FILENAME_LENGTH); + stack.funcs[idx] = funcs_buffer + (idx * ERR_MAX_FUNCNAME_LENGTH); + stack.messages[idx] = messages_buffer + (idx * ERR_MAX_MESSAGE_LENGTH); + idx++; + } + return retval; +} diff --git a/src/err.h b/src/err.h index c30f6f2..5830cc1 100644 --- a/src/err.h +++ b/src/err.h @@ -50,4 +50,6 @@ void reset_error_stack(); int init_h5_error_handling(); +int init_error_handling(); + #endif /* NXS_XDS_ERR_H */ diff --git a/src/plugin.c b/src/plugin.c index 595b955..c31609a 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -55,6 +55,8 @@ void plugin_open( int retval = 0; *error_flag = 0; + init_error_handling(); + if (H5dont_atexit() < 0) { ERROR_JUMP(-2, done, "Failed configuring HDF5 library behaviour"); } diff --git a/src/test.c b/src/test.c index 93d6d32..ec6d669 100644 --- a/src/test.c +++ b/src/test.c @@ -46,7 +46,7 @@ int main(int argc, char **argv) { int *mask = NULL; int *data = NULL; - reset_error_stack(); + init_error_handling(); if (init_h5_error_handling() < 0) { ERROR_JUMP(-1, done, ""); }