mirror of
https://git.gfz-potsdam.de/naaice/iphreeqc.git
synced 2025-12-16 16:44:49 +01:00
strcpy_safe and strcat_safe
This commit is contained in:
parent
6d98c4e13d
commit
6d575967d4
@ -406,7 +406,7 @@ cxxNameDouble::add(const char *token, LDBLE total)
|
|||||||
//
|
//
|
||||||
{
|
{
|
||||||
char key[MAX_LENGTH];
|
char key[MAX_LENGTH];
|
||||||
strcpy_s(key, MAX_LENGTH, token);
|
Utilities::strcpy_safe(key, MAX_LENGTH, token);
|
||||||
|
|
||||||
cxxNameDouble::iterator current = (*this).find(key);
|
cxxNameDouble::iterator current = (*this).find(key);
|
||||||
if (current != (*this).end())
|
if (current != (*this).end())
|
||||||
|
|||||||
@ -550,7 +550,7 @@ numtostr(char * Result, LDBLE n)
|
|||||||
l_s[i] = '\0';
|
l_s[i] = '\0';
|
||||||
* p2c: basic.p, line 248:
|
* p2c: basic.p, line 248:
|
||||||
* Note: Modification of string length may translate incorrectly [146] *
|
* Note: Modification of string length may translate incorrectly [146] *
|
||||||
strcpy_s(Result, MAX_LENGTH, strltrim(l_s));
|
Utilities::strcpy_safe(Result, MAX_LENGTH, strltrim(l_s));
|
||||||
return Result;
|
return Result;
|
||||||
} */
|
} */
|
||||||
}
|
}
|
||||||
@ -1747,16 +1747,16 @@ void PBasic::
|
|||||||
snerr(const char * l_s)
|
snerr(const char * l_s)
|
||||||
{
|
{
|
||||||
char str[MAX_LENGTH] = {0};
|
char str[MAX_LENGTH] = {0};
|
||||||
strcpy_s(str, MAX_LENGTH, "Syntax_error ");
|
Utilities::strcpy_safe(str, MAX_LENGTH, "Syntax_error ");
|
||||||
if (phreeqci_gui)
|
if (phreeqci_gui)
|
||||||
{
|
{
|
||||||
_ASSERTE(nIDErrPrompt == 0);
|
_ASSERTE(nIDErrPrompt == 0);
|
||||||
nIDErrPrompt = IDS_ERR_SYNTAX;
|
nIDErrPrompt = IDS_ERR_SYNTAX;
|
||||||
}
|
}
|
||||||
strcat_s(str, MAX_LENGTH, l_s);
|
Utilities::strcat_safe(str, MAX_LENGTH, l_s);
|
||||||
strcat_s(str, MAX_LENGTH, " in line: ");
|
Utilities::strcat_safe(str, MAX_LENGTH, " in line: ");
|
||||||
if (strcmp(inbuf, "run"))
|
if (strcmp(inbuf, "run"))
|
||||||
strcat_s(str, MAX_LENGTH, inbuf);
|
Utilities::strcat_safe(str, MAX_LENGTH, inbuf);
|
||||||
errormsg(str);
|
errormsg(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1764,16 +1764,16 @@ void PBasic::
|
|||||||
tmerr(const char * l_s)
|
tmerr(const char * l_s)
|
||||||
{
|
{
|
||||||
char str[MAX_LENGTH] = {0};
|
char str[MAX_LENGTH] = {0};
|
||||||
strcpy_s(str, MAX_LENGTH, "Type mismatch error");
|
Utilities::strcpy_safe(str, MAX_LENGTH, "Type mismatch error");
|
||||||
if (phreeqci_gui)
|
if (phreeqci_gui)
|
||||||
{
|
{
|
||||||
_ASSERTE(nIDErrPrompt == 0);
|
_ASSERTE(nIDErrPrompt == 0);
|
||||||
nIDErrPrompt = IDS_ERR_MISMATCH;
|
nIDErrPrompt = IDS_ERR_MISMATCH;
|
||||||
}
|
}
|
||||||
strcat_s(str, MAX_LENGTH, l_s);
|
Utilities::strcat_safe(str, MAX_LENGTH, l_s);
|
||||||
strcat_s(str, MAX_LENGTH, " in line: ");
|
Utilities::strcat_safe(str, MAX_LENGTH, " in line: ");
|
||||||
if (strcmp(inbuf, "run"))
|
if (strcmp(inbuf, "run"))
|
||||||
strcat_s(str, MAX_LENGTH, inbuf);
|
Utilities::strcat_safe(str, MAX_LENGTH, inbuf);
|
||||||
errormsg(str);
|
errormsg(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1902,8 +1902,8 @@ require(int k, struct LOC_exec *LINK)
|
|||||||
if (item == command_tokens.end())
|
if (item == command_tokens.end())
|
||||||
snerr(": missing unknown command");
|
snerr(": missing unknown command");
|
||||||
else {
|
else {
|
||||||
strcpy_s(str, MAX_LENGTH, ": missing ");
|
Utilities::strcpy_safe(str, MAX_LENGTH, ": missing ");
|
||||||
strcat_s(str, MAX_LENGTH, item->first.c_str());
|
Utilities::strcat_safe(str, MAX_LENGTH, item->first.c_str());
|
||||||
snerr(str);
|
snerr(str);
|
||||||
}
|
}
|
||||||
#if !defined(R_SO)
|
#if !defined(R_SO)
|
||||||
@ -2546,7 +2546,7 @@ factor(struct LOC_exec * LINK)
|
|||||||
size_t l = elt_name.size();
|
size_t l = elt_name.size();
|
||||||
l = l < 256 ? 256 : l + 1;
|
l = l < 256 ? 256 : l + 1;
|
||||||
char* token = (char*)PhreeqcPtr->PHRQ_malloc(l * sizeof(char));
|
char* token = (char*)PhreeqcPtr->PHRQ_malloc(l * sizeof(char));
|
||||||
strcpy_s(token, l, elt_name.c_str());
|
Utilities::strcpy_safe(token, l, elt_name.c_str());
|
||||||
*elt_varrec->UU.U1.sval = token;
|
*elt_varrec->UU.U1.sval = token;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -6242,9 +6242,9 @@ exec(void)
|
|||||||
_ASSERTE(nIDErrPrompt == 0);
|
_ASSERTE(nIDErrPrompt == 0);
|
||||||
nIDErrPrompt = IDS_ERR_ILLEGAL;
|
nIDErrPrompt = IDS_ERR_ILLEGAL;
|
||||||
}
|
}
|
||||||
strcat_s(STR1, MAX_LENGTH, "Illegal command in line: ");
|
Utilities::strcat_safe(STR1, MAX_LENGTH, "Illegal command in line: ");
|
||||||
if (strcmp(inbuf, "run"))
|
if (strcmp(inbuf, "run"))
|
||||||
strcat_s(STR1, MAX_LENGTH, inbuf);
|
Utilities::strcat_safe(STR1, MAX_LENGTH, inbuf);
|
||||||
errormsg(STR1);
|
errormsg(STR1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -6394,7 +6394,7 @@ cmdplot_xy(struct LOC_exec *LINK)
|
|||||||
n[i] = expr(LINK);
|
n[i] = expr(LINK);
|
||||||
if (n[i].stringval)
|
if (n[i].stringval)
|
||||||
{
|
{
|
||||||
strcpy_s(STR[i], MAX_LENGTH, n[i].UU.sval);
|
Utilities::strcpy_safe(STR[i], MAX_LENGTH, n[i].UU.sval);
|
||||||
PhreeqcPtr->PHRQ_free(n[i].UU.sval);
|
PhreeqcPtr->PHRQ_free(n[i].UU.sval);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@ -14,6 +14,7 @@
|
|||||||
#include "PBasic.h"
|
#include "PBasic.h"
|
||||||
#include "Temperature.h"
|
#include "Temperature.h"
|
||||||
#include "SSassemblage.h"
|
#include "SSassemblage.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
#if defined(PHREEQCI_GUI)
|
#if defined(PHREEQCI_GUI)
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
@ -173,7 +174,7 @@ size_t Phreeqc::list_components(std::list<std::string> &list_c)
|
|||||||
{
|
{
|
||||||
if (it->first == "Charge") continue;
|
if (it->first == "Charge") continue;
|
||||||
char string[MAX_LENGTH];
|
char string[MAX_LENGTH];
|
||||||
strcpy_s(string, MAX_LENGTH, it->first.c_str());
|
Utilities::strcpy_safe(string, MAX_LENGTH, it->first.c_str());
|
||||||
class master *master_ptr = master_bsearch_primary(string);
|
class master *master_ptr = master_bsearch_primary(string);
|
||||||
if (master_ptr == NULL) continue;
|
if (master_ptr == NULL) continue;
|
||||||
if (master_ptr->type != AQ) continue;
|
if (master_ptr->type != AQ) continue;
|
||||||
|
|||||||
@ -14,7 +14,7 @@
|
|||||||
#include "cxxMix.h"
|
#include "cxxMix.h"
|
||||||
#include "Reaction.h"
|
#include "Reaction.h"
|
||||||
#include "Temperature.h"
|
#include "Temperature.h"
|
||||||
|
#include "Utils.h"
|
||||||
#if defined(PHREEQCI_GUI)
|
#if defined(PHREEQCI_GUI)
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
#define new DEBUG_NEW
|
#define new DEBUG_NEW
|
||||||
@ -66,11 +66,11 @@ cxxSystem::totalize(Phreeqc * phreeqc_ptr)
|
|||||||
if (this->solution != NULL)
|
if (this->solution != NULL)
|
||||||
{
|
{
|
||||||
char token[MAX_LENGTH];
|
char token[MAX_LENGTH];
|
||||||
strcpy_s(token, MAX_LENGTH, "O");
|
Utilities::strcpy_safe(token, MAX_LENGTH, "O");
|
||||||
this->totals[token] = this->solution->Get_total_o();
|
this->totals[token] = this->solution->Get_total_o();
|
||||||
strcpy_s(token, MAX_LENGTH, "H");
|
Utilities::strcpy_safe(token, MAX_LENGTH, "H");
|
||||||
this->totals[token] = this->solution->Get_total_h();
|
this->totals[token] = this->solution->Get_total_h();
|
||||||
strcpy_s(token, MAX_LENGTH, "Charge");
|
Utilities::strcpy_safe(token, MAX_LENGTH, "Charge");
|
||||||
this->totals[token] = this->solution->Get_cb();
|
this->totals[token] = this->solution->Get_cb();
|
||||||
this->totals.add_extensive(this->solution->Get_totals(), 1.0);
|
this->totals.add_extensive(this->solution->Get_totals(), 1.0);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -705,7 +705,7 @@ calc_logk_n(const char* name)
|
|||||||
{
|
{
|
||||||
l_logk[i] = 0.0;
|
l_logk[i] = 0.0;
|
||||||
}
|
}
|
||||||
strcpy_s(token, MAX_LENGTH, name);
|
Utilities::strcpy_safe(token, MAX_LENGTH, name);
|
||||||
logk_ptr = logk_search(token);
|
logk_ptr = logk_search(token);
|
||||||
if (logk_ptr != NULL)
|
if (logk_ptr != NULL)
|
||||||
{
|
{
|
||||||
@ -730,7 +730,7 @@ calc_logk_p(const char* name)
|
|||||||
LDBLE lk = -999.9;
|
LDBLE lk = -999.9;
|
||||||
LDBLE l_logk[MAX_LOG_K_INDICES];
|
LDBLE l_logk[MAX_LOG_K_INDICES];
|
||||||
|
|
||||||
strcpy_s(token, MAX_LENGTH, name);
|
Utilities::strcpy_safe(token, MAX_LENGTH, name);
|
||||||
phase_ptr = phase_bsearch(token, &j, FALSE);
|
phase_ptr = phase_bsearch(token, &j, FALSE);
|
||||||
|
|
||||||
if (phase_ptr != NULL)
|
if (phase_ptr != NULL)
|
||||||
@ -769,7 +769,7 @@ calc_logk_s(const char* name)
|
|||||||
class species* s_ptr;
|
class species* s_ptr;
|
||||||
LDBLE lk, l_logk[MAX_LOG_K_INDICES];
|
LDBLE lk, l_logk[MAX_LOG_K_INDICES];
|
||||||
|
|
||||||
strcpy_s(token, MAX_LENGTH, name);
|
Utilities::strcpy_safe(token, MAX_LENGTH, name);
|
||||||
s_ptr = s_search(token);
|
s_ptr = s_search(token);
|
||||||
if (s_ptr != NULL)
|
if (s_ptr != NULL)
|
||||||
{
|
{
|
||||||
@ -797,7 +797,7 @@ dh_a0(const char* name)
|
|||||||
class species* s_ptr;
|
class species* s_ptr;
|
||||||
double a = -999.99;
|
double a = -999.99;
|
||||||
|
|
||||||
strcpy_s(token, MAX_LENGTH, name);
|
Utilities::strcpy_safe(token, MAX_LENGTH, name);
|
||||||
s_ptr = s_search(token);
|
s_ptr = s_search(token);
|
||||||
if (s_ptr != NULL)
|
if (s_ptr != NULL)
|
||||||
{
|
{
|
||||||
@ -819,7 +819,7 @@ dh_bdot(const char* name)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
strcpy_s(token, MAX_LENGTH, name);
|
Utilities::strcpy_safe(token, MAX_LENGTH, name);
|
||||||
s_ptr = s_search(token);
|
s_ptr = s_search(token);
|
||||||
if (s_ptr != NULL)
|
if (s_ptr != NULL)
|
||||||
{
|
{
|
||||||
@ -839,7 +839,7 @@ calc_deltah_p(const char* name)
|
|||||||
LDBLE lkm, lkp;
|
LDBLE lkm, lkp;
|
||||||
LDBLE l_logk[MAX_LOG_K_INDICES];
|
LDBLE l_logk[MAX_LOG_K_INDICES];
|
||||||
double dh = -999.99;
|
double dh = -999.99;
|
||||||
strcpy_s(token, MAX_LENGTH, name);
|
Utilities::strcpy_safe(token, MAX_LENGTH, name);
|
||||||
phase_ptr = phase_bsearch(token, &j, FALSE);
|
phase_ptr = phase_bsearch(token, &j, FALSE);
|
||||||
|
|
||||||
if (phase_ptr != NULL)
|
if (phase_ptr != NULL)
|
||||||
@ -879,7 +879,7 @@ calc_deltah_s(const char* name)
|
|||||||
class species* s_ptr;
|
class species* s_ptr;
|
||||||
LDBLE lkm, lkp, l_logk[MAX_LOG_K_INDICES];
|
LDBLE lkm, lkp, l_logk[MAX_LOG_K_INDICES];
|
||||||
double dh = -999.99;
|
double dh = -999.99;
|
||||||
strcpy_s(token, MAX_LENGTH, name);
|
Utilities::strcpy_safe(token, MAX_LENGTH, name);
|
||||||
s_ptr = s_search(token);
|
s_ptr = s_search(token);
|
||||||
if (s_ptr != NULL)
|
if (s_ptr != NULL)
|
||||||
{
|
{
|
||||||
@ -929,7 +929,7 @@ calc_surface_charge(const char* surface_name)
|
|||||||
if (token_ptr->s->type != SURF)
|
if (token_ptr->s->type != SURF)
|
||||||
continue;
|
continue;
|
||||||
master_ptr = trxn.token[i].s->primary;
|
master_ptr = trxn.token[i].s->primary;
|
||||||
strcpy_s(token, MAX_LENGTH, master_ptr->elt->name);
|
Utilities::strcpy_safe(token, MAX_LENGTH, master_ptr->elt->name);
|
||||||
replace("_", " ", token);
|
replace("_", " ", token);
|
||||||
cptr = token;
|
cptr = token;
|
||||||
copy_token(token1, &cptr, &j);
|
copy_token(token1, &cptr, &j);
|
||||||
@ -1237,7 +1237,7 @@ calc_t_sc(const char* name)
|
|||||||
char token[MAX_LENGTH];
|
char token[MAX_LENGTH];
|
||||||
class species* s_ptr;
|
class species* s_ptr;
|
||||||
|
|
||||||
strcpy_s(token, MAX_LENGTH, name);
|
Utilities::strcpy_safe(token, MAX_LENGTH, name);
|
||||||
s_ptr = s_search(token);
|
s_ptr = s_search(token);
|
||||||
if (s_ptr != NULL && s_ptr->in)
|
if (s_ptr != NULL && s_ptr->in)
|
||||||
{
|
{
|
||||||
@ -1262,7 +1262,7 @@ calc_f_visc(const char* name)
|
|||||||
|
|
||||||
if (print_viscosity)
|
if (print_viscosity)
|
||||||
{
|
{
|
||||||
strcpy_s(token, MAX_LENGTH, name);
|
Utilities::strcpy_safe(token, MAX_LENGTH, name);
|
||||||
s_ptr = s_search(token);
|
s_ptr = s_search(token);
|
||||||
if (s_ptr != NULL && s_ptr->in)
|
if (s_ptr != NULL && s_ptr->in)
|
||||||
return s_ptr->dw_t_visc;
|
return s_ptr->dw_t_visc;
|
||||||
@ -2111,7 +2111,7 @@ match_elts_in_species(const char* name, const char* mytemplate)
|
|||||||
char token1[MAX_LENGTH], template1[MAX_LENGTH], equal_list1[MAX_LENGTH];
|
char token1[MAX_LENGTH], template1[MAX_LENGTH], equal_list1[MAX_LENGTH];
|
||||||
char str[2];
|
char str[2];
|
||||||
|
|
||||||
strcpy_s(token, MAX_LENGTH, name);
|
Utilities::strcpy_safe(token, MAX_LENGTH, name);
|
||||||
squeeze_white(token);
|
squeeze_white(token);
|
||||||
replace("(+", "(", token);
|
replace("(+", "(", token);
|
||||||
if (strstr("token", "++") != NULL)
|
if (strstr("token", "++") != NULL)
|
||||||
@ -2168,7 +2168,7 @@ match_elts_in_species(const char* name, const char* mytemplate)
|
|||||||
/*
|
/*
|
||||||
* Replace elements with first of equivalent elements
|
* Replace elements with first of equivalent elements
|
||||||
*/
|
*/
|
||||||
strcpy_s(template1, MAX_LENGTH, mytemplate);
|
Utilities::strcpy_safe(template1, MAX_LENGTH, mytemplate);
|
||||||
squeeze_white(template1);
|
squeeze_white(template1);
|
||||||
cptr = template1;
|
cptr = template1;
|
||||||
while (extract_bracket(&cptr, equal_list) == TRUE)
|
while (extract_bracket(&cptr, equal_list) == TRUE)
|
||||||
@ -2229,22 +2229,22 @@ match_elts_in_species(const char* name, const char* mytemplate)
|
|||||||
token[0] = '\0';
|
token[0] = '\0';
|
||||||
for (i = 0; i < count_match_tokens; i++)
|
for (i = 0; i < count_match_tokens; i++)
|
||||||
{
|
{
|
||||||
strcat_s(token, MAX_LENGTH, match_vector[i].first.c_str());
|
Utilities::strcat_safe(token, MAX_LENGTH, match_vector[i].first.c_str());
|
||||||
if (match_vector[i].second != 1.0)
|
if (match_vector[i].second != 1.0)
|
||||||
{
|
{
|
||||||
snprintf(token1, sizeof(token1), "%g", (double)match_vector[i].second);
|
snprintf(token1, sizeof(token1), "%g", (double)match_vector[i].second);
|
||||||
strcat_s(token, MAX_LENGTH, token1);
|
Utilities::strcat_safe(token, MAX_LENGTH, token1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Write a template name using first of equivalent elements
|
* Write a template name using first of equivalent elements
|
||||||
*/
|
*/
|
||||||
strcpy_s(template1, MAX_LENGTH, mytemplate);
|
Utilities::strcpy_safe(template1, MAX_LENGTH, mytemplate);
|
||||||
squeeze_white(template1);
|
squeeze_white(template1);
|
||||||
cptr = template1;
|
cptr = template1;
|
||||||
while (extract_bracket(&cptr, equal_list) == TRUE)
|
while (extract_bracket(&cptr, equal_list) == TRUE)
|
||||||
{
|
{
|
||||||
strcpy_s(equal_list1, MAX_LENGTH, equal_list);
|
Utilities::strcpy_safe(equal_list1, MAX_LENGTH, equal_list);
|
||||||
replace("{", "", equal_list);
|
replace("{", "", equal_list);
|
||||||
replace("}", "", equal_list);
|
replace("}", "", equal_list);
|
||||||
while (replace(",", " ", equal_list) == TRUE);
|
while (replace(",", " ", equal_list) == TRUE);
|
||||||
@ -2508,7 +2508,7 @@ surf_total_no_redox(const char* total_name, const char* surface_name)
|
|||||||
{
|
{
|
||||||
if (x[j]->type != SURFACE)
|
if (x[j]->type != SURFACE)
|
||||||
continue;
|
continue;
|
||||||
strcpy_s(token, MAX_LENGTH, x[j]->master[0]->elt->name);
|
Utilities::strcpy_safe(token, MAX_LENGTH, x[j]->master[0]->elt->name);
|
||||||
replace("_", " ", token);
|
replace("_", " ", token);
|
||||||
cptr = token;
|
cptr = token;
|
||||||
copy_token(name, &cptr, &k);
|
copy_token(name, &cptr, &k);
|
||||||
@ -2524,7 +2524,7 @@ surf_total_no_redox(const char* total_name, const char* surface_name)
|
|||||||
}
|
}
|
||||||
if (j >= count_unknowns)
|
if (j >= count_unknowns)
|
||||||
return (0);
|
return (0);
|
||||||
strcpy_s(surface_name_local, MAX_LENGTH, name);
|
Utilities::strcpy_safe(surface_name_local, MAX_LENGTH, name);
|
||||||
/*
|
/*
|
||||||
* find total moles of each element in diffuse layer...
|
* find total moles of each element in diffuse layer...
|
||||||
*/
|
*/
|
||||||
@ -2538,7 +2538,7 @@ surf_total_no_redox(const char* total_name, const char* surface_name)
|
|||||||
{
|
{
|
||||||
if (s_x[j]->next_elt[i].elt->master->type != SURF) continue;
|
if (s_x[j]->next_elt[i].elt->master->type != SURF) continue;
|
||||||
|
|
||||||
strcpy_s(token, MAX_LENGTH, s_x[j]->next_elt[i].elt->name);
|
Utilities::strcpy_safe(token, MAX_LENGTH, s_x[j]->next_elt[i].elt->name);
|
||||||
replace("_", " ", token);
|
replace("_", " ", token);
|
||||||
cptr = token;
|
cptr = token;
|
||||||
copy_token(name, &cptr, &k);
|
copy_token(name, &cptr, &k);
|
||||||
@ -3122,7 +3122,7 @@ system_total_elements(void)
|
|||||||
{
|
{
|
||||||
t = master_ptr->total;
|
t = master_ptr->total;
|
||||||
}
|
}
|
||||||
strcpy_s(name, MAX_LENGTH, master[i]->elt->name);
|
Utilities::strcpy_safe(name, MAX_LENGTH, master[i]->elt->name);
|
||||||
count_sys = sys.size();
|
count_sys = sys.size();
|
||||||
sys.resize(count_sys + 1);
|
sys.resize(count_sys + 1);
|
||||||
sys[count_sys].name = string_duplicate(name);
|
sys[count_sys].name = string_duplicate(name);
|
||||||
@ -3169,7 +3169,7 @@ system_total_si(void)
|
|||||||
iap += rxn_ptr->s->la * rxn_ptr->coef;
|
iap += rxn_ptr->s->la * rxn_ptr->coef;
|
||||||
}
|
}
|
||||||
si = -phases[i]->lk + iap;
|
si = -phases[i]->lk + iap;
|
||||||
strcpy_s(name, MAX_LENGTH, phases[i]->name);
|
Utilities::strcpy_safe(name, MAX_LENGTH, phases[i]->name);
|
||||||
size_t count_sys = sys.size();
|
size_t count_sys = sys.size();
|
||||||
sys.resize(count_sys + 1);
|
sys.resize(count_sys + 1);
|
||||||
sys[count_sys].name = string_duplicate(name);
|
sys[count_sys].name = string_duplicate(name);
|
||||||
@ -3487,7 +3487,7 @@ system_total_elt(const char* total_name)
|
|||||||
{
|
{
|
||||||
size_t count_sys = sys.size();
|
size_t count_sys = sys.size();
|
||||||
sys.resize(count_sys + 1);
|
sys.resize(count_sys + 1);
|
||||||
strcpy_s(name, MAX_LENGTH, x[k]->master[0]->elt->name);
|
Utilities::strcpy_safe(name, MAX_LENGTH, x[k]->master[0]->elt->name);
|
||||||
replace("_psi", "", name);
|
replace("_psi", "", name);
|
||||||
sys[count_sys].name = string_duplicate(name);
|
sys[count_sys].name = string_duplicate(name);
|
||||||
sys[count_sys].moles = elt_list[j].coef;
|
sys[count_sys].moles = elt_list[j].coef;
|
||||||
@ -3732,7 +3732,7 @@ system_total_elt_secondary(const char* total_name)
|
|||||||
}
|
}
|
||||||
if (l >= count_elts)
|
if (l >= count_elts)
|
||||||
continue;
|
continue;
|
||||||
strcpy_s(name, MAX_LENGTH, x[k]->master[0]->elt->name);
|
Utilities::strcpy_safe(name, MAX_LENGTH, x[k]->master[0]->elt->name);
|
||||||
replace("_psi", "", name);
|
replace("_psi", "", name);
|
||||||
size_t count_sys = sys.size();
|
size_t count_sys = sys.size();
|
||||||
sys.resize(count_sys + 1);
|
sys.resize(count_sys + 1);
|
||||||
@ -4047,8 +4047,8 @@ iso_value(const char* total_name)
|
|||||||
int j;
|
int j;
|
||||||
char token[MAX_LENGTH];
|
char token[MAX_LENGTH];
|
||||||
char my_total_name[MAX_LENGTH];
|
char my_total_name[MAX_LENGTH];
|
||||||
strcpy_s(token, MAX_LENGTH, "");
|
Utilities::strcpy_safe(token, MAX_LENGTH, "");
|
||||||
strcpy_s(my_total_name, MAX_LENGTH, total_name);
|
Utilities::strcpy_safe(my_total_name, MAX_LENGTH, total_name);
|
||||||
while (replace(" ", "_", my_total_name));
|
while (replace(" ", "_", my_total_name));
|
||||||
for (j = 0; j < (int)isotope_ratio.size(); j++)
|
for (j = 0; j < (int)isotope_ratio.size(); j++)
|
||||||
{
|
{
|
||||||
@ -4058,12 +4058,12 @@ iso_value(const char* total_name)
|
|||||||
continue;
|
continue;
|
||||||
return (isotope_ratio[j]->converted_ratio);
|
return (isotope_ratio[j]->converted_ratio);
|
||||||
}
|
}
|
||||||
strcpy_s(my_total_name, MAX_LENGTH, total_name);
|
Utilities::strcpy_safe(my_total_name, MAX_LENGTH, total_name);
|
||||||
while (replace("[", "", my_total_name));
|
while (replace("[", "", my_total_name));
|
||||||
while (replace("]", "", my_total_name));
|
while (replace("]", "", my_total_name));
|
||||||
strcat_s(token, MAX_LENGTH, "R(");
|
Utilities::strcat_safe(token, MAX_LENGTH, "R(");
|
||||||
strcat_s(token, MAX_LENGTH, my_total_name);
|
Utilities::strcat_safe(token, MAX_LENGTH, my_total_name);
|
||||||
strcat_s(token, MAX_LENGTH, ")");
|
Utilities::strcat_safe(token, MAX_LENGTH, ")");
|
||||||
for (j = 0; j < (int)isotope_ratio.size(); j++)
|
for (j = 0; j < (int)isotope_ratio.size(); j++)
|
||||||
{
|
{
|
||||||
if (isotope_ratio[j]->ratio == MISSING)
|
if (isotope_ratio[j]->ratio == MISSING)
|
||||||
@ -4082,10 +4082,10 @@ iso_unit(const char* total_name)
|
|||||||
char token[MAX_LENGTH], unit[MAX_LENGTH];
|
char token[MAX_LENGTH], unit[MAX_LENGTH];
|
||||||
class master_isotope* master_isotope_ptr;
|
class master_isotope* master_isotope_ptr;
|
||||||
char my_total_name[MAX_LENGTH];
|
char my_total_name[MAX_LENGTH];
|
||||||
strcpy_s(token, MAX_LENGTH, "");
|
Utilities::strcpy_safe(token, MAX_LENGTH, "");
|
||||||
strcpy_s(my_total_name, MAX_LENGTH, total_name);
|
Utilities::strcpy_safe(my_total_name, MAX_LENGTH, total_name);
|
||||||
while (replace(" ", "_", my_total_name));
|
while (replace(" ", "_", my_total_name));
|
||||||
strcpy_s(unit, MAX_LENGTH, "unknown");
|
Utilities::strcpy_safe(unit, MAX_LENGTH, "unknown");
|
||||||
for (j = 0; j < (int)isotope_ratio.size(); j++)
|
for (j = 0; j < (int)isotope_ratio.size(); j++)
|
||||||
{
|
{
|
||||||
if (isotope_ratio[j]->ratio == MISSING)
|
if (isotope_ratio[j]->ratio == MISSING)
|
||||||
@ -4095,16 +4095,16 @@ iso_unit(const char* total_name)
|
|||||||
master_isotope_ptr = master_isotope_search(isotope_ratio[j]->isotope_name);
|
master_isotope_ptr = master_isotope_search(isotope_ratio[j]->isotope_name);
|
||||||
if (master_isotope_ptr != NULL)
|
if (master_isotope_ptr != NULL)
|
||||||
{
|
{
|
||||||
strcpy_s(unit, MAX_LENGTH, master_isotope_ptr->units);
|
Utilities::strcpy_safe(unit, MAX_LENGTH, master_isotope_ptr->units);
|
||||||
}
|
}
|
||||||
return string_duplicate(unit);
|
return string_duplicate(unit);
|
||||||
}
|
}
|
||||||
strcpy_s(my_total_name, MAX_LENGTH, total_name);
|
Utilities::strcpy_safe(my_total_name, MAX_LENGTH, total_name);
|
||||||
while (replace("[", "", my_total_name));
|
while (replace("[", "", my_total_name));
|
||||||
while (replace("]", "", my_total_name));
|
while (replace("]", "", my_total_name));
|
||||||
strcat_s(token, MAX_LENGTH, "R(");
|
Utilities::strcat_safe(token, MAX_LENGTH, "R(");
|
||||||
strcat_s(token, MAX_LENGTH, my_total_name);
|
Utilities::strcat_safe(token, MAX_LENGTH, my_total_name);
|
||||||
strcat_s(token, MAX_LENGTH, ")");
|
Utilities::strcat_safe(token, MAX_LENGTH, ")");
|
||||||
for (j = 0; j < (int)isotope_ratio.size(); j++)
|
for (j = 0; j < (int)isotope_ratio.size(); j++)
|
||||||
{
|
{
|
||||||
if (isotope_ratio[j]->ratio == MISSING)
|
if (isotope_ratio[j]->ratio == MISSING)
|
||||||
@ -4114,7 +4114,7 @@ iso_unit(const char* total_name)
|
|||||||
master_isotope_ptr = master_isotope_search(isotope_ratio[j]->isotope_name);
|
master_isotope_ptr = master_isotope_search(isotope_ratio[j]->isotope_name);
|
||||||
if (master_isotope_ptr != NULL)
|
if (master_isotope_ptr != NULL)
|
||||||
{
|
{
|
||||||
strcpy_s(unit, MAX_LENGTH, master_isotope_ptr->units);
|
Utilities::strcpy_safe(unit, MAX_LENGTH, master_isotope_ptr->units);
|
||||||
}
|
}
|
||||||
return string_duplicate(unit);
|
return string_duplicate(unit);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -181,6 +181,57 @@ Utilities::safe_exp(LDBLE t)
|
|||||||
}
|
}
|
||||||
return exp(t);
|
return exp(t);
|
||||||
}
|
}
|
||||||
|
size_t Utilities::
|
||||||
|
strcpy_safe(char* dest, size_t max, const char* src)
|
||||||
|
{
|
||||||
|
size_t lsrc = 0;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (dest == nullptr || src == nullptr)
|
||||||
|
{
|
||||||
|
std::cerr << "nullptr in Utilities::strcpy_safe." << std::endl;
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
lsrc = strlen(src);
|
||||||
|
if (lsrc + 1 > max)
|
||||||
|
{
|
||||||
|
std::cerr << "Buffer overrun in Utilities::strcpy_safe." << std::endl;
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
memcpy(dest, src, (lsrc + 1) * sizeof(char));
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
return lsrc;
|
||||||
|
}
|
||||||
|
size_t Utilities::
|
||||||
|
strcat_safe(char* dest, size_t max, const char* src)
|
||||||
|
{
|
||||||
|
size_t ldest = 0, lsrc = 0;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (dest == nullptr || src == nullptr)
|
||||||
|
{
|
||||||
|
std::cerr << "nullptr in Utilities::strcat_safe." << std::endl;
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
lsrc = strlen(src);
|
||||||
|
ldest = strlen(dest);
|
||||||
|
if (ldest + lsrc + 1 > max)
|
||||||
|
{
|
||||||
|
std::cerr << "Buffer overrun in Utilities::strcat_safe." << std::endl;
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
memcpy(&dest[ldest], src, (lsrc + 1) * sizeof(char));
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
return ldest + lsrc;
|
||||||
|
}
|
||||||
//+NAN LDBLE: 7ff8000000000000
|
//+NAN LDBLE: 7ff8000000000000
|
||||||
//-NAN LDBLE: fff8000000000000
|
//-NAN LDBLE: fff8000000000000
|
||||||
/*
|
/*
|
||||||
|
|||||||
@ -20,7 +20,8 @@ namespace Utilities
|
|||||||
void str_toupper(std::string & str);
|
void str_toupper(std::string & str);
|
||||||
std::string pad_right(const std::string & str, size_t l);
|
std::string pad_right(const std::string & str, size_t l);
|
||||||
bool replace(const char *str1, const char *str2, std::string & str);
|
bool replace(const char *str1, const char *str2, std::string & str);
|
||||||
|
size_t strcat_safe(char* dest, size_t max, const char* src);
|
||||||
|
size_t strcpy_safe(char* dest, size_t max, const char* src);
|
||||||
void squeeze_white(std::string & s_l);
|
void squeeze_white(std::string & s_l);
|
||||||
double convert_time(double t, std::string in, std::string out);
|
double convert_time(double t, std::string in, std::string out);
|
||||||
LDBLE safe_exp(LDBLE t);
|
LDBLE safe_exp(LDBLE t);
|
||||||
|
|||||||
@ -127,7 +127,7 @@ get_line(void)
|
|||||||
if (line == NULL)
|
if (line == NULL)
|
||||||
malloc_error();
|
malloc_error();
|
||||||
}
|
}
|
||||||
strcpy_s(line, max_line, phrq_io->Get_m_line().c_str());
|
Utilities::strcpy_safe(line, max_line, phrq_io->Get_m_line().c_str());
|
||||||
strcpy_s(line_save, max_line, phrq_io->Get_m_line_save().c_str());
|
Utilities::strcpy_safe(line_save, max_line, phrq_io->Get_m_line_save().c_str());
|
||||||
return j;
|
return j;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -54,10 +54,10 @@ inverse_models(void)
|
|||||||
*/
|
*/
|
||||||
if (inverse[n].pat != NULL)
|
if (inverse[n].pat != NULL)
|
||||||
{
|
{
|
||||||
strcpy_s(string, MAX_LENGTH, inverse[n].pat);
|
Utilities::strcat_safe(string, MAX_LENGTH, inverse[n].pat);
|
||||||
if (replace(".pat", ".pat", string) != TRUE)
|
if (replace(".pat", ".pat", string) != TRUE)
|
||||||
{
|
{
|
||||||
strcat_s(string, strlen(string), ".pat");
|
Utilities::strcat_safe(string, strlen(string), ".pat");
|
||||||
}
|
}
|
||||||
netpath_file = fopen(string, "w");
|
netpath_file = fopen(string, "w");
|
||||||
if (netpath_file == NULL)
|
if (netpath_file == NULL)
|
||||||
@ -4174,11 +4174,11 @@ print_total_multi(FILE * l_netpath_file, cxxSolution *solution_ptr,
|
|||||||
LDBLE sum;
|
LDBLE sum;
|
||||||
int i, found;
|
int i, found;
|
||||||
|
|
||||||
strcpy_s(elts[0], MAX_LENGTH, elt0);
|
Utilities::strcat_safe(elts[0], MAX_LENGTH, elt0);
|
||||||
strcpy_s(elts[1], MAX_LENGTH, elt1);
|
Utilities::strcat_safe(elts[1], MAX_LENGTH, elt1);
|
||||||
strcpy_s(elts[2], MAX_LENGTH, elt2);
|
Utilities::strcat_safe(elts[2], MAX_LENGTH, elt2);
|
||||||
strcpy_s(elts[3], MAX_LENGTH, elt3);
|
Utilities::strcat_safe(elts[3], MAX_LENGTH, elt3);
|
||||||
strcpy_s(elts[4], MAX_LENGTH, elt4);
|
Utilities::strcat_safe(elts[4], MAX_LENGTH, elt4);
|
||||||
|
|
||||||
|
|
||||||
sum = 0;
|
sum = 0;
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
#include "Phreeqc.h"
|
#include "Phreeqc.h"
|
||||||
#include "phqalloc.h"
|
#include "phqalloc.h"
|
||||||
#include "Solution.h"
|
#include "Solution.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
#if defined(PHREEQCI_GUI)
|
#if defined(PHREEQCI_GUI)
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
@ -982,7 +983,7 @@ print_isotope_ratios(void)
|
|||||||
/*
|
/*
|
||||||
* Print isotope ratio
|
* Print isotope ratio
|
||||||
*/
|
*/
|
||||||
strcpy_s(token, MAX_LENGTH, isotope_ratio[j]->name);
|
Utilities::strcpy_safe(token, MAX_LENGTH, isotope_ratio[j]->name);
|
||||||
while (replace("_", " ", token) == TRUE);
|
while (replace("_", " ", token) == TRUE);
|
||||||
output_msg(sformatf( " %-20s\t%12.5e\t%15.5g %-10s\n",
|
output_msg(sformatf( " %-20s\t%12.5e\t%15.5g %-10s\n",
|
||||||
token, (double) isotope_ratio[j]->ratio,
|
token, (double) isotope_ratio[j]->ratio,
|
||||||
@ -1045,7 +1046,7 @@ print_isotope_alphas(void)
|
|||||||
/*
|
/*
|
||||||
* Print isotope ratio
|
* Print isotope ratio
|
||||||
*/
|
*/
|
||||||
strcpy_s(token, MAX_LENGTH, isotope_alpha[j]->name);
|
Utilities::strcpy_safe(token, MAX_LENGTH, isotope_alpha[j]->name);
|
||||||
while (replace("_", " ", token) == TRUE);
|
while (replace("_", " ", token) == TRUE);
|
||||||
if (isotope_alpha[j]->named_logk != NULL)
|
if (isotope_alpha[j]->named_logk != NULL)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -67,6 +67,7 @@
|
|||||||
#include "nvector_serial.h"
|
#include "nvector_serial.h"
|
||||||
#include "sundialstypes.h"
|
#include "sundialstypes.h"
|
||||||
#include "sundialsmath.h"
|
#include "sundialsmath.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
/* WARNING don`t include any headers below here */
|
/* WARNING don`t include any headers below here */
|
||||||
|
|
||||||
@ -173,7 +174,7 @@ M_EnvInit_Serial(integertype vec_length)
|
|||||||
me->ops->nvprint = N_VPrint_Serial;
|
me->ops->nvprint = N_VPrint_Serial;
|
||||||
|
|
||||||
/* Attach ID tag */
|
/* Attach ID tag */
|
||||||
strcpy_s(me->tag, 8, ID_TAG_S);
|
Utilities::strcpy_safe(me->tag, 8, ID_TAG_S);
|
||||||
|
|
||||||
return (me);
|
return (me);
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
#include "Phreeqc.h"
|
#include "Phreeqc.h"
|
||||||
#include "phqalloc.h"
|
#include "phqalloc.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
#if defined(PHREEQCI_GUI)
|
#if defined(PHREEQCI_GUI)
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
@ -133,7 +134,7 @@ parse_eq(char* eqn, std::vector<class elt_list>& new_elt_list, int association)
|
|||||||
* Get elements in species or mineral formula
|
* Get elements in species or mineral formula
|
||||||
*/
|
*/
|
||||||
count_elts = 0;
|
count_elts = 0;
|
||||||
strcpy_s(token, MAX_LENGTH, trxn.token[0].name);
|
Utilities::strcpy_safe(token, MAX_LENGTH, trxn.token[0].name);
|
||||||
replace("(s)", "", token);
|
replace("(s)", "", token);
|
||||||
replace("(S)", "", token);
|
replace("(S)", "", token);
|
||||||
replace("(g)", "", token);
|
replace("(g)", "", token);
|
||||||
|
|||||||
@ -321,7 +321,7 @@ print_diffuse_layer(cxxSurfaceCharge *charge_ptr)
|
|||||||
add_elt_list(s_x[j]->next_elt, moles_surface);
|
add_elt_list(s_x[j]->next_elt, moles_surface);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
strcpy_s(token, MAX_LENGTH, s_h2o->name);
|
Utilities::strcpy_safe(token, MAX_LENGTH, s_h2o->name);
|
||||||
ptr = &(token[0]);
|
ptr = &(token[0]);
|
||||||
get_elts_in_species (&ptr, mass_water_surface / gfw_water);
|
get_elts_in_species (&ptr, mass_water_surface / gfw_water);
|
||||||
*/
|
*/
|
||||||
@ -427,9 +427,9 @@ print_eh(void)
|
|||||||
/*
|
/*
|
||||||
* Print result
|
* Print result
|
||||||
*/
|
*/
|
||||||
strcpy_s(token, MAX_LENGTH, master[i]->elt->name);
|
Utilities::strcpy_safe(token, MAX_LENGTH, master[i]->elt->name);
|
||||||
strcat_s(token, MAX_LENGTH, "/");
|
Utilities::strcat_safe(token, MAX_LENGTH, "/");
|
||||||
strcat_s(token, MAX_LENGTH, master[k]->elt->name);
|
Utilities::strcat_safe(token, MAX_LENGTH, master[k]->elt->name);
|
||||||
output_msg(sformatf("\t%-15s%12.4f%12.4f\n", token,
|
output_msg(sformatf("\t%-15s%12.4f%12.4f\n", token,
|
||||||
(double) pe, (double) eh));
|
(double) pe, (double) eh));
|
||||||
}
|
}
|
||||||
@ -2904,34 +2904,34 @@ punch_identifiers(void)
|
|||||||
switch (state)
|
switch (state)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
strcpy_s(token, MAX_LENGTH, "init");
|
Utilities::strcpy_safe(token, MAX_LENGTH, "init");
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
strcpy_s(token, MAX_LENGTH, "i_soln");
|
Utilities::strcpy_safe(token, MAX_LENGTH, "i_soln");
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
strcpy_s(token, MAX_LENGTH, "i_exch");
|
Utilities::strcpy_safe(token, MAX_LENGTH, "i_exch");
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
strcpy_s(token, MAX_LENGTH, "i_surf");
|
Utilities::strcpy_safe(token, MAX_LENGTH, "i_surf");
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
strcpy_s(token, MAX_LENGTH, "i_gas");
|
Utilities::strcpy_safe(token, MAX_LENGTH, "i_gas");
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
strcpy_s(token, MAX_LENGTH, "react");
|
Utilities::strcpy_safe(token, MAX_LENGTH, "react");
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
strcpy_s(token, MAX_LENGTH, "inverse");
|
Utilities::strcpy_safe(token, MAX_LENGTH, "inverse");
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
strcpy_s(token, MAX_LENGTH, "advect");
|
Utilities::strcpy_safe(token, MAX_LENGTH, "advect");
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
strcpy_s(token, MAX_LENGTH, "transp");
|
Utilities::strcpy_safe(token, MAX_LENGTH, "transp");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
strcpy_s(token, MAX_LENGTH, "unknown");
|
Utilities::strcpy_safe(token, MAX_LENGTH, "unknown");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fpunchf(PHAST_NULL("state"), sformat, token);
|
fpunchf(PHAST_NULL("state"), sformat, token);
|
||||||
|
|||||||
@ -1097,7 +1097,7 @@ read_exchange_master_species(void)
|
|||||||
if (token[0] == '[') {
|
if (token[0] == '[') {
|
||||||
cptr1 = token;
|
cptr1 = token;
|
||||||
get_elt(&cptr, element, &l);
|
get_elt(&cptr, element, &l);
|
||||||
strcpy_s(token, MAX_LENGTH, element);
|
Utilities::strcpy_safe(token, MAX_LENGTH, element);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
replace("(+", "(", token);
|
replace("(+", "(", token);
|
||||||
@ -1752,7 +1752,7 @@ read_inv_phases(class inverse *inverse_ptr, const char* cptr)
|
|||||||
j = copy_token(token, &cptr, &l);
|
j = copy_token(token, &cptr, &l);
|
||||||
if (j == EMPTY)
|
if (j == EMPTY)
|
||||||
break;
|
break;
|
||||||
strcpy_s(token1, MAX_LENGTH, token);
|
Utilities::strcpy_safe(token1, MAX_LENGTH, token);
|
||||||
str_tolower(token1);
|
str_tolower(token1);
|
||||||
if (token1[0] == 'p')
|
if (token1[0] == 'p')
|
||||||
{
|
{
|
||||||
@ -3107,7 +3107,7 @@ read_master_species(void)
|
|||||||
if (token[0] == '[') {
|
if (token[0] == '[') {
|
||||||
cptr1 = token;
|
cptr1 = token;
|
||||||
get_elt(&cptr, element, &l);
|
get_elt(&cptr, element, &l);
|
||||||
strcpy_s(token, MAX_LENGTH, element);
|
Utilities::strcpy_safe(token, MAX_LENGTH, element);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
replace("(+", "(", token);
|
replace("(+", "(", token);
|
||||||
@ -3726,7 +3726,7 @@ read_phases(void)
|
|||||||
/*
|
/*
|
||||||
* Get pointer to each species in the reaction, store new species if necessary
|
* Get pointer to each species in the reaction, store new species if necessary
|
||||||
*/
|
*/
|
||||||
strcpy_s(token1, MAX_LENGTH, trxn.token[0].name);
|
Utilities::strcpy_safe(token1, MAX_LENGTH, trxn.token[0].name);
|
||||||
replace("(g)", "", token1);
|
replace("(g)", "", token1);
|
||||||
replace("(s)", "", token1);
|
replace("(s)", "", token1);
|
||||||
replace("(G)", "", token1);
|
replace("(G)", "", token1);
|
||||||
@ -3739,7 +3739,7 @@ read_phases(void)
|
|||||||
(strstr(trxn.token[i].name, "(S)") == NULL) &&
|
(strstr(trxn.token[i].name, "(S)") == NULL) &&
|
||||||
(strstr(trxn.token[i].name, "(G)") == NULL))
|
(strstr(trxn.token[i].name, "(G)") == NULL))
|
||||||
{
|
{
|
||||||
strcpy_s(token1, MAX_LENGTH, trxn.token[i].name);
|
Utilities::strcpy_safe(token1, MAX_LENGTH, trxn.token[i].name);
|
||||||
replace("(aq)", "", token1);
|
replace("(aq)", "", token1);
|
||||||
replace("(AQ)", "", token1);
|
replace("(AQ)", "", token1);
|
||||||
replace("H2O(l)", "H2O", token1);
|
replace("H2O(l)", "H2O", token1);
|
||||||
@ -5737,7 +5737,7 @@ read_use(void)
|
|||||||
/*
|
/*
|
||||||
* Read number
|
* Read number
|
||||||
*/
|
*/
|
||||||
strcpy_s(token1, MAX_LENGTH, token);
|
Utilities::strcpy_safe(token1, MAX_LENGTH, token);
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
i = copy_token(token, &cptr, &l);
|
i = copy_token(token, &cptr, &l);
|
||||||
@ -7013,16 +7013,16 @@ read_surface_master_species(void)
|
|||||||
master[count_master]->s = s_store(token1.c_str(), l_z, FALSE);
|
master[count_master]->s = s_store(token1.c_str(), l_z, FALSE);
|
||||||
}
|
}
|
||||||
master[count_master]->primary = TRUE;
|
master[count_master]->primary = TRUE;
|
||||||
strcpy_s(token, MAX_LENGTH, master[count_master]->elt->name);
|
Utilities::strcpy_safe(token, MAX_LENGTH, master[count_master]->elt->name);
|
||||||
count_master++;
|
count_master++;
|
||||||
/*
|
/*
|
||||||
* Save values in master and species structure for surface psi
|
* Save values in master and species structure for surface psi
|
||||||
*/
|
*/
|
||||||
strcpy_s(token1, MAX_LENGTH, token);
|
Utilities::strcpy_safe(token1, MAX_LENGTH, token);
|
||||||
replace("_", " ", token1);
|
replace("_", " ", token1);
|
||||||
cptr1 = token1;
|
cptr1 = token1;
|
||||||
copy_token(token, &cptr1, &l);
|
copy_token(token, &cptr1, &l);
|
||||||
strcat_s(token, MAX_LENGTH, "_psi");
|
Utilities::strcat_safe(token, MAX_LENGTH, "_psi");
|
||||||
add_psi_master_species(token);
|
add_psi_master_species(token);
|
||||||
opt_save = OPTION_DEFAULT;
|
opt_save = OPTION_DEFAULT;
|
||||||
break;
|
break;
|
||||||
@ -7043,7 +7043,7 @@ add_psi_master_species(char *token)
|
|||||||
const char* cptr;
|
const char* cptr;
|
||||||
char token1[MAX_LENGTH] = "";
|
char token1[MAX_LENGTH] = "";
|
||||||
int i, n, plane;
|
int i, n, plane;
|
||||||
strcpy_s(token1, MAX_LENGTH, token);
|
Utilities::strcpy_safe(token1, MAX_LENGTH, token);
|
||||||
for (plane = SURF_PSI; plane <= SURF_PSI2; plane++)
|
for (plane = SURF_PSI; plane <= SURF_PSI2; plane++)
|
||||||
{
|
{
|
||||||
strcpy(token, token1);
|
strcpy(token, token1);
|
||||||
@ -9480,7 +9480,7 @@ read_copy(void)
|
|||||||
switch (next_keyword)
|
switch (next_keyword)
|
||||||
{
|
{
|
||||||
case Keywords::KEY_NONE: /* Have not read line with keyword */
|
case Keywords::KEY_NONE: /* Have not read line with keyword */
|
||||||
strcpy_s(nonkeyword, MAX_LENGTH, token);
|
Utilities::strcpy_safe(nonkeyword, MAX_LENGTH, token);
|
||||||
break;
|
break;
|
||||||
case Keywords::KEY_SOLUTION: /* Solution */
|
case Keywords::KEY_SOLUTION: /* Solution */
|
||||||
case Keywords::KEY_EQUILIBRIUM_PHASES: /* Pure phases */
|
case Keywords::KEY_EQUILIBRIUM_PHASES: /* Pure phases */
|
||||||
@ -9507,7 +9507,7 @@ read_copy(void)
|
|||||||
/*
|
/*
|
||||||
* Read source index
|
* Read source index
|
||||||
*/
|
*/
|
||||||
strcpy_s(token1, MAX_LENGTH, token);
|
Utilities::strcpy_safe(token1, MAX_LENGTH, token);
|
||||||
i = copy_token(token, &cptr, &l);
|
i = copy_token(token, &cptr, &l);
|
||||||
if (i == DIGIT)
|
if (i == DIGIT)
|
||||||
{
|
{
|
||||||
@ -9727,8 +9727,8 @@ cleanup_after_parser(CParser &parser)
|
|||||||
// check_key sets next_keyword
|
// check_key sets next_keyword
|
||||||
if (parser.get_m_line_type() == PHRQ_io::LT_EOF)
|
if (parser.get_m_line_type() == PHRQ_io::LT_EOF)
|
||||||
{
|
{
|
||||||
strcpy_s(line, max_line, "");
|
Utilities::strcpy_safe(line, max_line, "");
|
||||||
strcpy_s(line_save, max_line, "");
|
Utilities::strcpy_safe(line_save, max_line, "");
|
||||||
next_keyword = Keywords::KEY_END;
|
next_keyword = Keywords::KEY_END;
|
||||||
return(TRUE);
|
return(TRUE);
|
||||||
}
|
}
|
||||||
@ -9750,8 +9750,8 @@ cleanup_after_parser(CParser &parser)
|
|||||||
if (line == NULL)
|
if (line == NULL)
|
||||||
malloc_error();
|
malloc_error();
|
||||||
}
|
}
|
||||||
strcpy_s(line, max_line, parser.line().c_str());
|
Utilities::strcpy_safe(line, max_line, parser.line().c_str());
|
||||||
strcpy_s(line_save, max_line, parser.line_save().c_str());
|
Utilities::strcpy_safe(line_save, max_line, parser.line_save().c_str());
|
||||||
return return_value;
|
return return_value;
|
||||||
}
|
}
|
||||||
/* ---------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------- */
|
||||||
|
|||||||
@ -707,13 +707,13 @@ add_pp_assemblage(cxxPPassemblage *pp_assemblage_ptr)
|
|||||||
comp_ptr->Set_delta(0.0);
|
comp_ptr->Set_delta(0.0);
|
||||||
if (comp_ptr->Get_add_formula().size() > 0)
|
if (comp_ptr->Get_add_formula().size() > 0)
|
||||||
{
|
{
|
||||||
strcpy_s(token, MAX_LENGTH, comp_ptr->Get_add_formula().c_str());
|
Utilities::strcpy_safe(token, MAX_LENGTH, comp_ptr->Get_add_formula().c_str());
|
||||||
cptr = &(token[0]);
|
cptr = &(token[0]);
|
||||||
get_elts_in_species(&cptr, 1.0);
|
get_elts_in_species(&cptr, 1.0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
strcpy_s(token, MAX_LENGTH, phase_ptr->formula);
|
Utilities::strcpy_safe(token, MAX_LENGTH, phase_ptr->formula);
|
||||||
add_elt_list(phase_ptr->next_elt, 1.0);
|
add_elt_list(phase_ptr->next_elt, 1.0);
|
||||||
}
|
}
|
||||||
if (comp_ptr->Get_moles() > 0.0)
|
if (comp_ptr->Get_moles() > 0.0)
|
||||||
|
|||||||
@ -914,13 +914,13 @@ build_tally_table(void)
|
|||||||
paren_count = 0;
|
paren_count = 0;
|
||||||
if (comp_ptr->Get_add_formula().size() > 0)
|
if (comp_ptr->Get_add_formula().size() > 0)
|
||||||
{
|
{
|
||||||
strcpy_s(token, MAX_LENGTH, comp_ptr->Get_add_formula().c_str());
|
Utilities::strcpy_safe(token, MAX_LENGTH, comp_ptr->Get_add_formula().c_str());
|
||||||
cptr = &(token[0]);
|
cptr = &(token[0]);
|
||||||
get_elts_in_species(&cptr, 1.0);
|
get_elts_in_species(&cptr, 1.0);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
strcpy_s(token, MAX_LENGTH, phase_ptr->formula);
|
Utilities::strcpy_safe(token, MAX_LENGTH, phase_ptr->formula);
|
||||||
add_elt_list(phase_ptr->next_elt, 1.0);
|
add_elt_list(phase_ptr->next_elt, 1.0);
|
||||||
}
|
}
|
||||||
elt_list_combine();
|
elt_list_combine();
|
||||||
@ -971,7 +971,7 @@ build_tally_table(void)
|
|||||||
tally_table[n].type = Ss_phase;
|
tally_table[n].type = Ss_phase;
|
||||||
count_elts = 0;
|
count_elts = 0;
|
||||||
paren_count = 0;
|
paren_count = 0;
|
||||||
strcpy_s(token, MAX_LENGTH, phase_ptr->formula);
|
Utilities::strcpy_safe(token, MAX_LENGTH, phase_ptr->formula);
|
||||||
add_elt_list(phase_ptr->next_elt, 1.0);
|
add_elt_list(phase_ptr->next_elt, 1.0);
|
||||||
elt_list_combine();
|
elt_list_combine();
|
||||||
tally_table[n].formula = elt_list_vsave();
|
tally_table[n].formula = elt_list_vsave();
|
||||||
@ -1019,7 +1019,7 @@ build_tally_table(void)
|
|||||||
phase_ptr = NULL;
|
phase_ptr = NULL;
|
||||||
if (kinetics_comp_ptr->Get_namecoef().size() == 1)
|
if (kinetics_comp_ptr->Get_namecoef().size() == 1)
|
||||||
{
|
{
|
||||||
strcpy_s(token, MAX_LENGTH, kinetics_comp_ptr->Get_namecoef().begin()->first.c_str());
|
Utilities::strcpy_safe(token, MAX_LENGTH, kinetics_comp_ptr->Get_namecoef().begin()->first.c_str());
|
||||||
phase_ptr = phase_bsearch(token, &p, FALSE);
|
phase_ptr = phase_bsearch(token, &p, FALSE);
|
||||||
}
|
}
|
||||||
if (phase_ptr != NULL)
|
if (phase_ptr != NULL)
|
||||||
|
|||||||
@ -819,7 +819,7 @@ replace_solids_gases(void)
|
|||||||
/* try phase name without (g) or (s) */
|
/* try phase name without (g) or (s) */
|
||||||
if (phase_ptr == NULL)
|
if (phase_ptr == NULL)
|
||||||
{
|
{
|
||||||
strcpy_s(token, MAX_LENGTH, token_ptr->name);
|
Utilities::strcpy_safe(token, MAX_LENGTH, token_ptr->name);
|
||||||
replace("(g)", "", token);
|
replace("(g)", "", token);
|
||||||
replace("(s)", "", token);
|
replace("(s)", "", token);
|
||||||
replace("(G)", "", token);
|
replace("(G)", "", token);
|
||||||
@ -2013,8 +2013,8 @@ tidy_punch(void)
|
|||||||
" %s.", pair_ref.first.c_str());
|
" %s.", pair_ref.first.c_str());
|
||||||
warning_msg(error_string);
|
warning_msg(error_string);
|
||||||
}
|
}
|
||||||
// strcpy_s(token, MAX_LENGTH, "m_");
|
// Utilities::strcpy_safe(token, MAX_LENGTH, "m_");
|
||||||
//strcat_s(token, punch.molalities[i].name);
|
//Utilities::strcat_safe(token, punch.molalities[i].name);
|
||||||
//fpunchf_heading(sformatf("%*s\t", l, token));
|
//fpunchf_heading(sformatf("%*s\t", l, token));
|
||||||
//if (punch.molalities[i].s == NULL)
|
//if (punch.molalities[i].s == NULL)
|
||||||
//{
|
//{
|
||||||
@ -2039,8 +2039,8 @@ tidy_punch(void)
|
|||||||
" %s.", pair_ref.first.c_str());
|
" %s.", pair_ref.first.c_str());
|
||||||
warning_msg(error_string);
|
warning_msg(error_string);
|
||||||
}
|
}
|
||||||
// strcpy_s(token, MAX_LENGTH, "la_");
|
// Utilities::strcpy_safe(token, MAX_LENGTH, "la_");
|
||||||
//strcat_s(token, punch.activities[i].name);
|
//Utilities::strcat_safe(token, punch.activities[i].name);
|
||||||
//fpunchf_heading(sformatf("%*s\t", l, token));
|
//fpunchf_heading(sformatf("%*s\t", l, token));
|
||||||
//if (punch.activities[i].s == NULL)
|
//if (punch.activities[i].s == NULL)
|
||||||
//{
|
//{
|
||||||
@ -2066,8 +2066,8 @@ tidy_punch(void)
|
|||||||
" %s.", pair_ref.first.c_str());
|
" %s.", pair_ref.first.c_str());
|
||||||
warning_msg(error_string);
|
warning_msg(error_string);
|
||||||
}
|
}
|
||||||
// strcpy_s(token, MAX_LENGTH, "d_");
|
// Utilities::strcpy_safe(token, MAX_LENGTH, "d_");
|
||||||
//strcat_s(token, punch.pure_phases[i].name);
|
//Utilities::strcat_safe(token, punch.pure_phases[i].name);
|
||||||
//fpunchf_heading(sformatf("%*s\t", l, punch.pure_phases[i].name));
|
//fpunchf_heading(sformatf("%*s\t", l, punch.pure_phases[i].name));
|
||||||
//fpunchf_heading(sformatf("%*s\t", l, token));
|
//fpunchf_heading(sformatf("%*s\t", l, token));
|
||||||
//if (punch.pure_phases[i].phase == NULL)
|
//if (punch.pure_phases[i].phase == NULL)
|
||||||
@ -2093,8 +2093,8 @@ tidy_punch(void)
|
|||||||
" %s.", pair_ref.first.c_str());
|
" %s.", pair_ref.first.c_str());
|
||||||
warning_msg(error_string);
|
warning_msg(error_string);
|
||||||
}
|
}
|
||||||
// strcpy_s(token, MAX_LENGTH, "si_");
|
// Utilities::strcpy_safe(token, MAX_LENGTH, "si_");
|
||||||
//strcat_s(token, punch.si[i].name);
|
//Utilities::strcat_safe(token, punch.si[i].name);
|
||||||
//fpunchf_heading(sformatf("%*s\t", l, token));
|
//fpunchf_heading(sformatf("%*s\t", l, token));
|
||||||
//if (punch.si[i].phase == NULL)
|
//if (punch.si[i].phase == NULL)
|
||||||
//{
|
//{
|
||||||
@ -2126,8 +2126,8 @@ tidy_punch(void)
|
|||||||
" %s.", pair_ref.first.c_str());
|
" %s.", pair_ref.first.c_str());
|
||||||
warning_msg(error_string);
|
warning_msg(error_string);
|
||||||
}
|
}
|
||||||
// strcpy_s(token, MAX_LENGTH, "g_");
|
// Utilities::strcpy_safe(token, MAX_LENGTH, "g_");
|
||||||
//strcat_s(token, punch.gases[i].name);
|
//Utilities::strcat_safe(token, punch.gases[i].name);
|
||||||
//fpunchf_heading(sformatf("%*s\t", l, token));
|
//fpunchf_heading(sformatf("%*s\t", l, token));
|
||||||
//if (punch.gases[i].phase == NULL)
|
//if (punch.gases[i].phase == NULL)
|
||||||
//{
|
//{
|
||||||
@ -2149,11 +2149,11 @@ tidy_punch(void)
|
|||||||
name = "dk_";
|
name = "dk_";
|
||||||
name.append(pair_ref.first);
|
name.append(pair_ref.first);
|
||||||
fpunchf_heading(sformatf("%*s\t", l, name.c_str()));
|
fpunchf_heading(sformatf("%*s\t", l, name.c_str()));
|
||||||
// strcpy_s(token, MAX_LENGTH, "k_");
|
// Utilities::strcpy_safe(token, MAX_LENGTH, "k_");
|
||||||
//strcat_s(token, punch.kinetics[i].name);
|
//Utilities::strcat_safe(token, punch.kinetics[i].name);
|
||||||
//fpunchf_heading(sformatf("%*s\t", l, token));
|
//fpunchf_heading(sformatf("%*s\t", l, token));
|
||||||
// strcpy_s(token, MAX_LENGTH, "dk_");
|
// Utilities::strcpy_safe(token, MAX_LENGTH, "dk_");
|
||||||
//strcat_s(token, punch.kinetics[i].name);
|
//Utilities::strcat_safe(token, punch.kinetics[i].name);
|
||||||
//fpunchf_heading(sformatf("%*s\t", l, token));
|
//fpunchf_heading(sformatf("%*s\t", l, token));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2166,8 +2166,8 @@ tidy_punch(void)
|
|||||||
std::string name = "s_";
|
std::string name = "s_";
|
||||||
name.append(pair_ref.first);
|
name.append(pair_ref.first);
|
||||||
fpunchf_heading(sformatf("%*s\t", l, name.c_str()));
|
fpunchf_heading(sformatf("%*s\t", l, name.c_str()));
|
||||||
// strcpy_s(token, MAX_LENGTH, "s_");
|
// Utilities::strcpy_safe(token, MAX_LENGTH, "s_");
|
||||||
//strcat_s(token, punch.s_s[i].name);
|
//Utilities::strcat_safe(token, punch.s_s[i].name);
|
||||||
//fpunchf_heading(sformatf("%*s\t", l, token));
|
//fpunchf_heading(sformatf("%*s\t", l, token));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2196,8 +2196,8 @@ tidy_punch(void)
|
|||||||
// punch.isotopes[i].name, punch.isotopes[i].name);
|
// punch.isotopes[i].name, punch.isotopes[i].name);
|
||||||
// warning_msg(error_string);
|
// warning_msg(error_string);
|
||||||
//}
|
//}
|
||||||
// strcpy_s(token, MAX_LENGTH, "I_");
|
// Utilities::strcpy_safe(token, MAX_LENGTH, "I_");
|
||||||
//strcat_s(token, punch.isotopes[i].name);
|
//Utilities::strcat_safe(token, punch.isotopes[i].name);
|
||||||
//fpunchf_heading(sformatf("%*s\t", l, token));
|
//fpunchf_heading(sformatf("%*s\t", l, token));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2227,8 +2227,8 @@ tidy_punch(void)
|
|||||||
// punch.calculate_values[i].name);
|
// punch.calculate_values[i].name);
|
||||||
// warning_msg(error_string);
|
// warning_msg(error_string);
|
||||||
//}
|
//}
|
||||||
// strcpy_s(token, MAX_LENGTH, "V_");
|
// Utilities::strcpy_safe(token, MAX_LENGTH, "V_");
|
||||||
//strcat_s(token, punch.calculate_values[i].name);
|
//Utilities::strcat_safe(token, punch.calculate_values[i].name);
|
||||||
//fpunchf_heading(sformatf("%*s\t", l, token));
|
//fpunchf_heading(sformatf("%*s\t", l, token));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1784,7 +1784,7 @@ set_initial_moles(int i)
|
|||||||
cxxExchComp comp;
|
cxxExchComp comp;
|
||||||
count_elts = 0;
|
count_elts = 0;
|
||||||
paren_count = 0;
|
paren_count = 0;
|
||||||
strcpy_s(token, MAX_LENGTH, "X");
|
Utilities::strcpy_safe(token, MAX_LENGTH, "X");
|
||||||
cptr = token;
|
cptr = token;
|
||||||
get_elts_in_species(&cptr, 2e-10);
|
get_elts_in_species(&cptr, 2e-10);
|
||||||
cptr = token;
|
cptr = token;
|
||||||
|
|||||||
@ -233,7 +233,7 @@ compute_gfw(const char *string, LDBLE * gfw)
|
|||||||
|
|
||||||
count_elts = 0;
|
count_elts = 0;
|
||||||
paren_count = 0;
|
paren_count = 0;
|
||||||
strcpy_s(token, MAX_LENGTH, string);
|
Utilities::strcpy_safe(token, MAX_LENGTH, string);
|
||||||
cptr = token;
|
cptr = token;
|
||||||
if (get_elts_in_species(&cptr, 1.0) == ERROR)
|
if (get_elts_in_species(&cptr, 1.0) == ERROR)
|
||||||
{
|
{
|
||||||
@ -654,7 +654,7 @@ print_centered(const char *string)
|
|||||||
for (i = 0; i < l1; i++)
|
for (i = 0; i < l1; i++)
|
||||||
token[i] = '-';
|
token[i] = '-';
|
||||||
token[i] = '\0';
|
token[i] = '\0';
|
||||||
strcat_s(token, MAX_LENGTH, string);
|
Utilities::strcat_safe(token, MAX_LENGTH, string);
|
||||||
for (i = 0; i < l2; i++)
|
for (i = 0; i < l2; i++)
|
||||||
token[i + l1 + l] = '-';
|
token[i + l1 + l] = '-';
|
||||||
token[79] = '\0';
|
token[79] = '\0';
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user