fix potential deref of a null pointer
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user