diff --git a/phreeqcpp/PBasic.cpp b/phreeqcpp/PBasic.cpp index fb2413e3..84744807 100644 --- a/phreeqcpp/PBasic.cpp +++ b/phreeqcpp/PBasic.cpp @@ -2415,7 +2415,7 @@ factor(struct LOC_exec * LINK) //PhreeqcPtr->count_sys = 1000; //int count_sys = PhreeqcPtr->count_sys; int count_sys = 1000; - names_arg = (char**)PhreeqcPtr->PHRQ_calloc((size_t)(count_sys + 1), sizeof(char*)); + names_arg = (char**)PhreeqcPtr->PHRQ_calloc(((size_t)count_sys + 1), sizeof(char*)); if (names_arg == NULL) { PhreeqcPtr->malloc_error(); @@ -2423,7 +2423,7 @@ factor(struct LOC_exec * LINK) exit(4); #endif } - moles_arg = (LDBLE*)PhreeqcPtr->PHRQ_calloc((size_t)(count_sys + 1), sizeof(LDBLE)); + moles_arg = (LDBLE*)PhreeqcPtr->PHRQ_calloc(((size_t)count_sys + 1), sizeof(LDBLE)); if (moles_arg == NULL) { PhreeqcPtr->malloc_error(); @@ -2574,10 +2574,8 @@ factor(struct LOC_exec * LINK) if (s_v.subscripts == NULL) PhreeqcPtr->malloc_error(); } - s_v.subscripts = - (int*)PhreeqcPtr->PHRQ_realloc(s_v.subscripts, - (size_t)(s_v.count_subscripts + - 1) * sizeof(int)); + s_v.subscripts = (int*)PhreeqcPtr->PHRQ_realloc(s_v.subscripts, + ((size_t)s_v.count_subscripts + 1) * sizeof(int)); if (s_v.subscripts == NULL) { PhreeqcPtr->malloc_error(); @@ -2602,10 +2600,8 @@ factor(struct LOC_exec * LINK) if (s_v.subscripts == NULL) PhreeqcPtr->malloc_error(); } - s_v.subscripts = - (int*)PhreeqcPtr->PHRQ_realloc(s_v.subscripts, - (size_t)(s_v.count_subscripts + - 1) * sizeof(int)); + s_v.subscripts = (int*)PhreeqcPtr->PHRQ_realloc(s_v.subscripts, + ((size_t)s_v.count_subscripts + 1) * sizeof(int)); if (s_v.subscripts == NULL) { PhreeqcPtr->malloc_error(); @@ -2689,10 +2685,8 @@ factor(struct LOC_exec * LINK) if (s_v.subscripts == NULL) PhreeqcPtr->malloc_error(); } - s_v.subscripts = - (int*)PhreeqcPtr->PHRQ_realloc(s_v.subscripts, - (size_t)(s_v.count_subscripts + - 1) * sizeof(int)); + s_v.subscripts = (int*)PhreeqcPtr->PHRQ_realloc(s_v.subscripts, + ((size_t)s_v.count_subscripts + 1) * sizeof(int)); if (s_v.subscripts == NULL) PhreeqcPtr->malloc_error(); s_v.subscripts[s_v.count_subscripts] = i; @@ -2712,10 +2706,8 @@ factor(struct LOC_exec * LINK) if (s_v.subscripts == NULL) PhreeqcPtr->malloc_error(); } - s_v.subscripts = - (int*)PhreeqcPtr->PHRQ_realloc(s_v.subscripts, - (size_t)(s_v.count_subscripts + - 1) * sizeof(int)); + s_v.subscripts = (int*)PhreeqcPtr->PHRQ_realloc(s_v.subscripts, + ((size_t)s_v.count_subscripts + 1) * sizeof(int)); if (s_v.subscripts == NULL) PhreeqcPtr->malloc_error(); s_v.subscripts[s_v.count_subscripts] = j; @@ -3212,7 +3204,7 @@ factor(struct LOC_exec * LINK) { errormsg("Parameter subscript out of range."); } - n.UU.val = PhreeqcPtr->rate_p[i_rate - 1]; + n.UU.val = PhreeqcPtr->rate_p[(size_t)i_rate - 1]; } } break; @@ -3650,7 +3642,7 @@ factor(struct LOC_exec * LINK) // Make work space int max_length = length < 256 ? 256 : length; - char* token = (char*)PhreeqcPtr->PHRQ_calloc(size_t(max_length + 1), sizeof(char)); + char* token = (char*)PhreeqcPtr->PHRQ_calloc(((size_t)max_length + 1), sizeof(char)); if (token == NULL) PhreeqcPtr->malloc_error(); std::string std_num; @@ -3693,7 +3685,7 @@ factor(struct LOC_exec * LINK) // Make work space int max_length = length < 256 ? 256 : length; - char* token = (char*)PhreeqcPtr->PHRQ_calloc(size_t(max_length + 1), sizeof(char)); + char* token = (char*)PhreeqcPtr->PHRQ_calloc(((size_t)max_length + 1), sizeof(char)); if (token == NULL) PhreeqcPtr->malloc_error(); std::string std_num; @@ -4231,7 +4223,7 @@ factor(struct LOC_exec * LINK) case toksgn: { n.UU.val = realfactor(LINK); - n.UU.val = (n.UU.val > 0) - (n.UU.val < 0); + n.UU.val = (double)(n.UU.val > 0) - (double)(n.UU.val < 0); } break; @@ -4290,7 +4282,7 @@ factor(struct LOC_exec * LINK) } { std::string str = n.UU.sval; - str = str.substr(i - 1, j); + str = str.substr((size_t)i - 1, (size_t)j); strcpy(n.UU.sval, str.c_str()); } require(tokrp, LINK); @@ -6876,8 +6868,8 @@ void PBasic:: strmove(int len, char *l_s, int spos, char *d, int dpos) { - l_s += spos - 1; - d += dpos - 1; + l_s += (size_t)spos - 1; + d += (size_t)dpos - 1; while (*d && --len >= 0) *d++ = *l_s++; if (len > 0) @@ -7133,40 +7125,40 @@ P_addset(long *l_s, unsigned val) /* s := s + [val] */ return sbase; } -long * PBasic:: -P_addsetr(long *l_s, unsigned v1, unsigned v2) /* s := s + [v1..v2] */ -{ - long *sbase = l_s; - int b1, b2, size; - if ((int) v1 > (int) v2) - return sbase; - b1 = v1 % SETBITS; - v1 /= SETBITS; - b2 = v2 % SETBITS; - v2 /= SETBITS; - size = *l_s; - v1++; - if ((int) ++v2 > size) - { - while ((int) v2 > size) - l_s[++size] = 0; - l_s[v2] = 0; - *l_s = v2; - } - l_s += v1; - if (v1 == v2) - { - *l_s |= (~((-2L) << (b2 - b1))) << b1; - } - else - { - *l_s++ |= (-1L) << b1; - while (++v1 < v2) - *l_s++ = -1; - *l_s |= ~((-2L) << b2); - } - return sbase; -} +//long * PBasic:: +//P_addsetr(long *l_s, unsigned v1, unsigned v2) /* s := s + [v1..v2] */ +//{ +// long *sbase = l_s; +// int b1, b2, size; +// if ((int) v1 > (int) v2) +// return sbase; +// b1 = v1 % SETBITS; +// v1 /= SETBITS; +// b2 = v2 % SETBITS; +// v2 /= SETBITS; +// size = *l_s; +// v1++; +// if ((int) ++v2 > size) +// { +// while ((int) v2 > size) +// l_s[++size] = 0; +// l_s[v2] = 0; +// *l_s = v2; +// } +// l_s += v1; +// if (v1 == v2) +// { +// *l_s |= (~((-2L) << (b2 - b1))) << b1; +// } +// else +// { +// *l_s++ |= (-1L) << b1; +// while (++v1 < v2) +// *l_s++ = -1; +// *l_s |= ~((-2L) << b2); +// } +// return sbase; +//} long * PBasic:: P_remset(long *l_s, unsigned val) /* s := s - [val] */ diff --git a/phreeqcpp/PBasic.h b/phreeqcpp/PBasic.h index 7318bdf3..cc643a94 100644 --- a/phreeqcpp/PBasic.h +++ b/phreeqcpp/PBasic.h @@ -170,6 +170,7 @@ public: toktan, tokarctan, toklog, + toklog10, tokexp, tokabs, toksgn, @@ -182,7 +183,6 @@ public: tokpeek, tokrem, toklet, - tokprint, tokinput, tokgoto, tokif, @@ -206,7 +206,6 @@ public: toknew, tokload, tokmerge, - toksave, tokbye, tokdel, tokrenum, @@ -214,143 +213,142 @@ public: tokelse, tokto, tokstep, - toktc, - tokm0, - tokm, - tokparm, + /* start phreeqc */ tokact, - tokmol, - tokla, - toklm, - toksr, - toksi, - toktot, - toktk, - toktime, - toklog10, - toksim_time, - tokequi, - tokgas, - tokpunch, - tokkin, - toks_s, - tokmu, + tokadd_heading, tokalk, - tokrxn, - tokdist, - tokmisc1, - tokmisc2, - tokedl, - tokstep_no, - toksim_no, - toktotal_time, - tokput, - tokget, + tokaphi, + tokcalc_value, + tokceil, + tokcell_no, + tokchange_por, + tokchange_surf, tokcharge_balance, - tokpercent_error, -#if defined (PHREEQ98) || defined (MULTICHART) + tokcurrent_a, + tokdebye_length, + tokdelta_h_phase, + tokdelta_h_species, + tokdescription, + tokdh_a, + tokdh_a0, + tokdh_av, + tokdh_b, + tokdh_bdot, + tokdiff_c, + tokdist, + tokedl, + tokedl_species, + tokeol_, + tokeol_notab_, + tokeps_r, + tokeq_frac, + tokequiv_frac, + tokequi, + tokequi_delta, + tokerase, + tokexists, + tokfloor, + tokgamma, + tokgas, + tokgas_p, + tokgas_vm, + tokget, + tokget_por, + tokgfw, tokgraph_x, tokgraph_y, tokgraph_sy, -#endif - tokcell_no, - tokexists, - toksurf, - toklk_species, - toklk_named, - toklk_phase, - tokdelta_h_phase, - tokdelta_h_species, - tokdh_a0, - tokdh_bdot, - toksum_species, - toksum_gas, - toksum_s_s, - tokcalc_value, - tokdescription, - toktitle, - toksys, - tokadd_heading, tokinstr, - tokltrim, - tokrtrim, - toktrim, - tokpad, - tokpad_, - tokchange_por, - tokget_por, - tokosmotic, - tokchange_surf, - tokporevolume, - toksc, - tokgamma, - toklg, - tokrho, - tokrho_0, - tokcell_volume, - tokcell_pore_volume, - tokcell_porosity, - tokcell_saturation, - tokvelocity_x, - tokvelocity_y, - tokvelocity_z, - toktransport_cell_no, -#if defined MULTICHART - tokplot_xy, -#endif - toktotmole, tokiso, tokiso_unit, - toktotmol, - toktotmoles, - tokeol_, - tokeol_notab_, - tokno_newline_, - tokceil, - tokfloor, - tokkinetics_formula, - tokkinetics_formula_, - tokphase_formula, - tokphase_formula_, - tokspecies_formula, - tokspecies_formula_, - toklist_s_s, - tokpr_p, - tokpr_phi, - tokgas_p, - tokgas_vm, - tokpressure, - tokerase, - tokeps_r, - tokvm, - tokphase_vm, - tokdh_a, - tokdebye_length, - tokdh_b, - tokdh_av, - tokqbrn, + tokiterations, tokkappa, - tokgfw, - toksoln_vol, - tokequi_delta, + tokkin, tokkin_delta, tokkin_time, - tokstr_f_, - tokstr_e_, - tokeq_frac, - tokequiv_frac, - tokcallback, - tokdiff_c, + tokkinetics_formula, + tokkinetics_formula_, + tokla, + toklg, + toklist_s_s, + toklk_named, + toklk_phase, + toklk_species, + toklm, + tokltrim, + tokm, + tokm0, + tokmisc1, + tokmisc2, + tokmol, + tokmu, + tokno_newline_, + tokosmotic, + tokpad_, + tokpad, + tokparm, + tokpercent_error, + tokphase_formula, + tokphase_formula_, + tokphase_vm, + tokplot_xy, + tokpot_v, + tokpr_p, + tokpr_phi, + tokpressure, + tokprint, + tokpunch, + tokput, + tokqbrn, + tokrho, + tokrho_0, + tokrtrim, + tokrxn, + toks_s, + toksave, + toksc, toksetdiff_c, - toksa_declercq, - tokedl_species, + toksi, + toksim_no, + toksim_time, + toksoln_vol, + tokspecies_formula, + tokspecies_formula_, + toksr, + tokstep_no, + tokstr_e_, + tokstr_f_, + toksum_gas, + toksum_s_s, + toksum_species, + toksurf, + toksys, + tokt_sc, + toktc, + toktime, + toktitle, + toktk, + toktot, + toktotal_time, + toktotmole, + toktotmol, + toktotmoles, + toktrim, tokviscos, tokviscos_0, - tokcurrent_a, - tokpot_v, - tokt_sc, - tokaphi, - tokiterations + tokvm, + /* end phreeqc */ + toksa_declercq, // Undocumented function + tokcallback, // PHAST function + tokcell_pore_volume, // PHAST function + tokporevolume, // PHAST function + tokcell_porosity, // PHAST function + tokcell_saturation, // PHAST function + tokcell_volume, // PHAST function + toktransport_cell_no, // PHAST function + tokvelocity_x, // PHAST function + tokvelocity_y, // PHAST function + tokvelocity_z // PHAST function }; #if !defined(PHREEQCI_GUI) @@ -511,7 +509,7 @@ public: long * P_setdiff(long *d, long *s1, long *s2); long * P_setxor(long *d, long *s1, long *s2); long * P_addset(long *s, unsigned val); - long * P_addsetr(long *s, unsigned v1, unsigned v2); +// long * P_addsetr(long *s, unsigned v1, unsigned v2); long * P_remset(long *s, unsigned val); int P_setequal(long *s1, long *s2); int P_subset(long *s1, long *s2); diff --git a/phreeqcpp/Phreeqc.h b/phreeqcpp/Phreeqc.h index b3a3598e..d8748fe0 100644 --- a/phreeqcpp/Phreeqc.h +++ b/phreeqcpp/Phreeqc.h @@ -1762,7 +1762,8 @@ protected: *delta_save; LDBLE *min_delta, *max_delta; int *inv_iu, *inv_is; - int klmd, nklmd, n2d, kode, iter; + int klmd, nklmd, n2d; + int kode, iter; LDBLE toler, error, max_pct, scaled_error; struct master *master_alk; int *row_back, *col_back; diff --git a/phreeqcpp/Pressure.cxx b/phreeqcpp/Pressure.cxx index cb21173c..493bd532 100644 --- a/phreeqcpp/Pressure.cxx +++ b/phreeqcpp/Pressure.cxx @@ -336,9 +336,9 @@ Pressure_for_step(int step_number) else { LDBLE denom; - denom = (this->count <= 1) ? 1 : (LDBLE) (this->count - 1); + denom = (this->count <= 1) ? 1 : ((LDBLE)this->count - 1); p_temp = this->pressures[0] + ( this->pressures[1] - this->pressures[0]) * - ((LDBLE) (step_number - 1)) / (denom); + (((LDBLE)step_number - 1)) / (denom); } } else @@ -349,7 +349,7 @@ Pressure_for_step(int step_number) } else { - p_temp = this->pressures[step_number - 1]; + p_temp = this->pressures[(size_t)step_number - 1]; } } diff --git a/phreeqcpp/Temperature.cxx b/phreeqcpp/Temperature.cxx index 1af917b4..27563025 100644 --- a/phreeqcpp/Temperature.cxx +++ b/phreeqcpp/Temperature.cxx @@ -346,9 +346,9 @@ Temperature_for_step(int step_number) else { LDBLE denom; - denom = (this->countTemps <= 1) ? 1 : (LDBLE) (this->countTemps - 1); + denom = (this->countTemps <= 1) ? 1 : (LDBLE)this->countTemps - 1; t_temp = this->temps[0] + ( this->temps[1] - this->temps[0]) * - ((LDBLE) (step_number - 1)) / (denom); + ((LDBLE)step_number - 1) / (denom); } } else @@ -359,7 +359,7 @@ Temperature_for_step(int step_number) } else { - t_temp = this->temps[step_number - 1]; + t_temp = this->temps[(size_t)step_number - 1]; } } diff --git a/phreeqcpp/cxxKinetics.cxx b/phreeqcpp/cxxKinetics.cxx index 2cc4b67f..337cb918 100644 --- a/phreeqcpp/cxxKinetics.cxx +++ b/phreeqcpp/cxxKinetics.cxx @@ -489,7 +489,7 @@ Current_step(bool incremental_reactions, int reaction_step) const } else { - kin_time = this->steps[reaction_step - 1]; + kin_time = this->steps[(size_t)reaction_step - 1]; } } else @@ -515,7 +515,7 @@ Current_step(bool incremental_reactions, int reaction_step) const } else { - kin_time = this->steps[reaction_step - 1]; + kin_time = this->steps[(size_t)reaction_step - 1]; } } else diff --git a/phreeqcpp/gases.cpp b/phreeqcpp/gases.cpp index 4b2494bb..e6c76d3e 100644 --- a/phreeqcpp/gases.cpp +++ b/phreeqcpp/gases.cpp @@ -218,7 +218,7 @@ build_fixed_volume_gas(void) row / (count_unknowns + 1), col)); } store_jacob(&(gas_unknowns[i]->moles), - &(my_array[row + col]), coef); + &(my_array[(size_t)row + (size_t)col]), coef); } if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_PRESSURE) { @@ -231,7 +231,7 @@ build_fixed_volume_gas(void) gas_unknown->number)); } store_jacob(&(phase_ptr->fraction_x), - &(my_array[row + gas_unknown->number]), coef_elt); + &(my_array[(size_t)row + (size_t)gas_unknown->number]), coef_elt); } } /* @@ -309,7 +309,7 @@ build_fixed_volume_gas(void) master_ptr->s->name, (double) coef, row / (count_unknowns + 1), col)); } - store_jacob(&(phase_ptr->p_soln_x), &(my_array[row + col]), coef); + store_jacob(&(phase_ptr->p_soln_x), &(my_array[(size_t)row + (size_t)col]), coef); } } } diff --git a/phreeqcpp/integrate.cpp b/phreeqcpp/integrate.cpp index ce6fa6b1..f38a334c 100644 --- a/phreeqcpp/integrate.cpp +++ b/phreeqcpp/integrate.cpp @@ -305,10 +305,10 @@ polint(LDBLE * xa, LDBLE * ya, int n, LDBLE xv, LDBLE * yv, LDBLE * dy) /* * Malloc work space */ - c = (LDBLE *) PHRQ_malloc((size_t) (n + 1) * sizeof(LDBLE)); + c = (LDBLE *) PHRQ_malloc(((size_t)n + 1) * sizeof(LDBLE)); if (c == NULL) malloc_error(); - d = (LDBLE *) PHRQ_malloc((size_t) (n + 1) * sizeof(LDBLE)); + d = (LDBLE *) PHRQ_malloc(((size_t)n + 1) * sizeof(LDBLE)); if (d == NULL) malloc_error(); @@ -775,7 +775,7 @@ calc_all_donnan(void) A_surf = charge_ptr->Get_specific_area() * charge_ptr->Get_grams(); if (use.Get_surface_ptr()->Get_type() == cxxSurface::CD_MUSIC) { - f_psi = x[j + 2]->master[0]->s->la * LOG_10; /* -FPsi/RT */ + f_psi = x[(size_t)j + 2]->master[0]->s->la * LOG_10; /* -FPsi/RT */ f_psi = f_psi / 2; cd_m = 1; } else @@ -946,7 +946,7 @@ calc_init_donnan(void) A_surf = charge_ptr->Get_specific_area() * charge_ptr->Get_grams(); if (use.Get_surface_ptr()->Get_type() == cxxSurface::CD_MUSIC) { - f_psi = x[j + 2]->master[0]->s->la * LOG_10; /* -FPsi/RT */ + f_psi = x[(size_t)j + 2]->master[0]->s->la * LOG_10; /* -FPsi/RT */ f_psi = f_psi / 2; } else f_psi = x[j]->master[0]->s->la * LOG_10; diff --git a/phreeqcpp/inverse.cpp b/phreeqcpp/inverse.cpp index 8b2f30ff..26a6e824 100644 --- a/phreeqcpp/inverse.cpp +++ b/phreeqcpp/inverse.cpp @@ -340,8 +340,8 @@ setup_inverse(struct inverse *inv_ptr) (size_t) max_column_count * sizeof(LDBLE)); for (i = 0; i < max_row_count; i++) { - memcpy((void *) &(my_array[i * max_column_count]), (void *) &(inv_zero[0]), - (size_t) max_column_count * sizeof(LDBLE)); + memcpy((void *) &(my_array[(size_t)i * (size_t)max_column_count]), (void *) &(inv_zero[0]), + (size_t)max_column_count * sizeof(LDBLE)); } /* * begin filling array @@ -434,11 +434,11 @@ setup_inverse(struct inverse *inv_ptr) { if (master[j]->in >= 0) { - my_array[master[j]->in * max_column_count + i] = + my_array[(size_t)master[j]->in * (size_t)max_column_count + (size_t)i] = f * master[j]->total; if (master[j]->s == s_eminus) { - my_array[master[j]->in * max_column_count + i] = 0.0; + my_array[(size_t)master[j]->in * (size_t)max_column_count + (size_t)i] = 0.0; } } } @@ -465,7 +465,7 @@ setup_inverse(struct inverse *inv_ptr) } if (fabs(cb) < toler) cb = 0.0; - my_array[(row_charge + i) * max_column_count + i] = cb; + my_array[((size_t)row_charge + (size_t)i) * (size_t)max_column_count + (size_t)i] = cb; } /* mass_balance: phase data */ @@ -511,11 +511,11 @@ setup_inverse(struct inverse *inv_ptr) coef = master_ptr->coef; if (coef <= 0) coef = 1.0; - my_array[row * max_column_count + column] = + my_array[(size_t)row * (size_t)max_column_count + (size_t)column] = rxn_ptr->token[j].coef * coef; } row = master_alk->in; /* include alkalinity for phase */ - my_array[row * max_column_count + column] = calc_alk(rxn_ptr); + my_array[(size_t)row * (size_t)max_column_count + (size_t)column] = calc_alk(rxn_ptr); } /* mass balance: redox reaction data */ @@ -563,14 +563,14 @@ setup_inverse(struct inverse *inv_ptr) assert(row * max_column_count + column < max_column_count * max_row_count); assert(row >= 0); assert(column >= 0); - my_array[row * max_column_count + column] = + my_array[(size_t)row * (size_t)max_column_count + (size_t)column] = rxn_ptr->token[j].coef; /* if coefficient of element is not 1.0 in master species */ if (j != 0) - my_array[row * max_column_count + column] /= coef; + my_array[(size_t)row * (size_t)max_column_count + (size_t)column] /= coef; } row = master_alk->in; /* include alkalinity for redox reaction */ - my_array[row * max_column_count + column] = + my_array[(size_t)row * (size_t)max_column_count + (size_t)column] = (calc_alk(rxn_ptr) - inv_ptr->elts[i].master->s->alk) / coef; } } @@ -585,15 +585,15 @@ setup_inverse(struct inverse *inv_ptr) { if (j < (inv_ptr->count_solns - 1)) { - my_array[row * max_column_count + column] = 1.0; + my_array[(size_t)row * (size_t)max_column_count + (size_t)column] = 1.0; } else { - my_array[row * max_column_count + column] = -1.0; + my_array[(size_t)row * (size_t)max_column_count + (size_t)column] = -1.0; } if (inv_ptr->elts[i].master->s == s_eminus) { - my_array[row * max_column_count + column] = 0.0; + my_array[(size_t)row * (size_t)max_column_count + (size_t)column] = 0.0; } sprintf(token, "%s %d", row_name[row], j); col_name[column] = string_hsave(token); @@ -655,19 +655,19 @@ setup_inverse(struct inverse *inv_ptr) solution_ptr = Utilities::Rxn_find(Rxn_solution_map, inv_ptr->solns[i]); if (i < inv_ptr->count_solns - 1) { - my_array[count_rows * max_column_count + i] = + my_array[(size_t)count_rows * (size_t)max_column_count + (size_t)i] = 1.0 / gfw_water * solution_ptr->Get_mass_water(); } else { - my_array[count_rows * max_column_count + inv_ptr->count_solns - 1] = + my_array[(size_t)count_rows * (size_t)max_column_count + (size_t)inv_ptr->count_solns - 1] = -1.0 / gfw_water * solution_ptr->Get_mass_water(); } } /* coefficient for water uncertainty */ if (inv_ptr->water_uncertainty > 0) { - my_array[count_rows * max_column_count + col_water] = 1.0; + my_array[(size_t)count_rows * (size_t)max_column_count + (size_t)col_water] = 1.0; } row_name[count_rows] = string_hsave("H2O"); row_water = count_rows; @@ -677,8 +677,8 @@ setup_inverse(struct inverse *inv_ptr) * Final solution fraction equals 1.0 */ - my_array[count_rows * max_column_count + inv_ptr->count_solns - 1] = 1.0; - my_array[count_rows * max_column_count + count_unknowns] = 1.0; + my_array[(size_t)count_rows * (size_t)max_column_count + (size_t)inv_ptr->count_solns - 1] = 1.0; + my_array[(size_t)count_rows * (size_t)max_column_count + (size_t)count_unknowns] = 1.0; row_name[count_rows] = string_hsave("fract, final"); count_rows++; @@ -689,7 +689,7 @@ setup_inverse(struct inverse *inv_ptr) for (i = 0; i < inv_ptr->count_solns; i++) { /* solution_ptr = solution_bsearch(inv_ptr->solns[i], &j, TRUE); */ -/* array[count_rows * max_column_count + i] = solution_ptr->cb; */ +/* array[(size_t)count_rows * (size_t)max_column_count + (size_t)i] = solution_ptr->cb; */ for (j = 0; j < inv_ptr->count_elts; j++) { column = col_epsilon + j * inv_ptr->count_solns + i; @@ -700,10 +700,10 @@ setup_inverse(struct inverse *inv_ptr) { coef = -1.0; } - my_array[count_rows * max_column_count + column] = coef; + my_array[(size_t)count_rows * (size_t)max_column_count + (size_t)column] = coef; if (inv_ptr->elts[j].master->s == s_eminus) { - my_array[count_rows * max_column_count + column] = 0.0; + my_array[(size_t)count_rows * (size_t)max_column_count + (size_t)column] = 0.0; } } sprintf(token, "%s %d", "charge", i); @@ -721,12 +721,12 @@ setup_inverse(struct inverse *inv_ptr) if (inv_ptr->dalk_dph[i] != 0 || inv_ptr->dalk_dc[i] != 0) { column = col_ph + i; - my_array[count_rows * max_column_count + column] = + my_array[(size_t)count_rows * (size_t)max_column_count + (size_t)column] = inv_ptr->dalk_dph[i]; column = col_epsilon + i_alk * inv_ptr->count_solns + i; - my_array[count_rows * max_column_count + column] = -1.0; + my_array[(size_t)count_rows * (size_t)max_column_count + (size_t)column] = -1.0; column = col_epsilon + i_carb * inv_ptr->count_solns + i; - my_array[count_rows * max_column_count + column] = + my_array[(size_t)count_rows * (size_t)max_column_count + (size_t)column] = inv_ptr->dalk_dc[i]; } sprintf(token, "%s %d", "dAlk", i); @@ -772,9 +772,8 @@ setup_inverse(struct inverse *inv_ptr) } else { - coef = - my_array[inv_ptr->elts[j].master->in * max_column_count + - i] * coef; + coef = my_array[(size_t)inv_ptr->elts[j].master->in * + (size_t)max_column_count + (size_t)i] * coef; coef = fabs(coef); } @@ -786,7 +785,7 @@ setup_inverse(struct inverse *inv_ptr) { for (k = 0; k < count_rows; k++) { - my_array[k * max_column_count + column] = 0.0; + my_array[(size_t)k * (size_t)max_column_count + (size_t)column] = 0.0; } continue; } @@ -798,12 +797,12 @@ setup_inverse(struct inverse *inv_ptr) if (coef < toler) { - my_array[(column - col_epsilon) * max_column_count + column] = + my_array[((size_t)column - (size_t)col_epsilon) * (size_t)max_column_count + (size_t)column] = SCALE_EPSILON / toler; } else { - my_array[(column - col_epsilon) * max_column_count + column] = + my_array[((size_t)column - (size_t)col_epsilon) * (size_t)max_column_count + (size_t)column] = SCALE_EPSILON / coef; } @@ -817,15 +816,14 @@ setup_inverse(struct inverse *inv_ptr) { f = 1.0; } - my_array[count_rows * max_column_count + column] = 1.0 * f; - my_array[count_rows * max_column_count + i] = -coef * f; - sprintf(token, "%s %s", inv_ptr->elts[j].master->elt->name, - "eps+"); + my_array[(size_t)count_rows * (size_t)max_column_count + (size_t)column] = 1.0 * f; + my_array[(size_t)count_rows * (size_t)max_column_count + (size_t)i] = -coef * f; + sprintf(token, "%s %s", inv_ptr->elts[j].master->elt->name, "eps+"); row_name[count_rows] = string_hsave(token); count_rows++; /* set lower limit of change in negative direction */ - conc = my_array[inv_ptr->elts[j].master->in * max_column_count + i]; + conc = my_array[(size_t)inv_ptr->elts[j].master->in * (size_t)max_column_count + (size_t)i]; /* if concentration is zero, only positive direction allowed */ if (conc == 0.0) @@ -852,8 +850,8 @@ setup_inverse(struct inverse *inv_ptr) inv_ptr->elts[j].master->elt->name)) coef = fabs(conc) + toler; - my_array[count_rows * max_column_count + i] = -coef * f; - my_array[count_rows * max_column_count + column] = -1.0 * f; + my_array[(size_t)count_rows * (size_t)max_column_count + (size_t)i] = -coef * f; + my_array[(size_t)count_rows * (size_t)max_column_count + (size_t)column] = -1.0 * f; sprintf(token, "%s %s", inv_ptr->elts[j].master->elt->name, "eps-"); row_name[count_rows] = string_hsave(token); @@ -873,21 +871,21 @@ setup_inverse(struct inverse *inv_ptr) /* scale epsilon in optimization equation */ - my_array[(column - col_epsilon) * max_column_count + column] = + my_array[((size_t)column - (size_t)col_epsilon) * (size_t)max_column_count + (size_t)column] = SCALE_EPSILON / coef; /* set upper limit of change in positive direction */ - my_array[count_rows * max_column_count + column] = 1.0; - my_array[count_rows * max_column_count + i] = -coef; + my_array[(size_t)count_rows * (size_t)max_column_count + (size_t)column] = 1.0; + my_array[(size_t)count_rows * (size_t)max_column_count + (size_t)i] = -coef; sprintf(token, "%s %s", "pH", "eps+"); row_name[count_rows] = string_hsave(token); count_rows++; /* set lower limit of change in negative direction */ - my_array[count_rows * max_column_count + column] = -1.0; - my_array[count_rows * max_column_count + i] = -coef; + my_array[(size_t)count_rows * (size_t)max_column_count + (size_t)column] = -1.0; + my_array[(size_t)count_rows * (size_t)max_column_count + (size_t)i] = -coef; sprintf(token, "%s %s", "pH", "eps-"); row_name[count_rows] = string_hsave(token); count_rows++; @@ -902,16 +900,16 @@ setup_inverse(struct inverse *inv_ptr) if (coef > 0.0) { /* set upper limit of change in positive direction */ - my_array[count_rows * max_column_count + column] = 1.0; - my_array[count_rows * max_column_count + count_unknowns] = coef; + my_array[(size_t)count_rows * (size_t)max_column_count + (size_t)column] = 1.0; + my_array[(size_t)count_rows * (size_t)max_column_count + (size_t)count_unknowns] = coef; sprintf(token, "%s %s", "water", "eps+"); row_name[count_rows] = string_hsave(token); count_rows++; /* set lower limit of change in negative direction */ - my_array[count_rows * max_column_count + column] = -1.0; - my_array[count_rows * max_column_count + count_unknowns] = coef; + my_array[(size_t)count_rows * (size_t)max_column_count + (size_t)column] = -1.0; + my_array[(size_t)count_rows * (size_t)max_column_count + (size_t)count_unknowns] = coef; sprintf(token, "%s %s", "water", "eps-"); row_name[count_rows] = string_hsave(token); count_rows++; @@ -943,12 +941,12 @@ setup_inverse(struct inverse *inv_ptr) /* scale epsilon in optimization equation */ - my_array[(column - col_epsilon) * max_column_count + - column] = SCALE_EPSILON / coef; + my_array[((size_t)column - (size_t)col_epsilon) * (size_t)max_column_count + + (size_t)column] = SCALE_EPSILON / coef; /* set upper limit of change in positive direction */ - my_array[count_rows * max_column_count + column] = 1.0; - my_array[count_rows * max_column_count + i] = -coef; + my_array[(size_t)count_rows * (size_t)max_column_count + (size_t)column] = 1.0; + my_array[(size_t)count_rows * (size_t)max_column_count + (size_t)i] = -coef; sprintf(token, "%d%s %s", (int) kit->second.Get_isotope_number(), kit->second.Get_elt_name().c_str(), "eps+"); @@ -957,8 +955,8 @@ setup_inverse(struct inverse *inv_ptr) /* set lower limit of change in negative direction */ - my_array[count_rows * max_column_count + column] = -1.0; - my_array[count_rows * max_column_count + i] = -coef; + my_array[(size_t)count_rows * (size_t)max_column_count + (size_t)column] = -1.0; + my_array[(size_t)count_rows * (size_t)max_column_count + (size_t)i] = -coef; sprintf(token, "%d%s %s", (int) kit->second.Get_isotope_number(), kit->second.Get_elt_name().c_str(), "eps-"); @@ -987,11 +985,11 @@ setup_inverse(struct inverse *inv_ptr) { if (inv_ptr->phases[i].constraint == PRECIPITATE) { - delta[col_phases + i] = -1.0; + delta[(size_t)col_phases + (size_t)i] = -1.0; } else if (inv_ptr->phases[i].constraint == DISSOLVE) { - delta[col_phases + i] = 1.0; + delta[(size_t)col_phases + (size_t)i] = 1.0; } } for (i = 0; i < (inv_ptr->count_solns - 1); i++) @@ -1003,7 +1001,7 @@ setup_inverse(struct inverse *inv_ptr) */ for (i = 0; i < max_column_count; i++) { - my_array[row_water * max_column_count + i] *= SCALE_WATER; + my_array[(size_t)row_water * (size_t)max_column_count + (size_t)i] *= SCALE_WATER; } /* * Arrays are complete @@ -1025,8 +1023,8 @@ setup_inverse(struct inverse *inv_ptr) output_msg(sformatf( "\n")); k = 0; } - output_msg(sformatf( "%11.2e", - (double) my_array[i * max_column_count + j])); + output_msg(sformatf("%11.2e", + (double)my_array[(size_t)i * (size_t)max_column_count + (size_t)j])); k++; } if (k != 0) @@ -1115,8 +1113,8 @@ solve_inverse(struct inverse *inv_ptr) inv_cu = (LDBLE *) PHRQ_malloc((size_t) 2 * nklmd * sizeof(LDBLE)); if (inv_cu == NULL) malloc_error(); - memset(inv_cu, 0, ((size_t) (2 * nklmd * sizeof(LDBLE)))); - inv_iu = (int *) PHRQ_malloc((size_t) 2 * nklmd * sizeof(int)); + memset(inv_cu, 0, ((2 * (size_t)nklmd * sizeof(LDBLE)))); + inv_iu = (int *) PHRQ_malloc(2 * (size_t)nklmd * sizeof(int)); if (inv_iu == NULL) malloc_error(); inv_is = (int *) PHRQ_malloc((size_t) klmd * sizeof(int)); @@ -2769,8 +2767,8 @@ shrink(struct inverse *inv_ptr, LDBLE * array_in, LDBLE * array_out, memcpy(&(array_out[row * max_column_count]), - &(array_out[i * max_column_count]), - (size_t) (*n + 1) * sizeof(LDBLE)); + &(array_out[(size_t)i * (size_t)max_column_count]), + ((size_t)*n + 1) * sizeof(LDBLE)); } row_back_l[row] = i; row++; @@ -2813,8 +2811,8 @@ shrink(struct inverse *inv_ptr, LDBLE * array_in, LDBLE * array_out, assert(false); } memcpy(&(array_out[row * max_column_count]), - &(array_out[i * max_column_count]), - (size_t) (*n + 1) * sizeof(LDBLE)); + &(array_out[(size_t)i * (size_t)max_column_count]), + ((size_t)*n + 1) * sizeof(LDBLE)); } row_back_l[row] = i; row++; @@ -2855,9 +2853,9 @@ shrink(struct inverse *inv_ptr, LDBLE * array_in, LDBLE * array_out, { assert(false); } - memcpy(&(array_out[row * max_column_count]), - &(array_out[i * max_column_count]), - (size_t) (*n + 1) * sizeof(LDBLE)); + memcpy(&(array_out[(size_t)row * (size_t)max_column_count]), + &(array_out[(size_t)i * (size_t)max_column_count]), + ((size_t)*n + 1) * sizeof(LDBLE)); } row_back_l[row] = i; row++; @@ -3079,16 +3077,16 @@ post_mortem(void) sum = 0; for (j = 0; j < count_unknowns; j++) { - sum += inv_delta1[j] * my_array[i * max_column_count + j]; + sum += inv_delta1[j] * my_array[(size_t)i * (size_t)max_column_count + (size_t)j]; } - if (equal(sum, my_array[(i * max_column_count) + count_unknowns], toler) + if (equal(sum, my_array[((size_t)i * (size_t)max_column_count) + (size_t)count_unknowns], toler) == FALSE) { output_msg(sformatf( "\tERROR: equality not satisfied for %s, %e.\n", row_name[i], - (double) (sum - my_array[(i * max_column_count) + count_unknowns]))); + (double) (sum - my_array[((size_t)i * (size_t)max_column_count) + (size_t)count_unknowns]))); } } /* @@ -3099,15 +3097,15 @@ post_mortem(void) sum = 0; for (j = 0; j < count_unknowns; j++) { - sum += inv_delta1[j] * my_array[i * max_column_count + j]; + sum += inv_delta1[j] * my_array[(size_t)i * (size_t)max_column_count + (size_t)j]; } - if (sum > my_array[(i * max_column_count) + count_unknowns] + toler) + if (sum > my_array[((size_t)i * (size_t)max_column_count) + (size_t)count_unknowns] + toler) { output_msg(sformatf( "\tERROR: inequality not satisfied for %s, %e\n", row_name[i], - (double) (sum - my_array[(i * max_column_count) + count_unknowns]))); + (double) (sum - my_array[((size_t)i * (size_t)max_column_count) + (size_t)count_unknowns]))); } } /* @@ -3156,15 +3154,15 @@ test_cl1_solution(void) sum = 0; for (j = 0; j < count_unknowns; j++) { - sum += inv_delta1[j] * my_array[i * max_column_count + j]; + sum += inv_delta1[j] * my_array[(size_t)i * (size_t)max_column_count + (size_t)j]; } - if (equal(sum, my_array[(i * max_column_count) + count_unknowns], toler) == FALSE) + if (equal(sum, my_array[((size_t)i * (size_t)max_column_count) + (size_t)count_unknowns], toler) == FALSE) { if (debug_inverse) { output_msg(sformatf("\tERROR: equality not satisfied for %s, %e.\n", row_name[i], - (double) (sum - my_array[(i * max_column_count) + count_unknowns]))); + (double) (sum - my_array[((size_t)i * (size_t)max_column_count) + (size_t)count_unknowns]))); } rv = false; } @@ -3177,17 +3175,17 @@ test_cl1_solution(void) sum = 0; for (j = 0; j < count_unknowns; j++) { - sum += inv_delta1[j] * my_array[i * max_column_count + j]; + sum += inv_delta1[j] * my_array[(size_t)i * (size_t)max_column_count + (size_t)j]; } - if (sum > my_array[(i * max_column_count) + count_unknowns] + toler) + if (sum > my_array[((size_t)i * (size_t)max_column_count) + (size_t)count_unknowns] + toler) { if (debug_inverse) { output_msg(sformatf( "\tERROR: inequality not satisfied for %s, %e\n", row_name[i], - (double) (sum - my_array[(i * max_column_count) + count_unknowns]))); + (double) (sum - my_array[((size_t)i * (size_t)max_column_count) + (size_t)count_unknowns]))); } rv = false; } @@ -3440,7 +3438,7 @@ isotope_balance_equation(struct inverse *inv_ptr, int row, int n) if (primary_jit == primary_ptr && jit->second.Get_isotope_number() == isotope_number) { - my_array[row * max_column_count + i] += + my_array[(size_t)row * (size_t)max_column_count + (size_t)i] += f * jit->second.Get_total() * jit->second.Get_ratio(); } } @@ -3465,7 +3463,7 @@ isotope_balance_equation(struct inverse *inv_ptr, int row, int n) break; } column = col_epsilon + (k * inv_ptr->count_solns) + i; - my_array[row * max_column_count + column] += + my_array[(size_t)row * (size_t)max_column_count + (size_t)column] += f * jit->second.Get_ratio(); } } @@ -3493,7 +3491,7 @@ isotope_balance_equation(struct inverse *inv_ptr, int row, int n) (i * inv_ptr->count_isotope_unknowns) + k; } } - my_array[row * max_column_count + column] += + my_array[(size_t)row * (size_t)max_column_count + (size_t)column] += f * jit->second.Get_total(); } } @@ -3513,11 +3511,11 @@ isotope_balance_equation(struct inverse *inv_ptr, int row, int n) { /* term for alpha phase unknowns */ column = col_phases + i; - my_array[row * max_column_count + column] = + my_array[(size_t)row * (size_t)max_column_count + (size_t)column] = isotope_ptr[j].ratio * isotope_ptr[j].coef; /* term for phase isotope uncertainty unknown */ column = col_phase_isotopes + i * inv_ptr->count_isotopes + n; - my_array[row * max_column_count + column] = isotope_ptr[j].coef; + my_array[(size_t)row * (size_t)max_column_count + (size_t)column] = isotope_ptr[j].coef; break; } } @@ -3583,11 +3581,8 @@ count_isotope_unknowns(struct inverse *inv_ptr, /* nonredox element */ if (primary_ptr->s->secondary == NULL) { - isotopes = - (struct isotope *) PHRQ_realloc(isotopes, - (size_t) (count_isotopes + - 1) * - sizeof(struct isotope)); + isotopes = (struct isotope *) PHRQ_realloc(isotopes, + ((size_t)count_isotopes + 1) * sizeof(struct isotope)); if (isotopes == NULL) { malloc_error(); @@ -3617,12 +3612,8 @@ count_isotope_unknowns(struct inverse *inv_ptr, { if (master[k]->elt->primary != primary_ptr) break; - isotopes = - (struct isotope *) PHRQ_realloc(isotopes, - (size_t) (count_isotopes - + - 1) * - sizeof(struct isotope)); + isotopes = (struct isotope *) PHRQ_realloc(isotopes, + ((size_t)count_isotopes + 1) * sizeof(struct isotope)); if (isotopes == NULL) { malloc_error(); @@ -3759,7 +3750,7 @@ check_isotopes(struct inverse *inv_ptr) && !isnan(inv_ptr->i_u[i].uncertainties[inv_ptr->i_u[i].count_uncertainties - 1])) #else else if (inv_ptr->i_u[i].count_uncertainties > 0 - && inv_ptr->i_u[i].uncertainties[inv_ptr->i_u[i].count_uncertainties - 1] != NAN) + && inv_ptr->i_u[i].uncertainties[(size_t)inv_ptr->i_u[i].count_uncertainties - 1] != NAN) #endif { kit->second.Set_x_ratio_uncertainty(inv_ptr->i_u[i].uncertainties[inv_ptr->i_u[i].count_uncertainties - 1]); @@ -3905,7 +3896,7 @@ phase_isotope_inequalities(struct inverse *inv_ptr) { for (k = 0; k < count_rows; k++) { - my_array[k * max_column_count + column] = 0.0; + my_array[(size_t)k * (size_t)max_column_count + (size_t)column] = 0.0; } continue; } @@ -3913,26 +3904,25 @@ phase_isotope_inequalities(struct inverse *inv_ptr) /* * optimization */ - my_array[(column - col_epsilon) * max_column_count + column] = - SCALE_EPSILON / - inv_ptr->phases[i].isotopes[j].ratio_uncertainty; + my_array[((size_t)column - (size_t)col_epsilon) * (size_t)max_column_count + (size_t)column] = + SCALE_EPSILON / inv_ptr->phases[i].isotopes[j].ratio_uncertainty; /* * two inequalities to account for absolute value */ /* for phases constrained to precipitate */ if (inv_ptr->phases[i].constraint == PRECIPITATE) { - my_array[count_rows * max_column_count + col_phases + i] = + my_array[(size_t)count_rows * (size_t)max_column_count + (size_t)col_phases + (size_t)i] = inv_ptr->phases[i].isotopes[j].ratio_uncertainty; - my_array[count_rows * max_column_count + column] = 1.0; + my_array[(size_t)count_rows * (size_t)max_column_count + (size_t)column] = 1.0; sprintf(token, "%s %s", inv_ptr->phases[i].phase->name, "iso pos"); row_name[count_rows] = string_hsave(token); count_rows++; - my_array[count_rows * max_column_count + col_phases + i] = + my_array[(size_t)count_rows * (size_t)max_column_count + (size_t)col_phases + (size_t)i] = inv_ptr->phases[i].isotopes[j].ratio_uncertainty; - my_array[count_rows * max_column_count + column] = -1.0; + my_array[(size_t)count_rows * (size_t)max_column_count + (size_t)column] = -1.0; sprintf(token, "%s %s", inv_ptr->phases[i].phase->name, "iso neg"); row_name[count_rows] = string_hsave(token); @@ -3942,17 +3932,17 @@ phase_isotope_inequalities(struct inverse *inv_ptr) } else if (inv_ptr->phases[i].constraint == DISSOLVE) { - my_array[count_rows * max_column_count + col_phases + i] = + my_array[(size_t)count_rows * (size_t)max_column_count + (size_t)col_phases + (size_t)i] = -inv_ptr->phases[i].isotopes[j].ratio_uncertainty; - my_array[count_rows * max_column_count + column] = -1.0; + my_array[(size_t)count_rows * (size_t)max_column_count + (size_t)column] = -1.0; sprintf(token, "%s %s", inv_ptr->phases[i].phase->name, "iso pos"); row_name[count_rows] = string_hsave(token); count_rows++; - my_array[count_rows * max_column_count + col_phases + i] = + my_array[(size_t)count_rows * (size_t)max_column_count + (size_t)col_phases + (size_t)i] = -inv_ptr->phases[i].isotopes[j].ratio_uncertainty; - my_array[count_rows * max_column_count + column] = 1.0; + my_array[(size_t)count_rows * (size_t)max_column_count + (size_t)column] = 1.0; sprintf(token, "%s %s", inv_ptr->phases[i].phase->name, "iso neg"); row_name[count_rows] = string_hsave(token); diff --git a/phreeqcpp/isotopes.cpp b/phreeqcpp/isotopes.cpp index dcc3ed88..21b8515c 100644 --- a/phreeqcpp/isotopes.cpp +++ b/phreeqcpp/isotopes.cpp @@ -247,10 +247,8 @@ read_calculate_values(void) { length = (int) strlen(calculate_value_ptr->commands); line_length = (int) strlen(line); - calculate_value_ptr->commands = - (char *) PHRQ_realloc(calculate_value_ptr->commands, - (size_t) (length + line_length + - 2) * sizeof(char)); + calculate_value_ptr->commands = (char *)PHRQ_realloc(calculate_value_ptr->commands, + ((size_t)length + (size_t)line_length + 2) * sizeof(char)); if (calculate_value_ptr->commands == NULL) malloc_error(); calculate_value_ptr->commands[length] = ';'; @@ -1547,8 +1545,7 @@ calculate_value_alloc(void) */ { struct calculate_value *calculate_value_ptr; - calculate_value_ptr = - (struct calculate_value *) + calculate_value_ptr = (struct calculate_value *) PHRQ_malloc(sizeof(struct calculate_value)); if (calculate_value_ptr == NULL) malloc_error(); diff --git a/phreeqcpp/kinetics.cpp b/phreeqcpp/kinetics.cpp index e18f3dd7..b4f595bf 100644 --- a/phreeqcpp/kinetics.cpp +++ b/phreeqcpp/kinetics.cpp @@ -858,8 +858,9 @@ rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, /* define reaction for calculating k5 */ rk_moles[k + j] = kinetics_comp_ptr->Get_moles(); kinetics_comp_ptr->Set_moles(b51 * rk_moles[j] - + 2.5 * rk_moles[n_reactions + j] - + b53 * rk_moles[2 * n_reactions + j] + b54 * rk_moles[k + j]); + + 2.5 * rk_moles[(size_t)n_reactions + j] + + b53 * rk_moles[2 * (size_t)n_reactions + j] + + b54 * rk_moles[(size_t)k + (size_t)j]); } if (moles_reduction > 1.0) goto MOLES_TOO_LARGE; @@ -910,9 +911,10 @@ rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, /* define reaction for calculating k6 */ rk_moles[k + j] = kinetics_comp_ptr->Get_moles(); kinetics_comp_ptr->Set_moles(b61 * rk_moles[j] - + b62 * rk_moles[n_reactions + j] - + b63 * rk_moles[2 * n_reactions + j] - + b64 * rk_moles[3 * n_reactions + j] + b65 * rk_moles[k + j]); + + b62 * rk_moles[(size_t)n_reactions + j] + + b63 * rk_moles[2 * (size_t)n_reactions + j] + + b64 * rk_moles[3 * (size_t)n_reactions + j] + + b65 * rk_moles[(size_t)k + (size_t)j]); } if (moles_reduction > 1.0) goto MOLES_TOO_LARGE; @@ -964,10 +966,10 @@ rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, { cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); l_error = fabs(dc1 * rk_moles[j] - + dc3 * rk_moles[2 * n_reactions + j] - + dc4 * rk_moles[3 * n_reactions + j] - + dc5 * rk_moles[4 * n_reactions + j] - + dc6 * rk_moles[5 * n_reactions + j]); + + dc3 * rk_moles[2 * (size_t)n_reactions + (size_t)j] + + dc4 * rk_moles[3 * (size_t)n_reactions + (size_t)j] + + dc5 * rk_moles[4 * (size_t)n_reactions + (size_t)j] + + dc6 * rk_moles[5 * (size_t)n_reactions + (size_t)j]); /* tol is in moles/l */ l_error /= kinetics_comp_ptr->Get_tol(); @@ -998,9 +1000,9 @@ rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver, { cxxKineticsComp * kinetics_comp_ptr = &(kinetics_ptr->Get_kinetics_comps()[j]); kinetics_comp_ptr->Set_moles(c1 * rk_moles[j] - + c3 * rk_moles[2 * n_reactions + j] - + c4 * rk_moles[3 * n_reactions + j] - + c6 * rk_moles[5 * n_reactions + j]); + + c3 * rk_moles[2 * (size_t)n_reactions + (size_t)j] + + c4 * rk_moles[3 * (size_t)n_reactions + (size_t)j] + + c6 * rk_moles[5 * (size_t)n_reactions + (size_t)j]); } calc_final_kinetic_reaction(kinetics_ptr); for (size_t j = 0; j < kinetics_ptr->Get_kinetics_comps().size(); j++) diff --git a/phreeqcpp/model.cpp b/phreeqcpp/model.cpp index e40fb809..8eaa570e 100644 --- a/phreeqcpp/model.cpp +++ b/phreeqcpp/model.cpp @@ -1008,11 +1008,11 @@ ineq(int in_kode) { for (j = 0; j < count_unknowns; j++) { - my_array[j * (count_unknowns + 1) + i] = 0.0; + my_array[(size_t)j * ((size_t)count_unknowns + 1) + i] = 0.0; } for (j = 0; j < count_unknowns + 1; j++) { - my_array[i * (count_unknowns + 1) + j] = 0.0; + my_array[(size_t)i * ((size_t)count_unknowns + 1) + (size_t)j] = 0.0; } } } @@ -1046,24 +1046,24 @@ ineq(int in_kode) if (x[i]->type == SURFACE_CB1 && x[j]->type == SURFACE_CB2) continue; - if (fabs(my_array[j * (count_unknowns + 1) + i]) > max) + if (fabs(my_array[(size_t)j * ((size_t)count_unknowns + 1) + (size_t)i]) > max) { - max = fabs(my_array[j * (count_unknowns + 1) + i]); + max = fabs(my_array[(size_t)j * ((size_t)count_unknowns + 1) + (size_t)i]); if (max > min_value) break; } } if (diagonal_scale == TRUE) { - if (fabs(my_array[i * (count_unknowns + 1) + i]) < min_value) + if (fabs(my_array[(size_t)i * ((size_t)count_unknowns + 1) + (size_t)i]) < min_value) { - max = fabs(my_array[i * (count_unknowns + 1) + i]); + max = fabs(my_array[(size_t)i * ((size_t)count_unknowns + 1) + (size_t)i]); } } if (max == 0) { - my_array[i * (count_unknowns + 1) + i] = 1e-5 * x[i]->moles; + my_array[(size_t)i * ((size_t)count_unknowns + 1) + (size_t)i] = 1e-5 * x[i]->moles; max = fabs(1e-5 * x[i]->moles); } } @@ -1074,12 +1074,9 @@ ineq(int in_kode) min = 1e-12; min = MIN_TOTAL; - my_array[x[i]->number * (count_unknowns + 1) + x[i]->number] += min; - if (fabs - (my_array[x[i]->number * (count_unknowns + 1) + x[i]->number]) < - min) - my_array[x[i]->number * (count_unknowns + 1) + x[i]->number] = - min; + my_array[(size_t)x[i]->number * ((size_t)count_unknowns + 1) + (size_t)x[i]->number] += min; + if (fabs(my_array[(size_t)x[i]->number * ((size_t)count_unknowns + 1) + (size_t)x[i]->number]) < min) + my_array[(size_t)x[i]->number * ((size_t)count_unknowns + 1) + (size_t)x[i]->number] = min; max = 0.0; for (j = 0; j < count_unknowns; j++) @@ -1092,9 +1089,9 @@ ineq(int in_kode) x[j]->type != EXCH && x[j]->type != MH && x[j]->type != MH2O) continue; - if (fabs(my_array[j * (count_unknowns + 1) + i]) > max) + if (fabs(my_array[(size_t)j * ((size_t)count_unknowns + 1) + (size_t)i]) > max) { - max = fabs(my_array[j * (count_unknowns + 1) + i]); + max = fabs(my_array[(size_t)j * ((size_t)count_unknowns + 1) + (size_t)i]); if (max > min_value) break; } @@ -1111,7 +1108,7 @@ ineq(int in_kode) } for (j = 0; j < count_unknowns; j++) { - my_array[j * (count_unknowns + 1) + i] *= min_value / max; + my_array[(size_t)j * ((size_t)count_unknowns + 1) + (size_t)i] *= min_value / max; } normal[i] = min_value / max; } @@ -1174,9 +1171,9 @@ ineq(int in_kode) else { /* Copy in saturation index equation (has mass or supersaturated) */ - memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), - (void *) &(my_array[i * (count_unknowns + 1)]), - ((size_t) count_unknowns + 1) * sizeof(LDBLE)); + memcpy((void *) &(ineq_array[(size_t)l_count_rows * (size_t)max_column_count]), + (void *) &(my_array[(size_t)i * ((size_t)count_unknowns + 1)]), + ((size_t)count_unknowns + 1) * sizeof(LDBLE)); back_eq[l_count_rows] = i; //if (it->second.Get_add_formula().size() == 0 if (comp_ptr->Get_add_formula().size() == 0 @@ -1191,8 +1188,7 @@ ineq(int in_kode) { for (j = 0; j < count_unknowns + 1; j++) { - ineq_array[l_count_rows * max_column_count + j] *= - pp_scale; + ineq_array[(size_t)l_count_rows * (size_t)max_column_count + (size_t)j] *= pp_scale; } } @@ -1208,9 +1204,9 @@ ineq(int in_kode) /* * Alkalinity and solution phase boundary */ - memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), - (void *) &(my_array[i * (count_unknowns + 1)]), - ((size_t) count_unknowns + 1) * sizeof(LDBLE)); + memcpy((void *) &(ineq_array[(size_t)l_count_rows * (size_t)max_column_count]), + (void *) &(my_array[(size_t)i * ((size_t)count_unknowns + 1)]), + ((size_t)count_unknowns + 1) * sizeof(LDBLE)); back_eq[l_count_rows] = i; l_count_rows++; /* @@ -1219,9 +1215,9 @@ ineq(int in_kode) } else if (x[i]->type == GAS_MOLES && gas_in == TRUE) { - memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), - (void *) &(my_array[i * (count_unknowns + 1)]), - ((size_t) count_unknowns + 1) * sizeof(LDBLE)); + memcpy((void *) &(ineq_array[(size_t)l_count_rows * (size_t)max_column_count]), + (void *) &(my_array[(size_t)i * ((size_t)count_unknowns + 1)]), + ((size_t)count_unknowns + 1) * sizeof(LDBLE)); back_eq[l_count_rows] = i; res[l_count_rows] = 1.0; @@ -1236,9 +1232,9 @@ ineq(int in_kode) } else if (x[i]->type == SS_MOLES && x[i]->ss_in == TRUE) { - memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), - (void *) &(my_array[i * (count_unknowns + 1)]), - ((size_t) count_unknowns + 1) * sizeof(LDBLE)); + memcpy((void *) &(ineq_array[(size_t)l_count_rows * (size_t)max_column_count]), + (void *) &(my_array[(size_t)i * ((size_t)count_unknowns + 1)]), + ((size_t)count_unknowns + 1) * sizeof(LDBLE)); back_eq[l_count_rows] = i; res[l_count_rows] = 1.0; if (in_kode != 1) @@ -1267,9 +1263,9 @@ ineq(int in_kode) } if ((x[i]->type == SURFACE_CB || x[i]->type == SURFACE_CB1 || x[i]->type == SURFACE_CB2) - && x[i - 1]->phase_unknown != NULL) + && x[(size_t)i - 1]->phase_unknown != NULL) { - comp_ptr1 = pp_assemblage_ptr->Find(x[i-1]->phase_unknown->phase->name); + comp_ptr1 = pp_assemblage_ptr->Find(x[(size_t)i-1]->phase_unknown->phase->name); } if (x[i]->type != SOLUTION_PHASE_BOUNDARY && x[i]->type != ALK && @@ -1309,7 +1305,7 @@ ineq(int in_kode) continue; if ((x[i]->type == SURFACE_CB || x[i]->type == SURFACE_CB1 || x[i]->type == SURFACE_CB2) - && x[i - 1]->phase_unknown != NULL) + && x[(size_t)i - 1]->phase_unknown != NULL) { cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[i]->surface_charge); if (charge_ptr->Get_grams() <= MIN_RELATED_SURFACE && @@ -1318,26 +1314,26 @@ ineq(int in_kode) continue; } } - memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), - (void *) &(my_array[i * (count_unknowns + 1)]), - ((size_t) count_unknowns + 1) * sizeof(LDBLE)); + memcpy((void *) &(ineq_array[(size_t)l_count_rows * (size_t)max_column_count]), + (void *) &(my_array[(size_t)i * ((size_t)count_unknowns + 1)]), + ((size_t)count_unknowns + 1) * sizeof(LDBLE)); back_eq[l_count_rows] = i; if (mass_water_switch == TRUE && x[i] == mass_hydrogen_unknown) { k = mass_oxygen_unknown->number; for (j = 0; j < count_unknowns; j++) { - ineq_array[l_count_rows * max_column_count + j] -= - 2 * my_array[k * (count_unknowns + 1) + j]; + ineq_array[(size_t)l_count_rows * (size_t)max_column_count + (size_t)j] -= + 2 * my_array[(size_t)k * ((size_t)count_unknowns + 1) + (size_t)j]; } } l_count_rows++; } else if (x[i]->type == PITZER_GAMMA && full_pitzer == TRUE) { - memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), - (void *) &(my_array[i * (count_unknowns + 1)]), - ((size_t) count_unknowns + 1) * sizeof(LDBLE)); + memcpy((void *) &(ineq_array[(size_t)l_count_rows * (size_t)max_column_count]), + (void *) &(my_array[(size_t)i * ((size_t)count_unknowns + 1)]), + ((size_t)count_unknowns + 1) * sizeof(LDBLE)); back_eq[l_count_rows] = i; l_count_rows++; } @@ -1379,13 +1375,12 @@ ineq(int in_kode) /* Pure phase is present, force Mass transfer to be <= amount of mineral remaining */ //memcpy((void *) - // &(ineq_array[l_count_rows * max_column_count]), + // &(ineq_array[(size_t)l_count_rows * (size_t)max_column_count]), // (void *) &(zero[0]), // ((size_t) count_unknowns + 1) * sizeof(LDBLE)); - memset(&ineq_array[l_count_rows * max_column_count], 0, ((size_t) count_unknowns + 1) * sizeof(LDBLE)); - ineq_array[l_count_rows * max_column_count + i] = 1.0; - ineq_array[l_count_rows * max_column_count + - count_unknowns] = x[i]->moles; + memset(&ineq_array[(size_t)l_count_rows * (size_t)max_column_count], 0, ((size_t) count_unknowns + 1) * sizeof(LDBLE)); + ineq_array[(size_t)l_count_rows * (size_t)max_column_count + i] = 1.0; + ineq_array[(size_t)l_count_rows * (size_t)max_column_count + (size_t)count_unknowns] = x[i]->moles; back_eq[l_count_rows] = i; l_count_rows++; } @@ -1393,13 +1388,12 @@ ineq(int in_kode) if (x[i]->dissolve_only == TRUE) { //memcpy((void *) - // &(ineq_array[l_count_rows * max_column_count]), + // &(ineq_array[(size_t)l_count_rows * (size_t)max_column_count]), // (void *) &(zero[0]), // ((size_t) count_unknowns + 1) * sizeof(LDBLE)); - memset(&(ineq_array[l_count_rows * max_column_count]), 0, ((size_t)count_unknowns + 1) * sizeof(LDBLE)); - ineq_array[l_count_rows * max_column_count + i] = -1.0; - ineq_array[l_count_rows * max_column_count + - count_unknowns] = + memset(&(ineq_array[(size_t)l_count_rows * (size_t)max_column_count]), 0, ((size_t)count_unknowns + 1) * sizeof(LDBLE)); + ineq_array[(size_t)l_count_rows * (size_t)max_column_count + i] = -1.0; + ineq_array[(size_t)l_count_rows * (size_t)max_column_count + (size_t)count_unknowns] = comp_ptr->Get_initial_moles() - x[i]->moles; back_eq[l_count_rows] = i; l_count_rows++; @@ -1416,22 +1410,22 @@ ineq(int in_kode) { if (x[i]->type == MH2O) { - memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), - (void *) &(my_array[i * (count_unknowns + 1)]), - ((size_t) count_unknowns + 1) * sizeof(LDBLE)); + memcpy((void *) &(ineq_array[(size_t)l_count_rows * (size_t)max_column_count]), + (void *) &(my_array[(size_t)i * ((size_t)count_unknowns + 1)]), + ((size_t)count_unknowns + 1) * sizeof(LDBLE)); back_eq[l_count_rows] = i; for (j = 0; j < count_unknowns; j++) { if (x[j]->type < PP) { - ineq_array[l_count_rows * max_column_count + j] = 0.0; + ineq_array[(size_t)l_count_rows * (size_t)max_column_count + j] = 0.0; } else { /*ineq_array[l_count_rows*max_column_count + j] = -ineq_array[l_count_rows*max_column_count + j]; */ } } - ineq_array[l_count_rows * max_column_count + count_unknowns] = + ineq_array[(size_t)l_count_rows * (size_t)max_column_count + (size_t)count_unknowns] = 0.5 * x[i]->moles; l_count_rows++; } @@ -1459,7 +1453,7 @@ ineq(int in_kode) { for (j = 0; j < l_count_rows; j++) { - ineq_array[j * max_column_count + i] = 0.0; + ineq_array[(size_t)j * (size_t)max_column_count + i] = 0.0; } } if (x[i]->dissolve_only == TRUE) @@ -1470,7 +1464,7 @@ ineq(int in_kode) { for (j = 0; j < l_count_rows; j++) { - ineq_array[j * max_column_count + i] = 0.0; + ineq_array[(size_t)j * (size_t)max_column_count + (size_t)i] = 0.0; } } } @@ -1490,7 +1484,7 @@ ineq(int in_kode) { for (j = 0; j < l_count_rows; j++) { - ineq_array[j * max_column_count + i] = 0.0; + ineq_array[(size_t)j * (size_t)max_column_count + i] = 0.0; } } } @@ -1512,14 +1506,14 @@ ineq(int in_kode) } if ((x[i]->type == SURFACE_CB || x[i]->type == SURFACE_CB1 || x[i]->type == SURFACE_CB2) - && (x[i - 1]->phase_unknown != NULL)) + && (x[(size_t)i - 1]->phase_unknown != NULL)) { - comp_ptr1 = pp_assemblage_ptr->Find(x[i-1]->phase_unknown->phase->name); + comp_ptr1 = pp_assemblage_ptr->Find(x[(size_t)i-1]->phase_unknown->phase->name); } LDBLE grams = 0; if ((x[i]->type == SURFACE_CB || x[i]->type == SURFACE_CB1 || x[i]->type == SURFACE_CB2) - && x[i - 1]->phase_unknown != NULL) + && x[(size_t)i - 1]->phase_unknown != NULL) { cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[i]->surface_charge); grams = charge_ptr->Get_grams(); @@ -1529,13 +1523,13 @@ ineq(int in_kode) comp_ptr->Get_add_formula().size() == 0) || ((x[i]->type == SURFACE_CB || x[i]->type == SURFACE_CB1 || x[i]->type == SURFACE_CB2) - && x[i - 1]->phase_unknown != NULL && + && x[(size_t)i - 1]->phase_unknown != NULL && grams <= MIN_RELATED_SURFACE && comp_ptr1->Get_add_formula().size() == 0)) { for (j = 0; j < l_count_rows; j++) { - ineq_array[j * max_column_count + i] = 0.0; + ineq_array[(size_t)j * (size_t)max_column_count + (size_t)i] = 0.0; } } } @@ -1549,7 +1543,7 @@ ineq(int in_kode) for (i = 0; i < count_unknowns; i++) { if ((x[i]->type == SURFACE_CB || x[i]->type == SURFACE_CB1 - || x[i]->type == SURFACE_CB2) && x[i - 1]->phase_unknown == NULL) + || x[i]->type == SURFACE_CB2) && x[(size_t)i - 1]->phase_unknown == NULL) { cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[i]->surface_charge); grams = charge_ptr->Get_grams(); @@ -1559,12 +1553,12 @@ ineq(int in_kode) x[i]->moles <= MIN_RELATED_SURFACE) || ((x[i]->type == SURFACE_CB || x[i]->type == SURFACE_CB1 || x[i]->type == SURFACE_CB2) - && x[i - 1]->phase_unknown == NULL + && x[(size_t)i - 1]->phase_unknown == NULL && grams <= MIN_RELATED_SURFACE)) { for (j = 0; j < l_count_rows; j++) { - ineq_array[j * max_column_count + i] = 0.0; + ineq_array[(size_t)j * (size_t)max_column_count + (size_t)i] = 0.0; } } } @@ -1578,16 +1572,16 @@ ineq(int in_kode) { if (x[i]->type == GAS_MOLES) { - //memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), + //memcpy((void *) &(ineq_array[(size_t)l_count_rows * (size_t)max_column_count]), // (void *) &(zero[0]), // ((size_t) count_unknowns + 1) * sizeof(LDBLE)); - //std::fill(&(ineq_array[l_count_rows * max_column_count]), + //std::fill(&(ineq_array[(size_t)l_count_rows * (size_t)max_column_count]), // &(ineq_array[l_count_rows * max_column_count + count_unknowns]), // 0.0e0); - memset(&(ineq_array[l_count_rows * max_column_count]), 0, + memset(&(ineq_array[(size_t)l_count_rows * (size_t)max_column_count]), 0, ((size_t)count_unknowns + 1) * sizeof(LDBLE)); - ineq_array[l_count_rows * max_column_count + i] = -1.0; - ineq_array[l_count_rows * max_column_count + count_unknowns] = + ineq_array[(size_t)l_count_rows * (size_t)max_column_count + (size_t)i] = -1.0; + ineq_array[(size_t)l_count_rows * (size_t)max_column_count + (size_t)count_unknowns] = x[i]->moles; back_eq[l_count_rows] = i; l_count_rows++; @@ -1606,7 +1600,7 @@ ineq(int in_kode) i = gas_unknown->number; for (j = 0; j < l_count_rows; j++) { - ineq_array[j * max_column_count + i] = 0.0; + ineq_array[(size_t)j * (size_t)max_column_count + (size_t)i] = 0.0; } } /* @@ -1621,13 +1615,13 @@ ineq(int in_kode) break; if (x[i]->phase->in == TRUE && x[i]->ss_in == TRUE) { - //memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), + //memcpy((void *) &(ineq_array[(size_t)l_count_rows * (size_t)max_column_count]), // (void *) &(zero[0]), // ((size_t) count_unknowns + 1) * sizeof(LDBLE)); - memset(&(ineq_array[l_count_rows * max_column_count]), 0, + memset(&(ineq_array[(size_t)l_count_rows * (size_t)max_column_count]), 0, ((size_t)count_unknowns + 1) * sizeof(LDBLE)); - ineq_array[l_count_rows * max_column_count + i] = 1.0; - ineq_array[l_count_rows * max_column_count + count_unknowns] = + ineq_array[(size_t)l_count_rows * (size_t)max_column_count + (size_t)i] = 1.0; + ineq_array[(size_t)l_count_rows * (size_t)max_column_count + (size_t)count_unknowns] = 0.99 * x[i]->moles - MIN_TOTAL_SS; back_eq[l_count_rows] = i; l_count_rows++; @@ -1636,7 +1630,7 @@ ineq(int in_kode) { for (j = 0; j < l_count_rows; j++) { - ineq_array[j * max_column_count + i] = 0.0; + ineq_array[(size_t)j * (size_t)max_column_count + (size_t)i] = 0.0; } } } @@ -1650,15 +1644,15 @@ ineq(int in_kode) { if (x[i]->type == MB && x[i]->moles < 0.0) { - memcpy((void *) &(ineq_array[l_count_rows * max_column_count]), - (void *) &(my_array[i * (count_unknowns + 1)]), + memcpy((void *) &(ineq_array[(size_t)l_count_rows * (size_t)max_column_count]), + (void *) &(my_array[(size_t)i * ((size_t)count_unknowns + 1)]), ((size_t) count_unknowns + 1) * sizeof(LDBLE)); back_eq[l_count_rows] = i; for (j = 0; j < count_unknowns; j++) { if (x[j]->type < PP) { - ineq_array[l_count_rows * max_column_count + j] = 0.0; + ineq_array[(size_t)l_count_rows * (size_t)max_column_count + (size_t)j] = 0.0; } } l_count_rows++; @@ -1673,7 +1667,7 @@ ineq(int in_kode) k = mass_oxygen_unknown->number; for (j = 0; j < l_count_rows + 1; j++) { - ineq_array[j * max_column_count + k] = 0; + ineq_array[(size_t)j * (size_t)max_column_count + (size_t)k] = 0; } } /* @@ -1686,7 +1680,7 @@ ineq(int in_kode) { for (j = 0; j < l_count_rows; j++) { - ineq_array[j * max_column_count + i] *= pp_column_scale; + ineq_array[(size_t)j * (size_t)max_column_count + (size_t)i] *= pp_column_scale; } normal[i] = pp_column_scale; } @@ -1720,13 +1714,13 @@ ineq(int in_kode) { for (int j = 0; j < n; j++) { - ineq_array[i*(n+2) + j] = ineq_array[i*(count_unknowns+2) +j]; + ineq_array[(size_t)i*((size_t)n+2) + (size_t)j] = ineq_array[(size_t)i*((size_t)count_unknowns+2) + (size_t)j]; } //if (i > 0) //{ // memcpy((void *) &ineq_array[i*(n+2)], (void *) &ineq_array[i*(count_unknowns+2)], (size_t) (n) * sizeof(LDBLE)); //} - ineq_array[i*(n+2) + n] = ineq_array[i*(count_unknowns+2) + count_unknowns]; + ineq_array[(size_t)i*((size_t)n+2) + (size_t)n] = ineq_array[(size_t)i*((size_t)count_unknowns+2) + (size_t)count_unknowns]; } } else @@ -1866,7 +1860,7 @@ ineq(int in_kode) { for (j = 0; j < count_unknowns; j++) { - my_array[j * (count_unknowns + 1) + i] /= normal[i]; + my_array[(size_t)j * ((size_t)count_unknowns + 1) + (size_t)i] /= normal[i]; } } } @@ -1947,7 +1941,7 @@ jacobian_sums(void) } for (i = 1; i < count_unknowns; i++) { - memcpy((void *) &(my_array[i * (count_unknowns + 1)]), + memcpy((void *) &(my_array[(size_t)i * ((size_t)count_unknowns + 1)]), (void *) &(my_array[0]), (size_t) count_unknowns * sizeof(LDBLE)); } /* @@ -1982,18 +1976,18 @@ jacobian_sums(void) for (i = 0; i < count_unknowns; i++) { // using straight mu equation - my_array[mu_unknown->number * (count_unknowns + 1) + i] *= 0.5; + my_array[(size_t)mu_unknown->number * ((size_t)count_unknowns + 1) + i] *= 0.5; } - my_array[mu_unknown->number * (count_unknowns + 1) + - mu_unknown->number] -= mass_water_aq_x; + my_array[(size_t)mu_unknown->number * ((size_t)count_unknowns + 1) + + (size_t)mu_unknown->number] -= mass_water_aq_x; } /* * Mass of oxygen */ if (mass_oxygen_unknown != NULL && mu_unknown != NULL) { - my_array[mu_unknown->number * (count_unknowns + 1) + - mass_oxygen_unknown->number] -= mu_x * mass_water_aq_x; + my_array[(size_t)mu_unknown->number * ((size_t)count_unknowns + 1) + + (size_t)mass_oxygen_unknown->number] -= mu_x * mass_water_aq_x; } /* * Activity of water @@ -2012,16 +2006,16 @@ jacobian_sums(void) for (i = 0; i < count_unknowns; i++) { - my_array[ah2o_unknown->number * (count_unknowns + 1) + i] *= factor; + my_array[(size_t)ah2o_unknown->number * ((size_t)count_unknowns + 1) + (size_t)i] *= factor; } // activity of water term - my_array[ah2o_unknown->number * (count_unknowns + 1) + - ah2o_unknown->number] -= exp(s_h2o->la * LOG_10); + my_array[(size_t)ah2o_unknown->number * ((size_t)count_unknowns + 1) + + (size_t)ah2o_unknown->number] -= exp(s_h2o->la * LOG_10); // mass of water term if (mass_oxygen_unknown != NULL) { - my_array[ah2o_unknown->number * (count_unknowns + 1) + mass_oxygen_unknown->number] -= + my_array[(size_t)ah2o_unknown->number * ((size_t)count_unknowns + 1) + (size_t)mass_oxygen_unknown->number] -= a*y_sum*(x_h2o*(0.5*tanh(lim) + 0.5) + (47.5*x_h2o - 50.0*a*y_sum)/(cosh(lim)*cosh(lim))) / (x_h2o*x_h2o*x_h2o); } @@ -2030,13 +2024,13 @@ jacobian_sums(void) { for (i = 0; i < count_unknowns; i++) { - my_array[ah2o_unknown->number * (count_unknowns + 1) + i] *= -AH2O_FACTOR; + my_array[(size_t)ah2o_unknown->number * ((size_t)count_unknowns + 1) + i] *= -AH2O_FACTOR; } - my_array[ah2o_unknown->number * (count_unknowns + 1) + ah2o_unknown->number] -= + my_array[(size_t)ah2o_unknown->number * ((size_t)count_unknowns + 1) + (size_t)ah2o_unknown->number] -= mass_water_aq_x * exp(s_h2o->la * LOG_10); if (mass_oxygen_unknown != NULL) { - my_array[ah2o_unknown->number * (count_unknowns + 1) + mass_oxygen_unknown->number] -= + my_array[(size_t)ah2o_unknown->number * ((size_t)count_unknowns + 1) + (size_t)mass_oxygen_unknown->number] -= (exp(s_h2o->la * LOG_10) - 1) * mass_water_aq_x; } } @@ -2065,18 +2059,15 @@ jacobian_sums(void) { for (j = 0; j < count_unknowns; j++) { - my_array[x[i]->number * (count_unknowns + 1) + j] *= - F_C_MOL / (charge_ptr->Get_specific_area() * - charge_ptr->Get_grams()); + my_array[(size_t)x[i]->number * ((size_t)count_unknowns + 1) + (size_t)j] *= + F_C_MOL / (charge_ptr->Get_specific_area() * charge_ptr->Get_grams()); } - my_array[x[i]->number * (count_unknowns + 1) + x[i]->number] -= - sinh_constant * sqrt(mu_x) * - cosh(x[i]->master[0]->s->la * LOG_10); + my_array[(size_t)x[i]->number * ((size_t)count_unknowns + 1) + (size_t)x[i]->number] -= + sinh_constant * sqrt(mu_x) * cosh(x[i]->master[0]->s->la * LOG_10); if (mu_unknown != NULL) { - my_array[x[i]->number * (count_unknowns + 1) + - mu_unknown->number] -= - 0.5 * sinh_constant / sqrt(mu_x) * + my_array[(size_t)x[i]->number * ((size_t)count_unknowns + 1) + + (size_t)mu_unknown->number] -= 0.5 * sinh_constant / sqrt(mu_x) * sinh(x[i]->master[0]->s->la * LOG_10); } } @@ -2095,13 +2086,11 @@ jacobian_sums(void) { for (j = 0; j < count_unknowns; j++) { - my_array[x[i]->number * (count_unknowns + 1) + j] *= - F_C_MOL / (charge_ptr->Get_specific_area() * - charge_ptr->Get_grams()); + my_array[(size_t)x[i]->number * ((size_t)count_unknowns + 1) + (size_t)j] *= + F_C_MOL / (charge_ptr->Get_specific_area() * charge_ptr->Get_grams()); } - my_array[x[i]->number * (count_unknowns + 1) + x[i]->number] -= - charge_ptr->Get_capacitance0() * 2 * R_KJ_DEG_MOL * - tk_x * LOG_10 / F_KJ_V_EQ; + my_array[(size_t)x[i]->number * ((size_t)count_unknowns + 1) + (size_t)x[i]->number] -= + charge_ptr->Get_capacitance0() * 2 * R_KJ_DEG_MOL * tk_x * LOG_10 / F_KJ_V_EQ; } } } @@ -4542,7 +4531,7 @@ residuals(void) /* * Store residuals in array */ - my_array[(i + 1) * (count_unknowns + 1) - 1] = residual[i]; + my_array[((size_t)i + 1) * ((size_t)count_unknowns + 1) - 1] = residual[i]; sum_residual += fabs(residual[i]); } /* @@ -5350,8 +5339,8 @@ numerical_jacobian(void) } for (i = 1; i < count_unknowns; i++) { - memcpy((void *) &(my_array[i * (count_unknowns + 1)]), - (void *) &(my_array[0]), (size_t) count_unknowns * sizeof(LDBLE)); + memcpy((void *) &(my_array[(size_t)i * ((size_t)count_unknowns + 1)]), + (void *) &(my_array[0]), (size_t)count_unknowns * sizeof(LDBLE)); } base = (LDBLE *) PHRQ_malloc((size_t) count_unknowns * sizeof(LDBLE)); @@ -5466,13 +5455,13 @@ numerical_jacobian(void) LDBLE t = (LDBLE) pow((LDBLE) 10.0, (LDBLE) (DBL_MAX_10_EXP - 50.0)); if (residual[j] > t) { - my_array[j * (count_unknowns + 1) + i] = -pow(10.0, DBL_MAX_10_EXP - 50.0); + my_array[(size_t)j * ((size_t)count_unknowns + 1) + (size_t)i] = -pow(10.0, DBL_MAX_10_EXP - 50.0); } else { - my_array[j * (count_unknowns + 1) + i] = -(residual[j] - base[j]) / d2; + my_array[(size_t)j * ((size_t)count_unknowns + 1) + (size_t)i] = -(residual[j] - base[j]) / d2; if (x[i]->type == MH2O) // DL_pitz - my_array[j * (count_unknowns + 1) + i] *= mass_water_aq_x; + my_array[(size_t)j * ((size_t)count_unknowns + 1) + (size_t)i] *= mass_water_aq_x; } } else if (residual[j] < -1.0e101) @@ -5480,21 +5469,21 @@ numerical_jacobian(void) LDBLE t = pow((LDBLE) 10.0, (LDBLE) (DBL_MIN_10_EXP + 50.0)); if (residual[j] < -t) { - my_array[j * (count_unknowns + 1) + i] = pow(10.0, DBL_MIN_10_EXP + 50.0); + my_array[(size_t)j * ((size_t)count_unknowns + 1) + (size_t)i] = pow(10.0, DBL_MIN_10_EXP + 50.0); } else { - my_array[j * (count_unknowns + 1) + i] = -(residual[j] - base[j]) / d2; + my_array[(size_t)j * ((size_t)count_unknowns + 1) + (size_t)i] = -(residual[j] - base[j]) / d2; if (x[i]->type == MH2O) // DL_pitz - my_array[j * (count_unknowns + 1) + i] *= mass_water_aq_x; + my_array[(size_t)j * ((size_t)count_unknowns + 1) + (size_t)i] *= mass_water_aq_x; } } else { - my_array[j * (count_unknowns + 1) + i] = -(residual[j] - base[j]) / d2; + my_array[(size_t)j * ((size_t)count_unknowns + 1) + (size_t)i] = -(residual[j] - base[j]) / d2; if (x[i]->type == MH2O) // DL_pitz - my_array[j * (count_unknowns + 1) + i] *= mass_water_aq_x; - if (!PHR_ISFINITE(my_array[j * (count_unknowns + 1) + i])) + my_array[(size_t)j * ((size_t)count_unknowns + 1) + (size_t)i] *= mass_water_aq_x; + if (!PHR_ISFINITE(my_array[(size_t)j * ((size_t)count_unknowns + 1) + (size_t)i])) { //fprintf(stderr, "oops, got NaN: %e, %e, %e, %e\n", residual[j], base[j], d2, array[j * (count_unknowns + 1) + i]); } @@ -5518,10 +5507,10 @@ numerical_jacobian(void) break; case MH: s_eminus->la -= d; - if (my_array[i * (count_unknowns + 1) + i] == 0) + if (my_array[(size_t)i * ((size_t)count_unknowns + 1) + (size_t)i] == 0) { /*output_msg(sformatf( "Zero diagonal for MH\n")); */ - my_array[i * (count_unknowns + 1) + i] = + my_array[(size_t)i * ((size_t)count_unknowns + 1) + (size_t)i] = under(s_h2->lm) * 2; } break; diff --git a/phreeqcpp/parse.cpp b/phreeqcpp/parse.cpp index 147edd65..67fe9f76 100644 --- a/phreeqcpp/parse.cpp +++ b/phreeqcpp/parse.cpp @@ -145,9 +145,8 @@ parse_eq(char *eqn, struct elt_list **elt_ptr, int association) /* * Malloc space and store element data for return */ - *elt_ptr = - (struct elt_list *) PHRQ_malloc((size_t) (count_elts + 1) * - sizeof(struct elt_list)); + *elt_ptr = (struct elt_list *) PHRQ_malloc(((size_t)count_elts + 1) * + sizeof(struct elt_list)); if (*elt_ptr == NULL) { malloc_error(); diff --git a/phreeqcpp/pitzer.cpp b/phreeqcpp/pitzer.cpp index e13443ea..4036b9f7 100644 --- a/phreeqcpp/pitzer.cpp +++ b/phreeqcpp/pitzer.cpp @@ -2084,9 +2084,9 @@ Restart: residuals(); for (j = 0; j < count_unknowns; j++) { - my_array[j * (count_unknowns + 1) + i] = -(residual[j] - base[j]) / d2; + my_array[(size_t)j * ((size_t)count_unknowns + 1) + (size_t)i] = -(residual[j] - base[j]) / d2; if (x[i]->type == MH2O) // DL_pitz - my_array[j * (count_unknowns + 1) + i] *= mass_water_aq_x; + my_array[(size_t)j * ((size_t)count_unknowns + 1) + (size_t)i] *= mass_water_aq_x; } switch (x[i]->type) { @@ -2104,9 +2104,9 @@ Restart: break; case MH: s_eminus->la -= d; - if (my_array[i * (count_unknowns + 1) + i] == 0) + if (my_array[(size_t)i * ((size_t)count_unknowns + 1) + (size_t)i] == 0) { - my_array[i * (count_unknowns + 1) + i] = + my_array[(size_t)i * ((size_t)count_unknowns + 1) + (size_t)i] = exp(s_h2->lm * LOG_10) * 2; } break; diff --git a/phreeqcpp/prep.cpp b/phreeqcpp/prep.cpp index 77464ce2..cf077f4a 100644 --- a/phreeqcpp/prep.cpp +++ b/phreeqcpp/prep.cpp @@ -544,7 +544,7 @@ build_gas_phase(void) row / (count_unknowns + 1), col)); } store_jacob(&(phase_ptr->moles_x), - &(my_array[row + col]), coef); + &(my_array[(size_t)row + (size_t)col]), coef); } if (gas_phase_ptr->Get_type() == cxxGasPhase::GP_PRESSURE) { @@ -557,7 +557,7 @@ build_gas_phase(void) gas_unknown->number)); } store_jacob(&(phase_ptr->fraction_x), - &(my_array[row + gas_unknown->number]), coef_elt); + &(my_array[(size_t)row + (size_t)gas_unknown->number]), coef_elt); } } /* @@ -634,7 +634,7 @@ build_gas_phase(void) master_ptr->s->name, (double) coef, row / (count_unknowns + 1), col)); } - store_jacob(&(phase_ptr->p_soln_x), &(my_array[row + col]), coef); + store_jacob(&(phase_ptr->p_soln_x), &(my_array[(size_t)row + (size_t)col]), coef); } } } @@ -727,11 +727,11 @@ build_ss_assemblage(void) { col = x[i]->number - 1; } - store_jacob(&(x[i]->phase->dnc), &(my_array[row + col]), -1); + store_jacob(&(x[i]->phase->dnc), &(my_array[(size_t)row + (size_t)col]), -1); /* next dnb terms */ col++; - store_jacob(&(x[i]->phase->dnb), &(my_array[row + col]), -1); + store_jacob(&(x[i]->phase->dnb), &(my_array[(size_t)row + (size_t)col]), -1); } else { @@ -744,12 +744,12 @@ build_ss_assemblage(void) if ((int) j != x[i]->ss_comp_number) { /* store_jacob (&(s_s_ptr->dn), &(array[row + col + j]), -1.0); */ - store_jacob(&(x[i]->phase->dn), &(my_array[row + col + j]), + store_jacob(&(x[i]->phase->dn), &(my_array[(size_t)row + (size_t)col + (size_t)j]), -1.0); } else { - store_jacob(&(x[i]->phase->dnb), &(my_array[row + col + j]), + store_jacob(&(x[i]->phase->dnb), &(my_array[(size_t)row + (size_t)col + (size_t)j]), -1.0); } } @@ -905,10 +905,8 @@ build_jacobian_sums(int k) { /* term for water, sum of all surfaces */ source = &s[k]->tot_dh2o_moles; - target = - &(my_array - [mb_unknowns[i].unknown->number * (count_unknowns + 1) + - mass_oxygen_unknown->number]); + target = &(my_array[(size_t)mb_unknowns[i].unknown->number * + ((size_t)count_unknowns + 1) + (size_t)mass_oxygen_unknown->number]); if (debug_prep == TRUE) { output_msg(sformatf( "\t\t%-24s%10.3f\t%d\t%d", @@ -927,8 +925,8 @@ build_jacobian_sums(int k) continue; cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[j]->surface_charge); source = s_diff_layer[k][charge_ptr->Get_name()].Get_dx_moles_address(); - target = &(my_array[mb_unknowns[i].unknown->number * - (count_unknowns + 1) + x[j]->number]); + target = &(my_array[(size_t)mb_unknowns[i].unknown->number * + ((size_t)count_unknowns + 1) + (size_t)x[j]->number]); if (debug_prep == TRUE) { output_msg(sformatf( "\t\t%-24s%10.3f\t%d\t%d", @@ -949,7 +947,7 @@ build_jacobian_sums(int k) continue; cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[j]->surface_charge); /* has related phase */ - cxxSurfaceComp *comp_ptr = use.Get_surface_ptr()->Find_comp(x[j - 1]->surface_comp); + cxxSurfaceComp *comp_ptr = use.Get_surface_ptr()->Find_comp(x[(size_t)j - 1]->surface_comp); if (comp_ptr->Get_phase_name().size() == 0) continue; @@ -966,8 +964,8 @@ build_jacobian_sums(int k) if (kk >= 0) { source = s_diff_layer[k][charge_ptr->Get_name()].Get_drelated_moles_address(); - target = &(my_array[mb_unknowns[i].unknown->number * - (count_unknowns + 1) + x[kk]->number]); + target = &(my_array[(size_t)mb_unknowns[i].unknown->number * + ((size_t)count_unknowns + 1) + (size_t)x[kk]->number]); if (debug_prep == TRUE) { output_msg(sformatf( @@ -995,21 +993,20 @@ build_jacobian_sums(int k) if (mb_unknowns[i].unknown->number == x[j]->number) { source = s_diff_layer[k][charge_ptr->Get_name()].Get_dx_moles_address(); - target = &(my_array[mb_unknowns[i].unknown->number * - (count_unknowns + 1) + x[j]->number]); + target = &(my_array[(size_t)mb_unknowns[i].unknown->number * + ((size_t)count_unknowns + 1) + (size_t)x[j]->number]); if (debug_prep == TRUE) { - output_msg(sformatf( - "\t\t%-24s%10.3f\t%d\t%d", "dg/dlny", - (double) coef, - mb_unknowns[i].unknown->number, - x[j]->number)); + output_msg(sformatf("\t\t%-24s%10.3f\t%d\t%d", "dg/dlny", + (double)coef, + mb_unknowns[i].unknown->number, + x[j]->number)); } store_jacob(source, target, coef); /* term for related phase */ /* has related phase */ - cxxSurfaceComp *comp_ptr = use.Get_surface_ptr()->Find_comp(x[j - 1]->surface_comp); + cxxSurfaceComp *comp_ptr = use.Get_surface_ptr()->Find_comp(x[(size_t)j - 1]->surface_comp); if (comp_ptr->Get_phase_name().size() > 0) { /* now find the related phase */ @@ -1024,8 +1021,8 @@ build_jacobian_sums(int k) if (kk >= 0) { source = s_diff_layer[k][charge_ptr->Get_name()].Get_drelated_moles_address(); - target = &(my_array[mb_unknowns[i].unknown->number * - (count_unknowns + 1) + x[kk]->number]); + target = &(my_array[(size_t)(size_t)mb_unknowns[i].unknown->number * + ((size_t)count_unknowns + 1) + (size_t)x[kk]->number]); if (debug_prep == TRUE) { output_msg(sformatf( @@ -1042,9 +1039,9 @@ build_jacobian_sums(int k) { /* term for water, for same surfaces */ source = s_diff_layer[k][charge_ptr->Get_name()].Get_dh2o_moles_address(); - target = &(my_array[mb_unknowns[i].unknown->number * - (count_unknowns + 1) + - mass_oxygen_unknown->number]); + target = &(my_array[(size_t)mb_unknowns[i].unknown->number * + ((size_t)count_unknowns + 1) + + (size_t)mass_oxygen_unknown->number]); if (debug_prep == TRUE) { output_msg(sformatf( @@ -1296,14 +1293,14 @@ build_model(void) k = j0; for (i = j0; i < j; i++) { - if (s_x[i - j0]->type == EX) + if (s_x[(size_t)i - (size_t)j0]->type == EX) continue; - if (s_x[i - j0]->type == SURF) + if (s_x[(size_t)i - (size_t)j0]->type == SURF) continue; x[k]->number = k; x[k]->type = PITZER_GAMMA; - x[k]->s = s_x[i - j0]; - x[k]->description = s_x[i - j0]->name; + x[k]->s = s_x[(size_t)i - (size_t)j0]; + x[k]->description = s_x[(size_t)i - (size_t)j0]->name; k++; count_unknowns++; } @@ -2045,14 +2042,8 @@ get_list_master_ptrs(char *ptr, struct master *master_ptr) { if (master[j]->s->primary == NULL) { - master_ptr_list = - (struct master **) PHRQ_realloc((void *) - master_ptr_list, - (size_t) (count_list - + - 2) * - sizeof(struct master - *)); + master_ptr_list = (struct master **) PHRQ_realloc((void *) + master_ptr_list, ((size_t)count_list + 2) * sizeof(struct master *)); if (master_ptr_list == NULL) malloc_error(); master_ptr_list[count_list++] = master[j]; @@ -2072,11 +2063,8 @@ get_list_master_ptrs(char *ptr, struct master *master_ptr) master_ptr = master_bsearch(token); if (master_ptr != NULL) { - master_ptr_list = - (struct master **) PHRQ_realloc((void *) master_ptr_list, - (size_t) (count_list + - 2) * - sizeof(struct master *)); + master_ptr_list = (struct master **) PHRQ_realloc((void *) master_ptr_list, + ((size_t)count_list + 2) * sizeof(struct master *)); if (master_ptr_list == NULL) malloc_error(); master_ptr_list[count_list++] = master_ptr; @@ -2268,7 +2256,7 @@ mb_for_species_aq(int n) cxxSurfaceCharge *charge_ptr = use.Get_surface_ptr()->Find_charge(x[i]->surface_charge); unknown_ptr = x[i]; if (use.Get_surface_ptr()->Get_type() == cxxSurface::CD_MUSIC) - unknown_ptr = x[i + 2]; + unknown_ptr = x[(size_t)i + 2]; store_mb_unknowns(unknown_ptr, s_diff_layer[n][charge_ptr->Get_name()].Get_g_moles_address(), s[n]->z, s_diff_layer[n][charge_ptr->Get_name()].Get_dg_g_moles_address()); @@ -3413,7 +3401,7 @@ setup_surface(void) struct unknown *unknown_ptr = find_surface_charge_unknown(token, SURF_PSI); if (unknown_ptr != NULL) { - x[count_unknowns - 1]->potential_unknown = unknown_ptr; + x[(size_t)count_unknowns - 1]->potential_unknown = unknown_ptr; } else { @@ -3445,10 +3433,8 @@ setup_surface(void) x[count_unknowns]->master = master_ptr_list; x[count_unknowns]->master[0]->unknown = x[count_unknowns]; x[count_unknowns]->moles = 0.0; - x[count_unknowns - 1]->potential_unknown = - x[count_unknowns]; - x[count_unknowns]->surface_comp = - x[count_unknowns - 1]->surface_comp; + x[(size_t)count_unknowns - 1]->potential_unknown = x[count_unknowns]; + x[count_unknowns]->surface_comp = x[(size_t)count_unknowns - 1]->surface_comp; count_unknowns++; } } @@ -3547,7 +3533,7 @@ setup_surface(void) /* Add SURFACE unknown to a list for SURF_PSI */ struct unknown *unknown_ptr = find_surface_charge_unknown(token, SURF_PSI); unknown_ptr->comp_unknowns = (struct unknown **) PHRQ_realloc(unknown_ptr->comp_unknowns, - (size_t) ((unknown_ptr->count_comp_unknowns + 1) * sizeof(struct unknown *))); + (((size_t)unknown_ptr->count_comp_unknowns + 1) * sizeof(struct unknown *))); if (unknown_ptr->comp_unknowns == NULL) malloc_error(); unknown_ptr->comp_unknowns[unknown_ptr->count_comp_unknowns++] = @@ -4709,8 +4695,8 @@ setup_unknowns(void) } else { - max_unknowns += (int) (use.Get_surface_ptr()->Get_surface_comps().size() + - 4 * (int) use.Get_surface_ptr()->Get_surface_charges().size()); + max_unknowns += (int)(use.Get_surface_ptr()->Get_surface_comps().size() + + 4 * use.Get_surface_ptr()->Get_surface_charges().size()); } } /* @@ -4794,7 +4780,7 @@ store_dn(int k, LDBLE * source, int row, LDBLE coef_in, LDBLE * gamma_source) /* mu term */ if (gamma_source != NULL) { - store_jacob(gamma_source, &my_array[row + mu_unknown->number], + store_jacob(gamma_source, &my_array[(size_t)row + (size_t)mu_unknown->number], -1.0 * coef_in); } } @@ -4810,7 +4796,7 @@ store_dn(int k, LDBLE * source, int row, LDBLE coef_in, LDBLE * gamma_source) (double) coef_in, row / (count_unknowns + 1), mass_oxygen_unknown->number)); } - store_jacob(source, &(my_array[row + mass_oxygen_unknown->number]), + store_jacob(source, &(my_array[(size_t)row + (size_t)mass_oxygen_unknown->number]), coef_in); } if (s[k] == s_h2o) @@ -4840,7 +4826,7 @@ store_dn(int k, LDBLE * source, int row, LDBLE coef_in, LDBLE * gamma_source) master_ptr->s->name, (double) coef, row / (count_unknowns + 1), col)); } - store_jacob(source, &(my_array[row + col]), coef); + store_jacob(source, &(my_array[(size_t)row + (size_t)col]), coef); } return (OK); } @@ -6281,9 +6267,9 @@ build_min_surface(void) continue; /* update grams == moles in this case */ - if (j < count_unknowns - 1 && x[j + 1]->type == SURFACE_CB) + if (j < count_unknowns - 1 && x[(size_t)j + 1]->type == SURFACE_CB) { - store_sum_deltas(&delta[k], &(x[j + 1]->related_moles), -1.0); + store_sum_deltas(&delta[k], &(x[(size_t)j + 1]->related_moles), -1.0); } /* charge balance */ @@ -6408,7 +6394,7 @@ setup_related_surface(void) } else if (x[i]->type == SURFACE_CB) { - cxxSurfaceComp *comp_ptr = use.Get_surface_ptr()->Find_comp(x[i-1]->surface_comp); + cxxSurfaceComp *comp_ptr = use.Get_surface_ptr()->Find_comp(x[(size_t)i-1]->surface_comp); if (comp_ptr->Get_phase_name().size() > 0) { cxxSurfaceComp *comp_i_ptr = use.Get_surface_ptr()->Find_comp(x[i]->surface_comp); diff --git a/phreeqcpp/print.cpp b/phreeqcpp/print.cpp index 71c9103c..7051502a 100644 --- a/phreeqcpp/print.cpp +++ b/phreeqcpp/print.cpp @@ -1892,9 +1892,8 @@ print_surface_cd_music(void) */ if (dl_type_x != cxxSurface::NO_DL) { - output_msg(sformatf( - "\t%11.3e Surface + diffuse layer charge, eq\n\n", - (double) (x[j + 2]->f + (charge_ptr->Get_sigma0() + charge_ptr->Get_sigma1()) * (charge_ptr->Get_specific_area() * charge_ptr->Get_grams()) / F_C_MOL))); + output_msg(sformatf("\t%11.3e Surface + diffuse layer charge, eq\n\n", + (double)(x[(size_t)j + 2]->f + (charge_ptr->Get_sigma0() + charge_ptr->Get_sigma1()) * (charge_ptr->Get_specific_area() * charge_ptr->Get_grams()) / F_C_MOL))); } master_ptr0 = surface_get_psi_master(charge_ptr->Get_name().c_str(), SURF_PSI); diff --git a/phreeqcpp/read.cpp b/phreeqcpp/read.cpp index fdd5f9a6..7f0b73c6 100644 --- a/phreeqcpp/read.cpp +++ b/phreeqcpp/read.cpp @@ -656,15 +656,8 @@ read_exchange_species(void) } else { - s_ptr->add_logk = - (struct name_coef *) PHRQ_realloc(s_ptr->add_logk, - (size_t) ((s_ptr-> - count_add_logk - + - 1) * - sizeof - (struct - name_coef))); + s_ptr->add_logk = (struct name_coef *) PHRQ_realloc(s_ptr->add_logk, + (((size_t)s_ptr->count_add_logk + 1) * sizeof(struct name_coef))); if (s_ptr->add_logk == NULL) { malloc_error(); @@ -714,15 +707,8 @@ read_exchange_species(void) } else { - s_ptr->add_logk = - (struct name_coef *) PHRQ_realloc(s_ptr->add_logk, - (size_t) ((s_ptr-> - count_add_logk - + - 1) * - sizeof - (struct - name_coef))); + s_ptr->add_logk = (struct name_coef *) PHRQ_realloc(s_ptr->add_logk, + (((size_t)s_ptr->count_add_logk + 1) * sizeof(struct name_coef))); if (s_ptr->add_logk == NULL) { malloc_error(); @@ -1701,12 +1687,8 @@ read_inv_balances(struct inverse *inverse_ptr, char *ptr) } else if (strcmp_nocase_arg1(token, "ph") != 0) { - inverse_ptr->elts = - (struct inv_elts *) PHRQ_realloc(inverse_ptr->elts, - (size_t) (inverse_ptr-> - count_elts + - 1) * - sizeof(struct inv_elts)); + inverse_ptr->elts = (struct inv_elts *) PHRQ_realloc(inverse_ptr->elts, + ((size_t)inverse_ptr->count_elts + 1) * sizeof(struct inv_elts)); if (inverse_ptr->elts == NULL) malloc_error(); replace("(+", "(", token); @@ -1794,18 +1776,12 @@ read_inv_isotopes(struct inverse *inverse_ptr, char *ptr) } if (i == inverse_ptr->count_isotopes) { - inverse_ptr->isotopes = - (struct inv_isotope *) PHRQ_realloc(inverse_ptr->isotopes, - (size_t) (inverse_ptr-> - count_isotopes + - 1) * - sizeof(struct inv_isotope)); + inverse_ptr->isotopes = (struct inv_isotope *) PHRQ_realloc(inverse_ptr->isotopes, + ((size_t)inverse_ptr->count_isotopes + 1) * sizeof(struct inv_isotope)); if (inverse_ptr->isotopes == NULL) malloc_error(); - inverse_ptr->isotopes[inverse_ptr->count_isotopes].isotope_number = - isotope_number; - inverse_ptr->isotopes[inverse_ptr->count_isotopes].elt_name = - element_name; + inverse_ptr->isotopes[inverse_ptr->count_isotopes].isotope_number = isotope_number; + inverse_ptr->isotopes[inverse_ptr->count_isotopes].elt_name = element_name; inverse_ptr->isotopes[inverse_ptr->count_isotopes].uncertainties = (LDBLE *) PHRQ_malloc((size_t) sizeof(LDBLE)); if (inverse_ptr->isotopes[inverse_ptr->count_isotopes]. @@ -1816,12 +1792,8 @@ read_inv_isotopes(struct inverse *inverse_ptr, char *ptr) /* * add redox state name to inv_ptr->i_u */ - inverse_ptr->i_u = - (struct inv_isotope *) PHRQ_realloc(inverse_ptr->i_u, - (size_t) (inverse_ptr-> - count_i_u + - 1) * - sizeof(struct inv_isotope)); + inverse_ptr->i_u = (struct inv_isotope *) PHRQ_realloc(inverse_ptr->i_u, + ((size_t)inverse_ptr->count_i_u + 1) * sizeof(struct inv_isotope)); if (inverse_ptr->i_u == NULL) { malloc_error(); @@ -1853,12 +1825,8 @@ read_inv_phases(struct inverse *inverse_ptr, char *ptr) j = copy_token(token, &ptr, &l); if (j == EMPTY) return (OK); - inverse_ptr->phases = - (struct inv_phases *) PHRQ_realloc(inverse_ptr->phases, - (size_t) (inverse_ptr-> - count_phases + - 1) * - sizeof(struct inv_phases)); + inverse_ptr->phases = (struct inv_phases *) PHRQ_realloc(inverse_ptr->phases, + ((size_t)inverse_ptr->count_phases + 1) * sizeof(struct inv_phases)); if (inverse_ptr->phases == NULL) malloc_error(); inverse_ptr->phases[inverse_ptr->count_phases].name = string_hsave(token); @@ -3772,15 +3740,8 @@ read_phases(void) } else { - phase_ptr->add_logk = - (struct name_coef *) PHRQ_realloc(phase_ptr->add_logk, - (size_t) ((phase_ptr-> - count_add_logk - + - 1) * - sizeof - (struct - name_coef))); + phase_ptr->add_logk = (struct name_coef *) PHRQ_realloc(phase_ptr->add_logk, + (((size_t)phase_ptr->count_add_logk + 1) * sizeof(struct name_coef))); if (phase_ptr->add_logk == NULL) malloc_error(); } @@ -3818,20 +3779,13 @@ read_phases(void) } else { - phase_ptr->add_logk = - (struct name_coef *) PHRQ_realloc(phase_ptr->add_logk, - (size_t) ((phase_ptr-> - count_add_logk - + - 1) * - sizeof - (struct - name_coef))); + phase_ptr->add_logk = (struct name_coef *) PHRQ_realloc(phase_ptr->add_logk, + (((size_t)phase_ptr->count_add_logk + 1) * sizeof(struct name_coef))); if (phase_ptr->add_logk == NULL) malloc_error(); } i = sscanf(next_char, SCANFORMAT, - &phase_ptr->add_logk[phase_ptr->count_add_logk].coef); + &phase_ptr->add_logk[(size_t)phase_ptr->count_add_logk].coef); if (i <= 0) { input_error++; @@ -5678,15 +5632,8 @@ read_species(void) } else { - s_ptr->add_logk = - (struct name_coef *) PHRQ_realloc(s_ptr->add_logk, - (size_t) ((s_ptr-> - count_add_logk - + - 1) * - sizeof - (struct - name_coef))); + s_ptr->add_logk = (struct name_coef *) PHRQ_realloc(s_ptr->add_logk, + (((size_t)s_ptr->count_add_logk + 1) * sizeof(struct name_coef))); if (s_ptr->add_logk == NULL) malloc_error(); } @@ -5730,15 +5677,8 @@ read_species(void) } else { - s_ptr->add_logk = - (struct name_coef *) PHRQ_realloc(s_ptr->add_logk, - (size_t) ((s_ptr-> - count_add_logk - + - 1) * - sizeof - (struct - name_coef))); + s_ptr->add_logk = (struct name_coef *) PHRQ_realloc(s_ptr->add_logk, + (((size_t)s_ptr->count_add_logk + 1) * sizeof(struct name_coef))); if (s_ptr->add_logk == NULL) malloc_error(); } @@ -6391,15 +6331,8 @@ read_surface_species(void) } else { - s_ptr->add_logk = - (struct name_coef *) PHRQ_realloc(s_ptr->add_logk, - (size_t) ((s_ptr-> - count_add_logk - + - 1) * - sizeof - (struct - name_coef))); + s_ptr->add_logk = (struct name_coef *) PHRQ_realloc(s_ptr->add_logk, + (((size_t)s_ptr->count_add_logk + 1) * sizeof(struct name_coef))); if (s_ptr->add_logk == NULL) { malloc_error(); @@ -6446,15 +6379,8 @@ read_surface_species(void) } else { - s_ptr->add_logk = - (struct name_coef *) PHRQ_realloc(s_ptr->add_logk, - (size_t) ((s_ptr-> - count_add_logk - + - 1) * - sizeof - (struct - name_coef))); + s_ptr->add_logk = (struct name_coef *) PHRQ_realloc(s_ptr->add_logk, + (((size_t)s_ptr->count_add_logk + 1) * sizeof(struct name_coef))); if (s_ptr->add_logk == NULL) malloc_error(); } @@ -7448,10 +7374,8 @@ read_title(void) */ title_x_length = (int) strlen(title_x); line_length = (int) strlen(line); - title_x = - (char *) PHRQ_realloc(title_x, - (size_t) (title_x_length + line_length + - 2) * sizeof(char)); + title_x = (char *) PHRQ_realloc(title_x, + ((size_t)title_x_length + (size_t)line_length + 2) * sizeof(char)); if (title_x == NULL) malloc_error(); if (title_x_length > 0) @@ -7656,9 +7580,8 @@ read_advection(void) /* * Fill in data for punch */ - advection_punch = - (int *) PHRQ_realloc(advection_punch, - (size_t) (count_ad_cells + 1) * sizeof(int)); + advection_punch = (int *) PHRQ_realloc(advection_punch, + ((size_t)count_ad_cells + 1) * sizeof(int)); if (advection_punch == NULL) malloc_error(); if (count_punch != 0) @@ -7689,9 +7612,8 @@ read_advection(void) /* * Fill in data for print */ - advection_print = - (int *) PHRQ_realloc(advection_print, - (size_t) (count_ad_cells + 1) * sizeof(int)); + advection_print = (int *) PHRQ_realloc(advection_print, + ((size_t)count_ad_cells + 1) * sizeof(int)); if (advection_print == NULL) malloc_error(); if (count_print != 0) @@ -8602,10 +8524,8 @@ read_rates(void) } length = (int) strlen(rate_ptr->commands); line_length = (int) strlen(line); - rate_ptr->commands = - (char *) PHRQ_realloc(rate_ptr->commands, - (size_t) (length + line_length + - 2) * sizeof(char)); + rate_ptr->commands = (char *) PHRQ_realloc(rate_ptr->commands, + ((size_t)length + (size_t)line_length + 2) * sizeof(char)); if (rate_ptr->commands == NULL) { malloc_error(); @@ -8701,10 +8621,8 @@ read_user_print(void) case OPT_1: /* read command */ length = (int) strlen(user_print->commands); line_length = (int) strlen(line); - user_print->commands = - (char *) PHRQ_realloc(user_print->commands, - (size_t) (length + line_length + - 2) * sizeof(char)); + user_print->commands = (char *) PHRQ_realloc(user_print->commands, + ((size_t)length + (size_t)line_length + 2) * sizeof(char)); if (user_print->commands == NULL) malloc_error(); user_print->commands[length] = ';'; @@ -8838,7 +8756,7 @@ read_user_punch(void) length = (int) strlen(r->commands); line_length = (int) strlen(line); r->commands = (char *) PHRQ_realloc(r->commands, - (size_t) (length + line_length + 2) * sizeof(char)); + ((size_t)length + (size_t)line_length + 2) * sizeof(char)); if (r->commands == NULL) { malloc_error(); @@ -9945,15 +9863,8 @@ read_named_logk(void) } else { - logk_ptr->add_logk = - (struct name_coef *) PHRQ_realloc(logk_ptr->add_logk, - (size_t) ((logk_ptr-> - count_add_logk - + - 1) * - sizeof - (struct - name_coef))); + logk_ptr->add_logk = (struct name_coef *) PHRQ_realloc(logk_ptr->add_logk, + (((size_t)logk_ptr->count_add_logk + 1) * sizeof(struct name_coef))); if (logk_ptr->add_logk == NULL) malloc_error(); } diff --git a/phreeqcpp/readtr.cpp b/phreeqcpp/readtr.cpp index 5a682fd1..4bfada27 100644 --- a/phreeqcpp/readtr.cpp +++ b/phreeqcpp/readtr.cpp @@ -745,7 +745,7 @@ read_transport(void) if (count_disp > max_cells) max_cells = count_disp; if (count_por > max_cells * (1 + stag_data->count_stag)) - max_cells = (int)ceil(((double)count_por / (double)(1 + stag_data->count_stag))); + max_cells = (int)ceil(((double)count_por / (1 + (double)stag_data->count_stag))); if (max_cells > count_cells) { if (max_cells == count_length) @@ -766,7 +766,7 @@ read_transport(void) { sprintf(token, "Number of mobile cells is increased to (ceil)(number of porosities) / (1 + number of stagnant zones) = %d.", - (int) ceil(((double)count_por / (double)(1 + stag_data->count_stag)))); + (int) ceil(((double)count_por / (1 + (double)stag_data->count_stag)))); warning_msg(token); } } diff --git a/phreeqcpp/sit.cpp b/phreeqcpp/sit.cpp index a39c42a7..a92a8313 100644 --- a/phreeqcpp/sit.cpp +++ b/phreeqcpp/sit.cpp @@ -911,7 +911,7 @@ Restart: residuals(); for (j = 0; j < count_unknowns; j++) { - my_array[j * (count_unknowns + 1) + i] = + my_array[(size_t)j * ((size_t)count_unknowns + 1) + (size_t)i] = -(residual[j] - base[j]) / d2; } switch (x[i]->type) @@ -930,9 +930,9 @@ Restart: break; case MH: s_eminus->la -= d; - if (my_array[i * (count_unknowns + 1) + i] == 0) + if (my_array[(size_t)i * ((size_t)count_unknowns + 1) + (size_t)i] == 0) { - my_array[i * (count_unknowns + 1) + i] = + my_array[(size_t)i * ((size_t)count_unknowns + 1) + (size_t)i] = exp(s_h2->lm * LOG_10) * 2; } break; diff --git a/phreeqcpp/smalldense.cpp b/phreeqcpp/smalldense.cpp index 6cfd7c07..891ae99a 100644 --- a/phreeqcpp/smalldense.cpp +++ b/phreeqcpp/smalldense.cpp @@ -83,7 +83,7 @@ denalloc(integertype n) if (a == NULL) return (NULL); - a[0] = (realtype *) malloc(n * n * sizeof(realtype)); + a[0] = (realtype *) malloc((size_t)n * (size_t)n * sizeof(realtype)); if (a[0] == NULL) { free(a); @@ -91,7 +91,7 @@ denalloc(integertype n) } for (j = 1; j < n; j++) - a[j] = a[0] + j * n; + a[j] = a[0] + (size_t)j * (size_t)n; return (a); } diff --git a/phreeqcpp/spread.cpp b/phreeqcpp/spread.cpp index ca13926c..3b3c7372 100644 --- a/phreeqcpp/spread.cpp +++ b/phreeqcpp/spread.cpp @@ -377,11 +377,8 @@ read_solution_spread(void) } if (i == soln_defaults.count_iso) { - soln_defaults.iso = - (struct iso *) PHRQ_realloc(soln_defaults.iso, - (size_t) (i + - 1) * - sizeof(struct iso)); + soln_defaults.iso = (struct iso *) PHRQ_realloc(soln_defaults.iso, + ((size_t)i + 1) * sizeof(struct iso)); if (soln_defaults.iso == NULL) { malloc_error(); @@ -463,11 +460,8 @@ read_solution_spread(void) } if (i == soln_defaults.count_iso) { - soln_defaults.iso = - (struct iso *) PHRQ_realloc(soln_defaults.iso, - (size_t) (i + - 1) * - sizeof(struct iso)); + soln_defaults.iso = (struct iso *) PHRQ_realloc(soln_defaults.iso, + ((size_t)i + 1) * sizeof(struct iso)); if (soln_defaults.iso == NULL) { malloc_error(); diff --git a/phreeqcpp/step.cpp b/phreeqcpp/step.cpp index c0eb9a4f..032468f9 100644 --- a/phreeqcpp/step.cpp +++ b/phreeqcpp/step.cpp @@ -823,7 +823,7 @@ add_reaction(cxxReaction *reaction_ptr, int step_number, LDBLE step_fraction) } else { - step_x = reaction_ptr->Get_steps()[step_number - 1]; + step_x = reaction_ptr->Get_steps()[(size_t)step_number - 1]; } } else if (reaction_ptr->Get_equalIncrements() && reaction_ptr->Get_steps().size()> 0) @@ -851,11 +851,11 @@ add_reaction(cxxReaction *reaction_ptr, int step_number, LDBLE step_fraction) { if (step_number > (int) reaction_ptr->Get_reaction_steps()) { - step_x = reaction_ptr->Get_steps()[reaction_ptr->Get_reaction_steps() - 1]; + step_x = reaction_ptr->Get_steps()[(size_t)reaction_ptr->Get_reaction_steps() - 1]; } else { - step_x = reaction_ptr->Get_steps()[step_number - 1]; + step_x = reaction_ptr->Get_steps()[(size_t)step_number - 1]; } } else if (reaction_ptr->Get_equalIncrements() && reaction_ptr->Get_steps().size()> 0) diff --git a/phreeqcpp/structures.cpp b/phreeqcpp/structures.cpp index 670500de..128aaa3c 100644 --- a/phreeqcpp/structures.cpp +++ b/phreeqcpp/structures.cpp @@ -471,12 +471,12 @@ elt_list_dup(struct elt_list *elt_list_ptr_old) * Malloc space and store element data */ elt_list_ptr_new = - (struct elt_list *) PHRQ_malloc((size_t) (count_totals + 1) * + (struct elt_list *) PHRQ_malloc(((size_t)count_totals + 1) * sizeof(struct elt_list)); if (elt_list_ptr_new == NULL) malloc_error(); memcpy(elt_list_ptr_new, elt_list_ptr_old, - (size_t) (count_totals + 1) * sizeof(struct elt_list)); + ((size_t)count_totals + 1) * sizeof(struct elt_list)); return (elt_list_ptr_new); } @@ -536,7 +536,7 @@ elt_list_save(void) /* * Malloc space and store element data */ - elt_list_ptr = (struct elt_list*)PHRQ_malloc((size_t)(count_elts + 1) * + elt_list_ptr = (struct elt_list*)PHRQ_malloc(((size_t)count_elts + 1) * sizeof(struct elt_list)); if (elt_list_ptr == NULL) { @@ -1078,7 +1078,7 @@ master_bsearch_secondary(char *ptr) if (master_ptr_primary) { if ((master_ptr_primary->number >= (int)master.size() - 1) || - (master[master_ptr_primary->number + 1]->elt->primary != master_ptr_primary)) + (master[(size_t)master_ptr_primary->number + 1]->elt->primary != master_ptr_primary)) { return(master_ptr_primary); } @@ -1671,7 +1671,7 @@ rxn_dup(struct reaction *rxn_ptr_old) * Copy tokens */ memcpy(rxn_ptr_new->token, rxn_ptr_old->token, - (size_t) (i + 1) * sizeof(struct rxn_token)); + ((size_t)i + 1) * sizeof(struct rxn_token)); return (rxn_ptr_new); } diff --git a/phreeqcpp/tally.cpp b/phreeqcpp/tally.cpp index a6ccbb08..af3b6b4c 100644 --- a/phreeqcpp/tally.cpp +++ b/phreeqcpp/tally.cpp @@ -1212,10 +1212,8 @@ extend_tally_table(void) * adds another column to tally_table * increments number of columns */ - tally_table = - (struct tally *) PHRQ_realloc((void *) tally_table, - (size_t) (count_tally_table_columns + - 1) * sizeof(struct tally)); + tally_table = (struct tally *) PHRQ_realloc((void *) tally_table, + ((size_t)count_tally_table_columns + 1) * sizeof(struct tally)); if (tally_table == NULL) malloc_error(); for (i = 0; i < 3; i++) diff --git a/phreeqcpp/tidy.cpp b/phreeqcpp/tidy.cpp index cca5d3e2..f129127a 100644 --- a/phreeqcpp/tidy.cpp +++ b/phreeqcpp/tidy.cpp @@ -1349,7 +1349,7 @@ tidy_inverse(void) continue; /* if next master species is secondary, mark all secondary master species until a primary is found */ - if (master[j + 1]->primary == FALSE) + if (master[(size_t)j + 1]->primary == FALSE) { master[j]->in = FALSE; count_in--; diff --git a/phreeqcpp/transport.cpp b/phreeqcpp/transport.cpp index 91b7e7db..0eb53ba1 100644 --- a/phreeqcpp/transport.cpp +++ b/phreeqcpp/transport.cpp @@ -247,8 +247,8 @@ transport(void) "Electrical Field (potential) was defined, assuming constant boundary condition for last cell."); warning_msg(error_string); } - current_cells = (struct CURRENT_CELLS *) PHRQ_malloc((size_t) - (count_cells + 1) * sizeof(struct CURRENT_CELLS)); + current_cells = (struct CURRENT_CELLS *) PHRQ_malloc( + ((size_t)count_cells + 1) * sizeof(struct CURRENT_CELLS)); if (current_cells == NULL) malloc_error(); for (int i = 0; i < count_cells + 1; i++) @@ -288,8 +288,8 @@ transport(void) //} if (implicit && current_cells == NULL) { - current_cells = (struct CURRENT_CELLS *) PHRQ_malloc((size_t) - (count_cells + 1) * sizeof(struct CURRENT_CELLS)); + current_cells = (struct CURRENT_CELLS *) PHRQ_malloc( + ((size_t)count_cells + 1) * sizeof(struct CURRENT_CELLS)); if (current_cells == NULL) malloc_error(); for (int i = 0; i < count_cells + 1; i++) @@ -377,9 +377,9 @@ transport(void) if (nmix < 2) stagkin_time = timest; else - stagkin_time = timest / nmix; + stagkin_time = timest / (double)nmix; if (ishift != 0) - kin_time = timest / (1 + nmix); + kin_time = timest / (1 + (double)nmix); else kin_time = stagkin_time; kin_time_save = kin_time; @@ -528,8 +528,8 @@ transport(void) /* For half of mixing steps */ for (j = 1; j <= floor((LDBLE)nmix / 2); j++) { - rate_sim_time_start = - (transport_step - 1) * timest + (j - 1) * kin_time; + rate_sim_time_start = ((double)transport_step - 1) * + timest + ((double)j - 1) * kin_time; rate_sim_time = rate_sim_time_start + kin_time; mixrun = j; @@ -618,8 +618,8 @@ transport(void) Utilities::Rxn_copy(Rxn_solution_map, -2, count_cells); /* Stagnant zone mixing after completion of each diffusive/dispersive step ... */ - rate_sim_time_start = - (transport_step - 1) * timest + (j - 1) * stagkin_time; + rate_sim_time_start = ((double)transport_step - 1) * + timest + ((double)j - 1) * stagkin_time; rate_sim_time = rate_sim_time_start + stagkin_time; if (stag_data->count_stag > 0) @@ -656,10 +656,10 @@ transport(void) sprintf(token, "Transport step %3d.", transport_step); dup_print(token, FALSE); if (b_c == 1) - rate_sim_time_start = - (transport_step - 1) * timest + (j - 1) * kin_time; + rate_sim_time_start = ((double)transport_step - 1) * + timest + ((double)j - 1) * kin_time; else - rate_sim_time_start = (transport_step - 1) * timest; + rate_sim_time_start = ((double)transport_step - 1) * timest; rate_sim_time = rate_sim_time_start + kin_time; /* halftime kinetics for resident water in first cell ... */ @@ -806,8 +806,8 @@ transport(void) transport_step, j); dup_print(token, FALSE); } - rate_sim_time_start = - (transport_step - 1) * timest + (j - 1) * kin_time; + rate_sim_time_start = ((double)transport_step - 1) * + timest + ((double)j - 1) * kin_time; if (ishift != 0) rate_sim_time_start += kin_time; rate_sim_time = rate_sim_time_start + kin_time; @@ -876,8 +876,8 @@ transport(void) if (!dV_dcell) Utilities::Rxn_copy(Rxn_solution_map, -2, count_cells); /* Stagnant zone mixing after completion of each diffusive/dispersive step ... */ - rate_sim_time_start = - (transport_step - 1) * timest + (j - 1) * stagkin_time; + rate_sim_time_start = ((double)transport_step - 1) * + timest + ((double)j - 1) * stagkin_time; rate_sim_time = rate_sim_time_start + stagkin_time; if (stag_data->count_stag > 0) @@ -1102,10 +1102,10 @@ init_mix(void) bool warning = false; int i, l_nmix; LDBLE *m, *m1; - m = (LDBLE *)PHRQ_malloc((count_cells + 1) * sizeof(LDBLE)); + m = (LDBLE *)PHRQ_malloc(((size_t)count_cells + 1) * sizeof(LDBLE)); if (m == NULL) malloc_error(); - m1 = (LDBLE *)PHRQ_malloc((count_cells + 1) * sizeof(LDBLE)); + m1 = (LDBLE *)PHRQ_malloc(((size_t)count_cells + 1) * sizeof(LDBLE)); if (m1 == NULL) malloc_error(); for (i = 0; i < count_cells + 1; i++) @@ -1554,15 +1554,15 @@ init_heat_mix(int l_nmix) /* * Initialize arrays... */ - heat_mix_array = (LDBLE *)PHRQ_malloc((count_cells + 2) * sizeof(LDBLE)); + heat_mix_array = (LDBLE *)PHRQ_malloc(((size_t)count_cells + 2) * sizeof(LDBLE)); if (heat_mix_array == NULL) malloc_error(); - temp1 = (LDBLE *)PHRQ_malloc((count_cells + 2) * sizeof(LDBLE)); + temp1 = (LDBLE *)PHRQ_malloc(((size_t)count_cells + 2) * sizeof(LDBLE)); if (temp1 == NULL) malloc_error(); - temp2 = (LDBLE *)PHRQ_malloc((count_cells + 2) * sizeof(LDBLE)); + temp2 = (LDBLE *)PHRQ_malloc(((size_t)count_cells + 2) * sizeof(LDBLE)); if (temp2 == NULL) malloc_error(); /* @@ -1897,7 +1897,7 @@ fill_spec(int l_cell_no, int ref_cell) // continue; //if (s_ptr->type == SURF) // continue; - if (i > 0 && strcmp(s_ptr->name, species_list[i - 1].s->name) == 0) + if (i > 0 && strcmp(s_ptr->name, species_list[(size_t)i - 1].s->name) == 0) continue; //if (s_ptr == s_h2o) // continue; @@ -2021,7 +2021,8 @@ fill_spec(int l_cell_no, int ref_cell) i3 = i2 - i1; if (i3 + count_spec + 1 > sol_D[l_cell_no].spec_size) { - sol_D[l_cell_no].spec = (struct spec *) PHRQ_realloc(sol_D[l_cell_no].spec, (size_t)(i3 + count_spec + 1 + size_xt) * sizeof(struct spec)); + sol_D[l_cell_no].spec = (struct spec *) PHRQ_realloc(sol_D[l_cell_no].spec, + ((size_t)i3 + (size_t)count_spec + 1 + (size_t)size_xt) * sizeof(struct spec)); if (sol_D[l_cell_no].spec == NULL) malloc_error(); sol_D[l_cell_no].spec_size = i3 + count_spec + 1 + size_xt; @@ -2042,7 +2043,8 @@ fill_spec(int l_cell_no, int ref_cell) } if (count_spec >= sol_D[l_cell_no].spec_size) { - sol_D[l_cell_no].spec = (struct spec *) PHRQ_realloc(sol_D[l_cell_no].spec, (size_t)(count_spec + size_xt) * sizeof(struct spec)); + sol_D[l_cell_no].spec = (struct spec *) PHRQ_realloc(sol_D[l_cell_no].spec, + ((size_t)count_spec + (size_t)size_xt) * sizeof(struct spec)); if (sol_D[l_cell_no].spec == NULL) malloc_error(); sol_D[l_cell_no].spec_size = count_spec + size_xt; @@ -2093,7 +2095,8 @@ fill_spec(int l_cell_no, int ref_cell) i2 = sol_D[i1].count_spec + 1; if (i2 > sol_D[i1].spec_size) { - sol_D[i1].spec = (struct spec *) PHRQ_realloc(sol_D[i1].spec, (size_t)(i2 + size_xt) * sizeof(struct spec)); + sol_D[i1].spec = (struct spec *) PHRQ_realloc(sol_D[i1].spec, + ((size_t)i2 + (size_t)size_xt) * sizeof(struct spec)); if (sol_D[i1].spec == NULL) malloc_error(); sol_D[i1].spec_size = i2 + size_xt; @@ -2121,7 +2124,8 @@ fill_spec(int l_cell_no, int ref_cell) i3 = (int) dif_spec_names.size(); if (i3 > sol_D[l_cell_no].spec_size) { - sol_D[l_cell_no].spec = (struct spec *) PHRQ_realloc(sol_D[l_cell_no].spec, (size_t)(i3 + size_xt) * sizeof(struct spec)); + sol_D[l_cell_no].spec = (struct spec *) PHRQ_realloc(sol_D[l_cell_no].spec, + ((size_t)i3 + (size_t)size_xt) * sizeof(struct spec)); if (sol_D[l_cell_no].spec == NULL) malloc_error(); sol_D[l_cell_no].spec_size = i3 + size_xt; @@ -2212,41 +2216,41 @@ diffuse_implicit(LDBLE DDt, int stagnant) comp += 1; if (Ct2 == NULL) - Ct2 = (LDBLE *) PHRQ_malloc((size_t) (count_cells + 2 + stagnant * count_cells) * sizeof(LDBLE)); + Ct2 = (LDBLE *) PHRQ_malloc(((size_t)count_cells + 2 + (size_t)stagnant * (size_t)count_cells) * sizeof(LDBLE)); if (Ct2 == NULL) malloc_error(); if (l_tk_x2 == NULL) - l_tk_x2 = (LDBLE *) PHRQ_malloc((size_t) (count_cells + 2 + stagnant * count_cells) * sizeof(LDBLE)); + l_tk_x2 = (LDBLE *) PHRQ_malloc(((size_t)count_cells + 2 + (size_t)stagnant * (size_t)count_cells) * sizeof(LDBLE)); if (l_tk_x2 == NULL) malloc_error(); if (A == NULL) { - A = (LDBLE **)PHRQ_malloc((size_t)(count_cells + 2 + stagnant * count_cells) * sizeof(LDBLE *)); + A = (LDBLE **)PHRQ_malloc(((size_t)count_cells + 2 + (size_t)stagnant * (size_t)count_cells) * sizeof(LDBLE *)); if (A == NULL) malloc_error(); for (i = 0; i < count_cells + 2 + stagnant * count_cells; i++) { if (stagnant) - A[i] = (LDBLE *)PHRQ_calloc((size_t)(2 * count_cells + 2), sizeof(LDBLE)); + A[i] = (LDBLE *)PHRQ_calloc((2 * (size_t)count_cells + 2), sizeof(LDBLE)); else - A[i] = (LDBLE *)PHRQ_malloc((size_t)3 * sizeof(LDBLE)); + A[i] = (LDBLE *)PHRQ_malloc(3 * sizeof(LDBLE)); if (A[i] == NULL) malloc_error(); } } if (LU == NULL) { - LU = (LDBLE **)PHRQ_malloc((size_t)(count_cells + 2 + stagnant * count_cells) * sizeof(LDBLE *)); + LU = (LDBLE **)PHRQ_malloc(((size_t)count_cells + 2 + (size_t)stagnant * (size_t)count_cells) * sizeof(LDBLE *)); if (LU == NULL) malloc_error(); for (i = 0; i < count_cells + 2 + stagnant * count_cells; i++) { if (stagnant) - LU[i] = (LDBLE *)PHRQ_calloc((size_t)(2 * count_cells + 2), sizeof(LDBLE)); + LU[i] = (LDBLE *)PHRQ_calloc((2 * (size_t)count_cells + 2), sizeof(LDBLE)); else - LU[i] = (LDBLE *)PHRQ_malloc((size_t)3 * sizeof(LDBLE)); + LU[i] = (LDBLE *)PHRQ_malloc(3 * sizeof(LDBLE)); if (LU[i] == NULL) malloc_error(); } } if (mixf == NULL) { - mixf = (LDBLE **)PHRQ_malloc((size_t)(count_cells + 2) * sizeof(LDBLE *)); + mixf = (LDBLE **)PHRQ_malloc(((size_t)count_cells + 2) * sizeof(LDBLE *)); if (mixf == NULL) malloc_error(); for (i = 0; i < count_cells + 2; i++) { @@ -2257,7 +2261,7 @@ diffuse_implicit(LDBLE DDt, int stagnant) { if (mixf_stag == NULL) { - mixf_stag = (LDBLE **)PHRQ_malloc((size_t)(count_cells + 2) * sizeof(LDBLE *)); + mixf_stag = (LDBLE **)PHRQ_malloc(((size_t)count_cells + 2) * sizeof(LDBLE *)); if (mixf_stag == NULL) malloc_error(); for (i = 0; i < count_cells + 2; i++) { @@ -2270,16 +2274,16 @@ diffuse_implicit(LDBLE DDt, int stagnant) for (i = 0; i < count_cells + 2; i++) { if (mixf[i] == NULL) - mixf[i] = (LDBLE *)PHRQ_malloc((size_t)(comp + 2) * sizeof(LDBLE)); + mixf[i] = (LDBLE *)PHRQ_malloc(((size_t)comp + 2) * sizeof(LDBLE)); else - mixf[i] = (LDBLE *)PHRQ_realloc(mixf[i], (size_t)(comp + 2) * sizeof(LDBLE)); + mixf[i] = (LDBLE *)PHRQ_realloc(mixf[i], ((size_t)comp + 2) * sizeof(LDBLE)); if (mixf[i] == NULL) malloc_error(); if (stagnant) { if (mixf_stag[i] == NULL) - mixf_stag[i] = (LDBLE *)PHRQ_malloc((size_t)(comp + 2) * sizeof(LDBLE)); + mixf_stag[i] = (LDBLE *)PHRQ_malloc(((size_t)comp + 2) * sizeof(LDBLE)); else - mixf_stag[i] = (LDBLE *)PHRQ_realloc(mixf_stag[i], (size_t)(comp + 2) * sizeof(LDBLE)); + mixf_stag[i] = (LDBLE *)PHRQ_realloc(mixf_stag[i], ((size_t)comp + 2) * sizeof(LDBLE)); if (mixf_stag[i] == NULL) malloc_error(); for (cp = 0; cp < comp; cp++) mixf_stag[i][cp] = 0; @@ -2798,7 +2802,7 @@ diffuse_implicit(LDBLE DDt, int stagnant) ((dV_dcell > 0) && ((cell_data[i].potV + dVc) > cell_data[count_cells + 1].potV)) || ((dV_dcell < 0) && ((cell_data[i].potV + dVc) < cell_data[count_cells + 1].potV))) { - dVc = (cell_data[count_cells + 1].potV - cell_data[i].potV) / (count_cells + 1 - i); + dVc = (cell_data[(size_t)count_cells + 1].potV - cell_data[i].potV) / ((double)count_cells + 1 - (double)i); } cell_data[i + 1].potV = cell_data[i].potV + dVc; } @@ -2841,12 +2845,12 @@ diffuse_implicit(LDBLE DDt, int stagnant) ct[i].m_s = (struct M_S *) free_check_null(ct[i].m_s); if (ct[i].m_s == NULL) { - ct[i].m_s = (struct M_S *) PHRQ_malloc((size_t)(count_m_s + 5) * sizeof(struct M_S)); + ct[i].m_s = (struct M_S *) PHRQ_malloc(((size_t)count_m_s + 5) * sizeof(struct M_S)); ct[i].m_s_size = count_m_s + 5; } else if (count_m_s > ct[i].m_s_size) { - ct[i].m_s = (struct M_S *) PHRQ_realloc(ct[i].m_s, (size_t)(count_m_s + 5) * sizeof(struct M_S)); + ct[i].m_s = (struct M_S *) PHRQ_realloc(ct[i].m_s, ((size_t)count_m_s + 5) * sizeof(struct M_S)); ct[i].m_s_size = count_m_s + 5; } if (ct[i].m_s == NULL) diff --git a/phreeqcpp/utilities.cpp b/phreeqcpp/utilities.cpp index 86992a8b..2d4b5f3a 100644 --- a/phreeqcpp/utilities.cpp +++ b/phreeqcpp/utilities.cpp @@ -579,7 +579,7 @@ dup_print(const char *ptr, int emphasis) return (OK); std::string save_in(ptr); l = (int) strlen(ptr); - dash = (char *) PHRQ_malloc((size_t) (l + 2) * sizeof(char)); + dash = (char *) PHRQ_malloc(((size_t)l + 2) * sizeof(char)); if (dash == NULL) malloc_error(); if (emphasis == TRUE) @@ -1225,7 +1225,7 @@ string_duplicate(const char *token) #if !defined(NDEBUG) && defined(WIN32_MEMORY_DEBUG) str = (char *) _malloc_dbg((size_t) (l + 1) * sizeof(char), _NORMAL_BLOCK, szFileName, nLine); #else - str = (char *) PHRQ_malloc((size_t) (l + 1) * sizeof(char)); + str = (char *) PHRQ_malloc(((size_t)l + 1) * sizeof(char)); #endif if (str == NULL) @@ -1973,7 +1973,7 @@ string_pad(const char *str, int i) max = l; if (l < i) max = i; - str_ptr = (char *) PHRQ_malloc((size_t) ((max + 1) * sizeof(char))); + str_ptr = (char *) PHRQ_malloc((((size_t)max + 1) * sizeof(char))); if (str_ptr == NULL) malloc_error(); strcpy(str_ptr, str);