fixed some of the easier clang++ scan-build bugs

git-svn-id: svn://136.177.114.72/svn_GW/phreeqc3/trunk@8907 1feff8c3-07ed-0310-ac33-dd36852eb9cd
This commit is contained in:
Scott R Charlton 2014-08-05 02:51:35 +00:00
parent fbb95d10b0
commit f1438518eb
7 changed files with 139 additions and 74 deletions

View File

@ -3158,10 +3158,15 @@ factor(struct LOC_exec * LINK)
(size_t) (s_v.count_subscripts +
1) * sizeof(int));
if (s_v.subscripts == NULL)
{
PhreeqcPtr->malloc_error();
}
else
{
s_v.subscripts[s_v.count_subscripts] = j;
s_v.count_subscripts++;
}
}
else
{
/* get right parentheses */
@ -5154,7 +5159,11 @@ cmdon(struct LOC_exec *LINK)
{
l = (looprec *) PhreeqcPtr->PHRQ_calloc(1, sizeof(looprec));
if (l == NULL)
{
PhreeqcPtr->malloc_error();
}
else
{
l->next = loopbase;
loopbase = l;
l->kind = gosubloop;
@ -5162,6 +5171,7 @@ cmdon(struct LOC_exec *LINK)
l->hometok = LINK->t;
LINK->t = LINK->t->next;
}
}
else
require(tokgoto, LINK);
if (i < 1)

View File

@ -28,17 +28,19 @@ m_next_keyword(Keywords::KEY_NONE)
{
error_msg("This parser constructor requires non-null phrq_io", PHRQ_io::OT_STOP);
}
m_line_save = io->Get_m_line();
m_line = io->Get_m_line();
m_line_type = io->Get_m_line_type();
m_line_iss.str(m_line);
m_line_iss.seekg(0, std::ios_base::beg);
m_line_iss.clear();
echo_file = EO_ALL;
echo_stream = EO_NONE;
accumulate = false;
phrq_io_only = true;
else
{
m_line_save = io->Get_m_line();
m_line = io->Get_m_line();
m_line_type = io->Get_m_line_type();
m_line_iss.str(m_line);
m_line_iss.seekg(0, std::ios_base::beg);
m_line_iss.clear();
echo_file = EO_ALL;
echo_stream = EO_NONE;
accumulate = false;
phrq_io_only = true;
}
}
CParser::CParser(std::istream & input, PHRQ_io *io):

View File

