diff --git a/Phreeqc.cpp b/Phreeqc.cpp index 47122dcf..bece82d1 100644 --- a/Phreeqc.cpp +++ b/Phreeqc.cpp @@ -763,7 +763,6 @@ void Phreeqc::init(void) * Reaction work space *---------------------------------------------------------------------- */ // struct trxn; - trxn.token = 0; for (int i = 0; i < MAX_LOG_K_INDICES; i++) { trxn.logk[i] = 0; @@ -773,7 +772,6 @@ void Phreeqc::init(void) trxn.dz[i] = 0; } count_trxn = 0; - max_trxn = MAX_TRXN; mb_unknowns = NULL; count_mb_unknowns = 0; @@ -1896,7 +1894,6 @@ Phreeqc::InternalCopy(const Phreeqc *pSrc) trxn.dz[i] = 0; } count_trxn = 0; - max_trxn = MAX_TRXN; */ /* mb_unknowns = NULL; diff --git a/Phreeqc.h b/Phreeqc.h index 4dcc12d6..0f9555d0 100644 --- a/Phreeqc.h +++ b/Phreeqc.h @@ -1530,8 +1530,7 @@ protected: *---------------------------------------------------------------------- */ struct reaction_temp trxn; /* structure array of working space while reading equations species names are in "temp_strings" */ - int count_trxn; /* number of reactants in trxn = position of next */ - int max_trxn; + int count_trxn; /* number of reactants in trxn = position of next */ struct unknown_list *mb_unknowns; int count_mb_unknowns; diff --git a/global_structures.h b/global_structures.h index d0604682..b6e833bb 100644 --- a/global_structures.h +++ b/global_structures.h @@ -813,7 +813,7 @@ struct reaction_temp { LDBLE logk[MAX_LOG_K_INDICES]; LDBLE dz[3]; - struct rxn_token_temp *token; + std::vector token; }; struct rxn_token_temp { /* data for equations, aq. species or minerals */ diff --git a/mainsubs.cpp b/mainsubs.cpp index 10654610..d5bbe610 100644 --- a/mainsubs.cpp +++ b/mainsubs.cpp @@ -78,10 +78,6 @@ initialize(void) stag_data->exch_f = 0; stag_data->th_m = 0; stag_data->th_im = 0; - - space((void **) ((void *) &trxn.token), INIT, &max_trxn, - sizeof(struct rxn_token_temp)); - /* * Create hash tables */ diff --git a/parse.cpp b/parse.cpp index 8931f432..11cc4e26 100644 --- a/parse.cpp +++ b/parse.cpp @@ -1025,11 +1025,8 @@ get_species(char **ptr) char string[MAX_LENGTH]; int l; - if (count_trxn + 1 >= max_trxn) - { - space((void **) ((void *) &(trxn.token)), count_trxn + 1, &max_trxn, - sizeof(struct rxn_token_temp)); - } + if ((size_t) count_trxn + 1 > trxn.token.size()) + trxn.token.resize((size_t)count_trxn + 1); /* coefficient */ if (get_coef(&(trxn.token[count_trxn].coef), ptr) == ERROR) { diff --git a/prep.cpp b/prep.cpp index b837e060..6bb87951 100644 --- a/prep.cpp +++ b/prep.cpp @@ -2861,11 +2861,8 @@ add_potential_factor(void) /* * Make sure there is space */ - if (count_trxn + 1 >= max_trxn) - { - space((void **) ((void *) &(trxn.token)), count_trxn + 1, &max_trxn, - sizeof(struct rxn_token_temp)); - } + if ((size_t)count_trxn + 1 > trxn.token.size()) + trxn.token.resize((size_t)count_trxn + 1); /* * Include psi in mass action equation */ @@ -2958,11 +2955,8 @@ add_cd_music_factors(int n) /* * Make sure there is space */ - if (count_trxn + 3 >= max_trxn) - { - space((void **) ((void *) &(trxn.token)), count_trxn + 3, &max_trxn, - sizeof(struct rxn_token_temp)); - } + if ((size_t)count_trxn + 3 > trxn.token.size()) + trxn.token.resize((size_t)count_trxn + 3); /* * Include psi in mass action equation */ diff --git a/structures.cpp b/structures.cpp index fb94a438..44f96472 100644 --- a/structures.cpp +++ b/structures.cpp @@ -291,10 +291,8 @@ clean_up(void) change_surf = (struct Change_Surf *) free_check_null(change_surf); /* miscellaneous work space */ - - //elt_list = (struct elt_list *) free_check_null(elt_list); elt_list.clear(); - trxn.token = (struct rxn_token_temp *) free_check_null(trxn.token); + trxn.token.clear(); mb_unknowns = (struct unknown_list *) free_check_null(mb_unknowns); line = (char *) free_check_null(line); line_save = (char *) free_check_null(line_save); @@ -2620,11 +2618,8 @@ trxn_add(cxxChemRxn &r_ptr, LDBLE coef, int combine) */ for (size_t j = 0; j < r_ptr.Get_tokens().size(); j++) { - if (count_trxn + 1 >= max_trxn) - { - space((void **) ((void *) &(trxn.token)), count_trxn + 1, - &max_trxn, sizeof(struct rxn_token_temp)); - } + if ((size_t)count_trxn + 1 > trxn.token.size()) + trxn.token.resize((size_t)count_trxn + 1); trxn.token[count_trxn].name = r_ptr.Get_tokens()[j].name; trxn.token[count_trxn].s = r_ptr.Get_tokens()[j].s; trxn.token[count_trxn].coef = coef * r_ptr.Get_tokens()[j].coef; @@ -2685,11 +2680,8 @@ trxn_add(struct reaction *r_ptr, LDBLE coef, int combine) next_token = r_ptr->token; while (next_token->s != NULL) { - if (count_trxn + 1 >= max_trxn) - { - space((void **) ((void *) &(trxn.token)), count_trxn + 1, - &max_trxn, sizeof(struct rxn_token_temp)); - } + if ((size_t)count_trxn + 1 > trxn.token.size()) + trxn.token.resize((size_t)count_trxn + 1); trxn.token[count_trxn].name = next_token->s->name; trxn.token[count_trxn].s = next_token->s; trxn.token[count_trxn].coef = coef * next_token->coef; @@ -2743,11 +2735,8 @@ trxn_add_phase(struct reaction *r_ptr, LDBLE coef, int combine) next_token = r_ptr->token; while (next_token->s != NULL || next_token->name != NULL) { - if (count_trxn + 1 >= max_trxn) - { - space((void **) ((void *) &(trxn.token)), count_trxn + 1, - &max_trxn, sizeof(struct rxn_token_temp)); - } + if ((size_t)count_trxn + 1 > trxn.token.size()) + trxn.token.resize((size_t)count_trxn + 1); if (next_token->s != NULL) { trxn.token[count_trxn].name = next_token->s->name; diff --git a/tidy.cpp b/tidy.cpp index 0ba1ec98..ce623bfa 100644 --- a/tidy.cpp +++ b/tidy.cpp @@ -2873,11 +2873,8 @@ species_rxn_to_trxn(struct species *s_ptr) trxn.token[i].unknown = NULL; trxn.token[i].coef = s_ptr->rxn->token[i].coef; count_trxn = i + 1; - if (count_trxn + 1 >= max_trxn) - { - space((void **) ((void *) &(trxn.token)), count_trxn + 1, - &max_trxn, sizeof(struct rxn_token_temp)); - } + if ((size_t)count_trxn + 1 > trxn.token.size()) + trxn.token.resize((size_t)count_trxn + 1); } return (OK); } @@ -2916,11 +2913,8 @@ phase_rxn_to_trxn(struct phase *phase_ptr, struct reaction *rxn_ptr) trxn.token[i].unknown = NULL; trxn.token[i].coef = rxn_ptr->token[i].coef; count_trxn = i + 1; - if (count_trxn + 1 >= max_trxn) - { - space((void **) ((void *) &(trxn.token)), count_trxn + 1, - &max_trxn, sizeof(struct rxn_token_temp)); - } + if ((size_t)count_trxn + 1 > trxn.token.size()) + trxn.token.resize((size_t)count_trxn + 1); } return (OK); }