diff --git a/src/project.c b/src/project.c index eae6ffd..22d07a0 100644 --- a/src/project.c +++ b/src/project.c @@ -7,7 +7,7 @@ Authors: see AUTHORS Copyright: see AUTHORS License: see LICENSE - Last Updated: 04/29/2023 + Last Updated: 08/02/2023 ****************************************************************************** */ @@ -1373,10 +1373,10 @@ char *xstrcpy(char **s1, const char *s2, const size_t n) // s1 points to a valid memory location or is NULL. E.g., // the following code will likely cause a segment fault: // char *s; -// s = xstrcpy(s, "Some text"); +// s = xstrcpy(&s, "Some text"); // while this would work correctly: // char *s = NULL; -// s = xstrcpy(s, "Some text"); +// s = xstrcpy(&s, "Some text"); //---------------------------------------------------------------- { size_t n1 = 0, n2 = 0; @@ -1398,7 +1398,7 @@ char *xstrcpy(char **s1, const char *s2, const size_t n) if (n2 > n1) *s1 = realloc(*s1, (n2 + 1) * sizeof(char)); // Copy the source string into the destination string - strncpy(*s1, s2, n2+1); + if (*s1) strncpy(*s1, s2, n2+1); return *s1; } diff --git a/src/qualroute.c b/src/qualroute.c index b71f218..144be67 100644 --- a/src/qualroute.c +++ b/src/qualroute.c @@ -7,7 +7,7 @@ Description: computes water quality transport over a single time step Authors: see AUTHORS Copyright: see AUTHORS License: see LICENSE -Last Updated: 05/15/2019 +Last Updated: 08/02/2023 ****************************************************************************** */ @@ -609,7 +609,7 @@ void initsegs(Project *pr) addseg(pr, k, v, c); // Create a 2nd segment for the 2-compartment tank model - if (net->Tank[j].MixModel == MIX2) + if (!qual->OutOfMemory && net->Tank[j].MixModel == MIX2) { // ... mixing zone segment v1 = MAX(0, v - net->Tank[j].V1frac * net->Tank[j].Vmax); diff --git a/src/util/errormanager.c b/src/util/errormanager.c index 57c19de..1bda020 100644 --- a/src/util/errormanager.c +++ b/src/util/errormanager.c @@ -7,7 +7,7 @@ Authors: see AUTHORS Copyright: see AUTHORS License: see LICENSE - Last Updated: 04/02/2019 + Last Updated: 08/02/2023 ****************************************************************************** */ @@ -36,6 +36,7 @@ error_handle_t *create_error_manager(void (*p_error_message)(int, char*, int)) { error_handle_t *error_handle; error_handle = (error_handle_t*)calloc(1, sizeof(error_handle_t)); + if (error_handle == NULL) return NULL; error_handle->p_msg_lookup = p_error_message; diff --git a/src/util/filemanager.c b/src/util/filemanager.c index 79a45d2..c06b434 100644 --- a/src/util/filemanager.c +++ b/src/util/filemanager.c @@ -7,7 +7,7 @@ Authors: see AUTHORS Copyright: see AUTHORS License: see LICENSE - Last Updated: 04/01/2019 + Last Updated: 08/02/2023 ****************************************************************************** */ @@ -41,6 +41,7 @@ file_handle_t *create_file_manager() { file_handle_t *file_handle; file_handle = (file_handle_t *)calloc(1, sizeof(file_handle_t)); + if (file_handle == NULL) return NULL; file_handle->filename = NULL; file_handle->file = NULL;