@ -229,11 +229,16 @@ read_calculate_values(void)
calculate_value_ptr->commands =
(char *) PHRQ_malloc(sizeof(char));
if (calculate_value_ptr->commands == NULL)
{
malloc_error();
calculate_value_ptr->commands[0] = '\0';
calculate_value_ptr->linebase = NULL;
calculate_value_ptr->varbase = NULL;
calculate_value_ptr->loopbase = NULL;
}
else
{
calculate_value_ptr->commands[0] = '\0';
calculate_value_ptr->linebase = NULL;
calculate_value_ptr->varbase = NULL;
calculate_value_ptr->loopbase = NULL;
}
opt_save = OPT_1;
break;
@ -1518,15 +1523,18 @@ master_isotope_init(struct master_isotope *master_isotope_ptr)
/*
* set pointers in structure to NULL
*/
master_isotope_ptr->name = NULL;
master_isotope_ptr->master = NULL;
master_isotope_ptr->elt = NULL;
master_isotope_ptr->units = NULL;
master_isotope_ptr->standard = 0;
master_isotope_ptr->ratio = 0;
master_isotope_ptr->moles = 0;
master_isotope_ptr->total_is_major = 0;
master_isotope_ptr->minor_isotope = 1;
if (master_isotope_ptr)
{
master_isotope_ptr->name = NULL;
master_isotope_ptr->master = NULL;
master_isotope_ptr->elt = NULL;
master_isotope_ptr->units = NULL;
master_isotope_ptr->standard = 0;
master_isotope_ptr->ratio = 0;
master_isotope_ptr->moles = 0;
master_isotope_ptr->total_is_major = 0;
master_isotope_ptr->minor_isotope = 1;
}
return (OK);
}
@ -1685,11 +1693,14 @@ calculate_value_init(struct calculate_value *calculate_value_ptr)
/*
* set pointers in structure to NULL
*/
calculate_value_ptr->name = NULL;
calculate_value_ptr->commands = NULL;
calculate_value_ptr->linebase = NULL;
calculate_value_ptr->varbase = NULL;
calculate_value_ptr->loopbase = NULL;
if (calculate_value_ptr)
{
calculate_value_ptr->name = NULL;
calculate_value_ptr->commands = NULL;
calculate_value_ptr->linebase = NULL;
calculate_value_ptr->varbase = NULL;
calculate_value_ptr->loopbase = NULL;
}
return (OK);
}
@ -1869,10 +1880,13 @@ isotope_ratio_init(struct isotope_ratio *isotope_ratio_ptr)
/*
* set pointers in structure to NULL
*/
isotope_ratio_ptr->name = NULL;
isotope_ratio_ptr->isotope_name = NULL;
isotope_ratio_ptr->ratio = MISSING;
isotope_ratio_ptr->converted_ratio = MISSING;
if (isotope_ratio_ptr)
{
isotope_ratio_ptr->name = NULL;
isotope_ratio_ptr->isotope_name = NULL;
isotope_ratio_ptr->ratio = MISSING;
isotope_ratio_ptr->converted_ratio = MISSING;
}
return (OK);
}
@ -2028,9 +2042,12 @@ isotope_alpha_init(struct isotope_alpha *isotope_alpha_ptr)
/*
* set pointers in structure to NULL
*/
isotope_alpha_ptr->name = NULL;
isotope_alpha_ptr->named_logk = NULL;
isotope_alpha_ptr->value = MISSING;
if (isotope_alpha_ptr)
{
isotope_alpha_ptr->name = NULL;
isotope_alpha_ptr->named_logk = NULL;
isotope_alpha_ptr->value = MISSING;
}
return (OK);
}

View File

@ -151,13 +151,18 @@ parse_eq(char *eqn, struct elt_list **elt_ptr, int association)
(struct elt_list *) PHRQ_malloc((size_t) (count_elts + 1) *
sizeof(struct elt_list));
if (*elt_ptr == NULL)
malloc_error();
for (i = 0; i < count_elts; i++)
{
(*elt_ptr)[i].elt = elt_list[i].elt;
(*elt_ptr)[i].coef = -elt_list[i].coef;
malloc_error();
}
else
{
for (i = 0; i < count_elts; i++)
{
(*elt_ptr)[i].elt = elt_list[i].elt;
(*elt_ptr)[i].coef = -elt_list[i].coef;
}
(*elt_ptr)[count_elts].elt = NULL;
}
(*elt_ptr)[count_elts].elt = NULL;
/*
* Debugging print of parsed equation
trxn_print();

View File

@ -2877,7 +2877,10 @@ add_potential_factor(void)
"No potential unknown found for surface species %s.", token.c_str());
error_msg(error_string, STOP);
}
master_ptr = unknown_ptr->master[0]; /* potential for surface component */
else
{
master_ptr = unknown_ptr->master[0]; /* potential for surface component */
}
/*
* Make sure there is space
*/
@ -4639,9 +4642,14 @@ unknown_alloc_master(void)
master_ptr = (struct master **) PHRQ_malloc(2 * sizeof(struct master *));
if (master_ptr == NULL)
{
malloc_error();
master_ptr[0] = NULL;
master_ptr[1] = NULL;
}
else
{
master_ptr[0] = NULL;
master_ptr[1] = NULL;
}
return (master_ptr);
}

View File

@ -840,11 +840,14 @@ read_exchange_species(void)
error_string = sformatf( "Copying exchange to phases.");
error_msg(error_string, CONTINUE);
}
phase_ptr->formula = s_ptr->name;
phase_ptr->check_equation = FALSE;
phase_ptr->type = EX;
phase_ptr->next_elt = elt_list_dup(s_ptr->next_elt);
phase_ptr->rxn = rxn_dup(s_ptr->rxn);
else
{
phase_ptr->formula = s_ptr->name;
phase_ptr->check_equation = FALSE;
phase_ptr->type = EX;
phase_ptr->next_elt = elt_list_dup(s_ptr->next_elt);
phase_ptr->rxn = rxn_dup(s_ptr->rxn);
}
break;
}
if (return_value == EOF || return_value == KEYWORD)
@ -9158,12 +9161,17 @@ read_rates(void)
rate_ptr->new_def = TRUE;
rate_ptr->commands = (char *) PHRQ_malloc(sizeof(char));
if (rate_ptr->commands == NULL)
{
malloc_error();
rate_ptr->commands[0] = '\0';
rate_ptr->name = string_hsave(token);
rate_ptr->linebase = NULL;
rate_ptr->varbase = NULL;
rate_ptr->loopbase = NULL;
}
else
{
rate_ptr->commands[0] = '\0';
rate_ptr->name = string_hsave(token);
rate_ptr->linebase = NULL;
rate_ptr->varbase = NULL;
rate_ptr->loopbase = NULL;
}
opt_save = OPT_1;
break;
case OPT_1: /* read command */
@ -9392,7 +9400,7 @@ read_user_punch(void)
{
r->commands = (char *) PHRQ_malloc(sizeof(char));
if (r->commands == NULL) malloc_error();
r->commands[0] = '\0';
else r->commands[0] = '\0';
}
//rate_free(user_punch);
//user_punch->new_def = TRUE;
@ -9410,11 +9418,16 @@ read_user_punch(void)
line_length = (int) strlen(line);
r->commands = (char *) PHRQ_realloc(r->commands,
(size_t) (length + line_length + 2) * sizeof(char));
if (r->commands == NULL) malloc_error();
r->commands[length] = ';';
r->commands[length + 1] = '\0';
strcat((r->commands), line);
if (r->commands == NULL)
{
malloc_error();
}
else
{
r->commands[length] = ';';
r->commands[length + 1] = '\0';
strcat((r->commands), line);
}
//length = (int) strlen(user_punch->commands);
//line_length = (int) strlen(line);
//user_punch->commands =

View File

@ -667,13 +667,18 @@ elt_list_save(void)
(struct elt_list *) PHRQ_malloc((size_t) (count_elts + 1) *
sizeof(struct elt_list));
if (elt_list_ptr == NULL)
malloc_error();
for (j = 0; j < count_elts; j++)
{
elt_list_ptr[j].elt = elt_list[j].elt;
elt_list_ptr[j].coef = elt_list[j].coef;
malloc_error();
}
else
{
for (j = 0; j < count_elts; j++)
{
elt_list_ptr[j].elt = elt_list[j].elt;
elt_list_ptr[j].coef = elt_list[j].coef;
}
elt_list_ptr[count_elts].elt = NULL;
}
elt_list_ptr[count_elts].elt = NULL;
return (elt_list_ptr);
}
/* ---------------------------------------------------------------------- */
@ -686,17 +691,22 @@ NameDouble2elt_list(const cxxNameDouble &nd)
*/
struct elt_list *elt_list_ptr = (struct elt_list *) PHRQ_malloc((nd.size() + 1) * sizeof(struct elt_list));
if (elt_list_ptr == NULL)
malloc_error();
cxxNameDouble::const_iterator it = nd.begin();
int i = 0;
for( ; it != nd.end(); it++)
{
elt_list_ptr[i].elt = element_store(it->first.c_str());
elt_list_ptr[i].coef = it->second;
i++;
malloc_error();
}
else
{
cxxNameDouble::const_iterator it = nd.begin();
int i = 0;
for( ; it != nd.end(); it++)
{
elt_list_ptr[i].elt = element_store(it->first.c_str());
elt_list_ptr[i].coef = it->second;
i++;
}
elt_list_ptr[i].elt = NULL;
elt_list_ptr[i].coef = 0;
}
elt_list_ptr[i].elt = NULL;
elt_list_ptr[i].coef = 0;
return (elt_list_ptr);
}
/* **********************************************************************