Squashed 'phreeqcpp/' changes from 8715a91..feaa432

feaa432 [iphreeqc] Issue 8 -- change sprintf to snprintf for CRAN (#9)

git-subtree-dir: phreeqcpp
git-subtree-split: feaa4321a63ece0f205ce12795d6553261c74f7d
This commit is contained in:
Darth Vader 2023-01-15 06:04:23 +00:00
parent e0b04393ed
commit be9e230efb
16 changed files with 187 additions and 179 deletions

View File

@ -499,22 +499,22 @@ numtostr(char * Result, LDBLE n)
//if (PhreeqcPtr->current_selected_output != NULL &&
// !PhreeqcPtr->current_selected_output->Get_high_precision())
//{
// sprintf(l_s, "%12.0f", (double) n);
// snprintf(l_s, PhreeqcPtr->max_line, "%12.0f", (double) n);
//}
//else
//{
// sprintf(l_s, "%20.0f", (double) n);
// snprintf(l_s, PhreeqcPtr->max_line, "%20.0f", (double) n);
//}
bool temp_high_precision = (PhreeqcPtr->current_selected_output != NULL) ?
PhreeqcPtr->current_selected_output->Get_high_precision() :
PhreeqcPtr->high_precision;
if (!temp_high_precision)
{
sprintf(l_s, "%12.0f", (double) n);
snprintf(l_s, PhreeqcPtr->max_line, "%12.0f", (double) n);
}
else
{
sprintf(l_s, "%20.0f", (double) n);
snprintf(l_s, PhreeqcPtr->max_line, "%20.0f", (double) n);
}
}
else
@ -524,11 +524,11 @@ numtostr(char * Result, LDBLE n)
PhreeqcPtr->high_precision;
if (!temp_high_precision)
{
sprintf(l_s, "%12.4e", (double) n);
snprintf(l_s, PhreeqcPtr->max_line, "%12.4e", (double) n);
}
else
{
sprintf(l_s, "%20.12e", (double) n);
snprintf(l_s, PhreeqcPtr->max_line, "%20.12e", (double) n);
}
}
i = (int) strlen(l_s) + 1;
@ -539,8 +539,8 @@ numtostr(char * Result, LDBLE n)
PhreeqcPtr->free_check_null(l_s);
return (Result);
/* } else {
if (PhreeqcPtr->punch.high_precision == FALSE) sprintf(l_s, "%30.10f", n);
else sprintf(l_s, "%30.12f", n);
if (PhreeqcPtr->punch.high_precision == FALSE) snprintf(l_s, PhreeqcPtr->max_line, "%30.10f", n);
else snprintf(l_s, PhreeqcPtr->max_line, "%30.12f", n);
i = strlen(l_s) + 1;
do {
i--;
@ -612,6 +612,7 @@ parse(char * l_inbuf, tokenrec ** l_buf)
if (j + 1 > m)
m = j + 1;
t->UU.sp = (char *) PhreeqcPtr->PHRQ_calloc(m, sizeof(char));
t->sp_sz = m;
if (t->UU.sp == NULL)
{
PhreeqcPtr->malloc_error();
@ -739,6 +740,7 @@ parse(char * l_inbuf, tokenrec ** l_buf)
if (m < 256)
m = 256;
t->UU.sp = (char *) PhreeqcPtr->PHRQ_calloc(m, sizeof(char));
t->sp_sz = m;
if (t->UU.sp == NULL)
{
PhreeqcPtr->malloc_error();
@ -746,7 +748,7 @@ parse(char * l_inbuf, tokenrec ** l_buf)
exit(4);
#endif
}
sprintf(t->UU.sp, "%.*s",
snprintf(t->UU.sp, t->sp_sz, "%.*s",
(int) (strlen(l_inbuf) - i + 1),
l_inbuf + i - 1);
i = (int) strlen(l_inbuf) + 1;
@ -2232,7 +2234,7 @@ factor(struct LOC_exec * LINK)
{
if (PhreeqcPtr->use.Get_mix_in())
{
sprintf(string, "Mix %d", PhreeqcPtr->use.Get_n_mix_user());
snprintf(string, sizeof(string), "Mix %d", PhreeqcPtr->use.Get_n_mix_user());
n.UU.sval = PhreeqcPtr->string_duplicate(string);
}
else
@ -2251,7 +2253,7 @@ factor(struct LOC_exec * LINK)
}
else if (PhreeqcPtr->state == ADVECTION || PhreeqcPtr->state == TRANSPORT || PhreeqcPtr->state == PHAST)
{
sprintf(string, "Cell %d", PhreeqcPtr->cell_no);
snprintf(string, sizeof(string), "Cell %d", PhreeqcPtr->cell_no);
n.UU.sval = PhreeqcPtr->string_duplicate(string);
}
else
@ -3608,7 +3610,7 @@ factor(struct LOC_exec * LINK)
std::string std_num;
{
sprintf(token, "%*.*e", length, width, nmbr);
snprintf(token, sizeof(token), "%*.*e", length, width, nmbr);
std_num = token;
}
@ -3651,7 +3653,7 @@ factor(struct LOC_exec * LINK)
std::string std_num;
{
sprintf(token, "%*.*f", length, width, nmbr);
snprintf(token, sizeof(token), "%*.*f", length, width, nmbr);
std_num = token;
}
@ -4729,12 +4731,12 @@ cmdload(bool merging, char * name, struct LOC_exec *LINK)
cmdnew(LINK);
if (f != NULL)
{
sprintf(STR1, "%s.TEXT", name);
snprintf(STR1, sizeof(STR1), "%s.TEXT", name);
f = freopen(STR1, "r", f);
}
else
{
sprintf(STR1, "%s.TEXT", name);
snprintf(STR1, sizeof(STR1), "%s.TEXT", name);
f = fopen(STR1, "r");
}
if (f == NULL)
@ -7213,6 +7215,7 @@ _NilCheck(void)
return _Escape(-3);
}
#ifdef SKIP
/* The following is suitable for the HP Pascal operating system.
It might want to be revised when emulating another system. */
@ -7233,7 +7236,7 @@ _ShowEscape(char *buf, int code, int ior, char *prefix)
}
if (code == -10)
{
sprintf(bufp, "Pascal system I/O error %d", ior);
snprintf(bufp, sizeof(bufp), "Pascal system I/O error %d", ior); // FIXME -- replace sizeof
switch (ior)
{
case 3:
@ -7273,7 +7276,7 @@ _ShowEscape(char *buf, int code, int ior, char *prefix)
}
else
{
sprintf(bufp, "Pascal system error %d", code);
snprintf(bufp, sizeof(bufp), "Pascal system error %d", code); // FIXME -- replace sizeof
switch (code)
{
case -2:
@ -7307,7 +7310,7 @@ _ShowEscape(char *buf, int code, int ior, char *prefix)
}
return buf;
}
#endif
int PBasic::
_Escape(int code)
{

View File

@ -79,6 +79,7 @@ typedef struct tokenrec
//#ifdef PHREEQCI_GUI
size_t n_sz;
char *sz_num;
size_t sp_sz;
//#endif
} tokenrec;

View File

@ -136,7 +136,7 @@ fpunchf_user(int user_index, const char *format, double d)
warning_msg(error_string);
fpunchf_user_s_warning = 1;
}
sprintf(fpunchf_user_buffer, "no_heading_%d",
snprintf(fpunchf_user_buffer, sizeof(fpunchf_user_buffer), "no_heading_%d",
(user_index - user_punch_count_headings) + 1);
name = fpunchf_user_buffer;
}
@ -173,7 +173,7 @@ fpunchf_user(int user_index, const char *format, char * d)
warning_msg(error_string);
fpunchf_user_s_warning = 1;
}
sprintf(fpunchf_user_buffer, "no_heading_%d",
snprintf(fpunchf_user_buffer, sizeof(fpunchf_user_buffer), "no_heading_%d",
(user_index - user_punch_count_headings) + 1);
name = fpunchf_user_buffer;
}

View File

@ -481,7 +481,7 @@ public:
// parse.cpp -------------------------------
int check_eqn(int association);
int get_charge(char* charge, LDBLE* z);
int get_charge(char* charge, size_t charge_size, LDBLE* z);
int get_elt(const char** t_ptr, std::string& element, int* i);
int get_elts_in_species(const char** t_ptr, LDBLE coef);
int get_num(const char** t_ptr, LDBLE* num);

View File

@ -551,7 +551,7 @@ run_as_cells(void)
rate_sim_time = 0;
for (reaction_step = 1; reaction_step <= count_steps; reaction_step++)
{
sprintf(token, "Reaction step %d.", reaction_step);
snprintf(token, sizeof(token), "Reaction step %d.", reaction_step);
if (reaction_step > 1 && incremental_reactions == FALSE)
{
copy_use(-2);
@ -635,7 +635,7 @@ run_as_cells(void)
rate_sim_time = 0;
reaction_step = 1;
sprintf(token, "Reaction step %d.", reaction_step);
snprintf(token, sizeof(token), "Reaction step %d.", reaction_step);
dup_print(token, FALSE);
/*
@ -763,7 +763,7 @@ run_as_cells(void)
rate_sim_time = 0;
for (reaction_step = 1; reaction_step <= count_steps; reaction_step++)
{
sprintf(token, "Reaction step %d.", reaction_step);
snprintf(token, sizeof(token), "Reaction step %d.", reaction_step);
if (reaction_step > 1 && incremental_reactions == FALSE)
{
copy_use(-2);

View File

@ -2097,12 +2097,13 @@ match_elts_in_species(const char *name, const char *mytemplate)
* write out string
*/
token[0] = '\0';
assert(MAX_LENGTH == sizeof(token1));
for (i = 0; i < count_match_tokens; i++)
{
strcat(token, match_vector[i].first.c_str());
if (match_vector[i].second != 1.0)
{
sprintf(token1, "%g", (double) match_vector[i].second);
snprintf(token1, sizeof(token1), "%g", (double) match_vector[i].second);
strcat(token, token1);
}
}

View File

@ -1,3 +1,6 @@
#ifdef DOS
#include <windows.h>
#endif
#include "Phreeqc.h"
#include "NameDouble.h"
@ -296,9 +299,9 @@ write_banner(void)
/* version */
#ifdef NPP
len = sprintf(buffer, "* PHREEQC-%s *", "3.7.1");
len = snprintf(buffer, sizeof(buffer), "* PHREEQC-%s *", "3.7.1");
#else
len = sprintf(buffer, "* PHREEQC-%s *", "@VERSION@");
len = snprintf(buffer, sizeof(buffer), "* PHREEQC-%s *", "@VERSION@");
#endif
indent = (44 - len) / 2;
screen_msg(sformatf("%14c║%*c%s%*c║\n", ' ', indent, ' ', buffer,
@ -320,9 +323,9 @@ write_banner(void)
/* date */
#ifdef NPP
len = sprintf(buffer, "%s", "July 5, 2021");
len = snprintf(buffer, sizeof(buffer), "%s", "July 5, 2021");
#else
len = sprintf(buffer, "%s", "@VER_DATE@");
len = snprintf(buffer, sizeof(buffer), "%s", "@VER_DATE@");
#endif
indent = (44 - len) / 2;
screen_msg(sformatf("%14c║%*c%s%*c║\n", ' ', indent, ' ', buffer,

View File

@ -371,7 +371,7 @@ setup_inverse(class inverse *inv_ptr)
f = -1.0;
}
column = i;
sprintf(token, "soln %d", i);
snprintf(token, sizeof(token), "soln %d", i);
col_name[column] = string_hsave(token);
for (j = 0; j < (int)master.size(); j++)
{
@ -538,7 +538,7 @@ setup_inverse(class inverse *inv_ptr)
{
my_array[(size_t)row * max_column_count + (size_t)column] = 0.0;
}
sprintf(token, "%s %d", row_name[row], j);
snprintf(token, sizeof(token), "%s %d", row_name[row], j);
col_name[column] = string_hsave(token);
column++;
}
@ -549,13 +549,13 @@ setup_inverse(class inverse *inv_ptr)
for (i = 0; i < inv_ptr->count_solns; i++)
{
sprintf(token, "ph %d", i);
snprintf(token, sizeof(token), "ph %d", i);
col_name[column] = string_hsave(token);
column++;
}
/* put names in col_name for water */
sprintf(token, "water");
snprintf(token, sizeof(token), "water");
col_name[column] = string_hsave(token);
column++;
@ -564,7 +564,7 @@ setup_inverse(class inverse *inv_ptr)
{
for (j = 0; j < inv_ptr->isotope_unknowns.size(); j++)
{
sprintf(token, "%d%s %d",
snprintf(token, sizeof(token), "%d%s %d",
(int) inv_ptr->isotope_unknowns[j].isotope_number,
inv_ptr->isotope_unknowns[j].elt_name, i);
col_name[column] = string_hsave(token);
@ -581,7 +581,7 @@ setup_inverse(class inverse *inv_ptr)
{
for (j = 0; j < inv_ptr->isotopes.size(); j++)
{
sprintf(token, "%d%s %s",
snprintf(token, sizeof(token), "%d%s %s",
(int) inv_ptr->isotopes[j].isotope_number,
inv_ptr->isotopes[j].elt_name,
inv_ptr->phases[i].phase->name);
@ -649,7 +649,7 @@ setup_inverse(class inverse *inv_ptr)
my_array[count_rows * max_column_count + (size_t)column] = 0.0;
}
}
sprintf(token, "%s %d", "charge", i);
snprintf(token, sizeof(token), "%s %d", "charge", i);
row_name[count_rows] = string_hsave(token);
count_rows++;
}
@ -672,7 +672,7 @@ setup_inverse(class inverse *inv_ptr)
my_array[count_rows * max_column_count + (size_t)column] =
inv_ptr->dalk_dc[i];
}
sprintf(token, "%s %d", "dAlk", i);
snprintf(token, sizeof(token), "%s %d", "dAlk", i);
row_name[count_rows] = string_hsave(token);
count_rows++;
}
@ -688,7 +688,7 @@ setup_inverse(class inverse *inv_ptr)
for (size_t j = 0; j < inv_ptr->isotopes.size(); j++)
{
isotope_balance_equation(inv_ptr, (int)count_rows, (int)j);
sprintf(token, "%d%s", (int) inv_ptr->isotopes[j].isotope_number,
snprintf(token, sizeof(token), "%d%s", (int) inv_ptr->isotopes[j].isotope_number,
inv_ptr->isotopes[j].elt_name);
row_name[count_rows] = string_hsave(token);
count_rows++;
@ -761,7 +761,7 @@ setup_inverse(class inverse *inv_ptr)
}
my_array[count_rows * max_column_count + (size_t)column] = 1.0 * f;
my_array[count_rows * max_column_count + (size_t)i] = -coef * f;
sprintf(token, "%s %s", inv_ptr->elts[j].master->elt->name, "eps+");
snprintf(token, sizeof(token), "%s %s", inv_ptr->elts[j].master->elt->name, "eps+");
row_name[count_rows] = string_hsave(token);
count_rows++;
@ -795,7 +795,7 @@ setup_inverse(class inverse *inv_ptr)
my_array[count_rows * max_column_count + (size_t)i] = -coef * f;
my_array[count_rows * max_column_count + (size_t)column] = -1.0 * f;
sprintf(token, "%s %s", inv_ptr->elts[j].master->elt->name,
snprintf(token, sizeof(token), "%s %s", inv_ptr->elts[j].master->elt->name,
"eps-");
row_name[count_rows] = string_hsave(token);
count_rows++;
@ -821,7 +821,7 @@ setup_inverse(class inverse *inv_ptr)
my_array[count_rows * max_column_count + (size_t)column] = 1.0;
my_array[count_rows * max_column_count + (size_t)i] = -coef;
sprintf(token, "%s %s", "pH", "eps+");
snprintf(token, sizeof(token), "%s %s", "pH", "eps+");
row_name[count_rows] = string_hsave(token);
count_rows++;
@ -829,7 +829,7 @@ setup_inverse(class inverse *inv_ptr)
my_array[count_rows * max_column_count + (size_t)column] = -1.0;
my_array[count_rows * max_column_count + (size_t)i] = -coef;
sprintf(token, "%s %s", "pH", "eps-");
snprintf(token, sizeof(token), "%s %s", "pH", "eps-");
row_name[count_rows] = string_hsave(token);
count_rows++;
}
@ -845,7 +845,7 @@ setup_inverse(class inverse *inv_ptr)
/* set upper limit of change in positive direction */
my_array[count_rows * max_column_count + (size_t)column] = 1.0;
my_array[count_rows * max_column_count + count_unknowns] = coef;
sprintf(token, "%s %s", "water", "eps+");
snprintf(token, sizeof(token), "%s %s", "water", "eps+");
row_name[count_rows] = string_hsave(token);
count_rows++;
@ -853,7 +853,7 @@ setup_inverse(class inverse *inv_ptr)
my_array[count_rows * max_column_count + (size_t)column] = -1.0;
my_array[count_rows * max_column_count + count_unknowns] = coef;
sprintf(token, "%s %s", "water", "eps-");
snprintf(token, sizeof(token), "%s %s", "water", "eps-");
row_name[count_rows] = string_hsave(token);
count_rows++;
}
@ -890,7 +890,7 @@ setup_inverse(class inverse *inv_ptr)
/* set upper limit of change in positive direction */
my_array[count_rows * max_column_count + (size_t)column] = 1.0;
my_array[count_rows * max_column_count + (size_t)i] = -coef;
sprintf(token, "%d%s %s",
snprintf(token, sizeof(token), "%d%s %s",
(int) kit->second.Get_isotope_number(),
kit->second.Get_elt_name().c_str(), "eps+");
row_name[count_rows] = string_hsave(token);
@ -900,7 +900,7 @@ setup_inverse(class inverse *inv_ptr)
my_array[count_rows * max_column_count + (size_t)column] = -1.0;
my_array[count_rows * max_column_count + (size_t)i] = -coef;
sprintf(token, "%d%s %s",
snprintf(token, sizeof(token), "%d%s %s",
(int) kit->second.Get_isotope_number(),
kit->second.Get_elt_name().c_str(), "eps-");
row_name[count_rows] = string_hsave(token);
@ -1777,7 +1777,7 @@ print_model(class inverse *inv_ptr)
d2 = 0.0;
if (equal(d3, 0.0, MIN_TOTAL_INVERSE) == TRUE)
d3 = 0.0;
sprintf(token, "%d%s",
snprintf(token, sizeof(token), "%d%s",
(int) inv_ptr->isotope_unknowns[j].
isotope_number,
inv_ptr->isotope_unknowns[j].elt_name);
@ -1853,7 +1853,7 @@ print_model(class inverse *inv_ptr)
d2 = 0.0;
if (equal(d3, 0.0, 1e-7) == TRUE)
d3 = 0.0;
sprintf(token, "%d%s %s",
snprintf(token, sizeof(token), "%d%s %s",
(int) inv_ptr->isotopes[j].isotope_number,
inv_ptr->isotopes[j].elt_name,
inv_ptr->phases[i].phase->name);
@ -2060,7 +2060,7 @@ punch_model_heading(class inverse *inv_ptr)
*/
for (i = 0; i < inv_ptr->count_solns; i++)
{
sprintf(token, "Soln_%d", inv_ptr->solns[i]);
snprintf(token, sizeof(token), "Soln_%d", inv_ptr->solns[i]);
std::string tok1(token);
tok1.append("_min");
std::string tok2(token);
@ -3618,7 +3618,7 @@ check_isotopes(class inverse *inv_ptr)
}
else
{
sprintf(token, "%g%s",
snprintf(token, sizeof(token), "%g%s",
(double) kit->second.Get_isotope_number(),
kit->second.Get_elt_name().c_str());
for (l = 0; l < count_iso_defaults; l++)
@ -3764,7 +3764,7 @@ phase_isotope_inequalities(class inverse *inv_ptr)
my_array[count_rows * 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 + (size_t)column] = 1.0;
sprintf(token, "%s %s", inv_ptr->phases[i].phase->name,
snprintf(token, sizeof(token), "%s %s", inv_ptr->phases[i].phase->name,
"iso pos");
row_name[count_rows] = string_hsave(token);
count_rows++;
@ -3772,7 +3772,7 @@ phase_isotope_inequalities(class inverse *inv_ptr)
my_array[count_rows * 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 + (size_t)column] = -1.0;
sprintf(token, "%s %s", inv_ptr->phases[i].phase->name,
snprintf(token, sizeof(token), "%s %s", inv_ptr->phases[i].phase->name,
"iso neg");
row_name[count_rows] = string_hsave(token);
count_rows++;
@ -3784,7 +3784,7 @@ phase_isotope_inequalities(class inverse *inv_ptr)
my_array[count_rows * 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 + (size_t)column] = -1.0;
sprintf(token, "%s %s", inv_ptr->phases[i].phase->name,
snprintf(token, sizeof(token), "%s %s", inv_ptr->phases[i].phase->name,
"iso pos");
row_name[count_rows] = string_hsave(token);
count_rows++;
@ -3792,7 +3792,7 @@ phase_isotope_inequalities(class inverse *inv_ptr)
my_array[count_rows * 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 + (size_t)column] = 1.0;
sprintf(token, "%s %s", inv_ptr->phases[i].phase->name,
snprintf(token, sizeof(token), "%s %s", inv_ptr->phases[i].phase->name,
"iso neg");
row_name[count_rows] = string_hsave(token);
count_rows++;
@ -3829,7 +3829,7 @@ write_optimize_names(class inverse *inv_ptr)
{
for (i = 0; i < inv_ptr->count_solns; i++)
{
sprintf(token, "%s %s %d", "optimize",
snprintf(token, sizeof(token), "%s %s %d", "optimize",
inv_ptr->elts[j].master->elt->name, inv_ptr->solns[i]);
row_name[row] = string_hsave(token);
row++;
@ -3842,7 +3842,7 @@ write_optimize_names(class inverse *inv_ptr)
{
for (i = 0; i < inv_ptr->count_solns; i++)
{
sprintf(token, "%s %s %d", "optimize", "pH", inv_ptr->solns[i]);
snprintf(token, sizeof(token), "%s %s %d", "optimize", "pH", inv_ptr->solns[i]);
row_name[row] = string_hsave(token);
row++;
}
@ -3850,7 +3850,7 @@ write_optimize_names(class inverse *inv_ptr)
/*
* water
*/
sprintf(token, "%s %s", "optimize", "water");
snprintf(token, sizeof(token), "%s %s", "optimize", "water");
row_name[row] = string_hsave(token);
row++;
/*
@ -3860,7 +3860,7 @@ write_optimize_names(class inverse *inv_ptr)
{
for (j = 0; j < inv_ptr->isotope_unknowns.size(); j++)
{
sprintf(token, "%s %d%s %d", "optimize",
snprintf(token, sizeof(token), "%s %d%s %d", "optimize",
(int) inv_ptr->isotope_unknowns[j].isotope_number,
inv_ptr->isotope_unknowns[j].elt_name, inv_ptr->solns[i]);
row_name[row] = string_hsave(token);
@ -3875,7 +3875,7 @@ write_optimize_names(class inverse *inv_ptr)
{
for (j = 0; j < inv_ptr->isotopes.size(); j++)
{
sprintf(token, "%s %s %d%s", "optimize",
snprintf(token, sizeof(token), "%s %s %d%s", "optimize",
inv_ptr->phases[i].phase->name,
(int) inv_ptr->isotopes[j].isotope_number,
inv_ptr->isotopes[j].elt_name);

View File

@ -1075,7 +1075,7 @@ rk_kinetics(int i, LDBLE kin_time, int use_mix, int nsaver,
}
{
char str[MAX_LENGTH];
sprintf(str, "RK-steps: Bad%4d. OK%5d. Time %3d%%", step_bad,
snprintf(str, sizeof(str), "RK-steps: Bad%4d. OK%5d. Time %3d%%", step_bad,
step_ok, (int) (100 * h_sum / kin_time));
status(0, str, true);
}

View File

@ -381,7 +381,7 @@ initial_solutions(int print)
}
if (print == TRUE)
{
sprintf(token, "Initial solution %d.\t%.350s",
snprintf(token, sizeof(token), "Initial solution %d.\t%.350s",
solution_ref.Get_n_user(), solution_ref.Get_description().c_str());
dup_print(token, FALSE);
}
@ -518,7 +518,7 @@ initial_exchangers(int print)
}
if (print == TRUE)
{
sprintf(token, "Exchange %d.\t%.350s",
snprintf(token, sizeof(token), "Exchange %d.\t%.350s",
exchange_ptr->Get_n_user(), exchange_ptr->Get_description().c_str());
dup_print(token, FALSE);
}
@ -609,7 +609,7 @@ initial_gas_phases(int print)
}
if (print == TRUE)
{
sprintf(token, "Gas_Phase %d.\t%.350s",
snprintf(token, sizeof(token), "Gas_Phase %d.\t%.350s",
gas_phase_ptr->Get_n_user(), gas_phase_ptr->Get_description().c_str());
dup_print(token, FALSE);
}
@ -660,7 +660,7 @@ initial_gas_phases(int print)
}
if (fabs(gas_phase_ptr->Get_total_p() - use.Get_solution_ptr()->Get_patm()) > 5)
{
sprintf(token,
snprintf(token, sizeof(token),
"WARNING: While initializing gas phase composition by equilibrating:\n%s (%.2f atm) %s (%.2f atm).\n%s.",
" Gas phase pressure",
(double) gas_phase_ptr->Get_total_p(),
@ -828,7 +828,7 @@ reactions(void)
for (reaction_step = 1; reaction_step <= count_steps; reaction_step++)
{
overall_iterations = 0;
sprintf(token, "Reaction step %d.", reaction_step);
snprintf(token, sizeof(token), "Reaction step %d.", reaction_step);
if (reaction_step > 1 && incremental_reactions == FALSE)
{
copy_use(-2);
@ -934,7 +934,7 @@ saver(void)
if (save.solution == TRUE)
{
sprintf(token, "Solution after simulation %d.", simulation);
snprintf(token, sizeof(token), "Solution after simulation %d.", simulation);
description_x = token;
n = save.n_solution_user;
xsolution_save(n);
@ -1025,7 +1025,7 @@ xexchange_save(int n_user)
temp_exchange.Set_n_user(n_user);
temp_exchange.Set_n_user_end(n_user);
temp_exchange.Set_new_def(false);
sprintf(token, "Exchange assemblage after simulation %d.", simulation);
snprintf(token, sizeof(token), "Exchange assemblage after simulation %d.", simulation);
temp_exchange.Set_description(token);
temp_exchange.Set_solution_equilibria(false);
temp_exchange.Set_n_solution(-999);
@ -1108,7 +1108,7 @@ xgas_save(int n_user)
*/
temp_gas_phase.Set_n_user(n_user);
temp_gas_phase.Set_n_user_end(n_user);
sprintf(token, "Gas phase after simulation %d.", simulation);
snprintf(token, sizeof(token), "Gas phase after simulation %d.", simulation);
temp_gas_phase.Set_description(token);
temp_gas_phase.Set_new_def(false);
temp_gas_phase.Set_solution_equilibria(false);
@ -2094,10 +2094,10 @@ run_simulations(void)
#endif
#if defined PHREEQCI_GUI
sprintf(token, "\nSimulation %d\n", simulation);
snprintf(token, sizeof(token), "\nSimulation %d\n", simulation);
screen_msg(token);
#endif
sprintf(token, "Reading input data for simulation %d.", simulation);
snprintf(token, sizeof(token), "Reading input data for simulation %d.", simulation);
dup_print(token, TRUE);
if (read_input() == EOF)
@ -2105,7 +2105,7 @@ run_simulations(void)
if (title_x.size() > 0)
{
sprintf(token, "TITLE");
snprintf(token, sizeof(token), "TITLE");
dup_print(token, TRUE);
if (pr.headings == TRUE)
{

View File

@ -259,7 +259,7 @@ check_eqn(int association)
/* ---------------------------------------------------------------------- */
int Phreeqc::
get_charge(char *charge, LDBLE * l_z)
get_charge(char *charge, size_t charge_size, LDBLE * l_z)
/* ---------------------------------------------------------------------- */
/*
* Function takes character string and calculates the charge on
@ -367,7 +367,7 @@ get_charge(char *charge, LDBLE * l_z)
*/
if (abs(i) > 1)
{
if (sprintf(charge, "%-+d", i) == EOF)
if (snprintf(charge, charge_size, "%-+d", i) == EOF)
{
error_string = sformatf(
"Error converting charge to character string, %s.",

View File

@ -129,7 +129,7 @@ pitzer_tidy(void)
{
for (j = i + 1; j < count_cations; j++)
{
sprintf(line, "%s %s 1", spec[i]->name, spec[j]->name);
snprintf(line, max_line, "%s %s 1", spec[i]->name, spec[j]->name);
pzp_ptr = pitz_param_read(line, 2);
pzp_ptr->type = TYPE_ETHETA;
size_t count_pitz_param = pitz_params.size();
@ -141,7 +141,7 @@ pitzer_tidy(void)
{
for (j = i + 1; j < 2 * (int)s.size() + count_anions; j++)
{
sprintf(line, "%s %s 1", spec[i]->name, spec[j]->name);
snprintf(line, max_line, "%s %s 1", spec[i]->name, spec[j]->name);
pzp_ptr = pitz_param_read(line, 2);
pzp_ptr->type = TYPE_ETHETA;
size_t count_pitz_param = pitz_params.size();

View File

@ -590,7 +590,7 @@ print_gas_phase(void)
return (OK);
if (gas_unknown->moles < 1e-12)
{
sprintf(info, "Fixed-pressure gas phase %d dissolved completely",
snprintf(info, sizeof(info), "Fixed-pressure gas phase %d dissolved completely",
use.Get_n_gas_phase_user());
print_centered(info);
return (OK);
@ -1378,7 +1378,7 @@ print_pp_assemblage(void)
x[j]->moles = 0.0;
if (state != TRANSPORT && state != PHAST)
{
sprintf(token, " %11.3e %11.3e %11.3e",
snprintf(token, sizeof(token), " %11.3e %11.3e %11.3e",
(double) (comp_ptr->Get_moles() +
comp_ptr->Get_delta()), (double) x[j]->moles,
(double) (x[j]->moles - comp_ptr->Get_moles() -
@ -1386,7 +1386,7 @@ print_pp_assemblage(void)
}
else
{
sprintf(token, " %11.3e %11.3e %11.3e",
snprintf(token, sizeof(token), " %11.3e %11.3e %11.3e",
(double) comp_ptr->Get_initial_moles(),
(double) x[j]->moles,
(double) (x[j]->moles - comp_ptr->Get_initial_moles()));

View File

@ -749,21 +749,21 @@ read_transport(void)
{
if (max_cells == count_length)
{
sprintf(token,
snprintf(token, sizeof(token),
"Number of cells is increased to number of 'lengths' %d.",
count_length);
warning_msg(token);
}
else if (max_cells == count_disp)
{
sprintf(token,
snprintf(token, sizeof(token),
"Number of cells is increased to number of dispersivities %d.",
count_disp);
warning_msg(token);
}
else
{
sprintf(token,
snprintf(token, sizeof(token),
"Number of mobile cells is increased to (ceil)(number of porosities) / (1 + number of stagnant zones) = %d.",
(int) ceil(((double)count_por / (1 + (double)stag_data.count_stag))));
warning_msg(token);
@ -1222,26 +1222,26 @@ dump_cpp(void)
fs << "END" << "\n";
char token[MAX_LENGTH];
sprintf(token, "KNOBS\n");
snprintf(token, sizeof(token), "KNOBS\n");
fs << token;
sprintf(token, "\t-iter%15d\n", itmax);
snprintf(token, sizeof(token), "\t-iter%15d\n", itmax);
fs << token;
sprintf(token, "\t-tol %15.3e\n", (double)ineq_tol);
snprintf(token, sizeof(token), "\t-tol %15.3e\n", (double)ineq_tol);
fs << token;
sprintf(token, "\t-step%15.3e\n", (double)step_size);
snprintf(token, sizeof(token), "\t-step%15.3e\n", (double)step_size);
fs << token;
sprintf(token, "\t-pe_s%15.3e\n", (double)pe_step_size);
snprintf(token, sizeof(token), "\t-pe_s%15.3e\n", (double)pe_step_size);
fs << token;
sprintf(token, "\t-diag ");
snprintf(token, sizeof(token), "\t-diag ");
fs << token;
if (diagonal_scale == TRUE)
{
sprintf(token, "true\n");
snprintf(token, sizeof(token), "true\n");
fs << token;
}
else
{
sprintf(token, "false\n");
snprintf(token, sizeof(token), "false\n");
fs << token;
}
std::map < int, SelectedOutput >::iterator so_it = SelectedOutput_map.begin();
@ -1249,223 +1249,223 @@ dump_cpp(void)
{
current_selected_output = &(so_it->second);
sprintf(token, "SELECTED_OUTPUT %d\n", current_selected_output->Get_n_user());
snprintf(token, sizeof(token), "SELECTED_OUTPUT %d\n", current_selected_output->Get_n_user());
fs << token;
//sprintf(token, "\t-file %-15s\n", "sel_o$$$.prn");
//snprintf(token, sizeof(token), "\t-file %-15s\n", "sel_o$$$.prn");
//fs << token;
fs << "\t-file " << "sel_o$$$" << current_selected_output->Get_n_user() << ".prn\n";
//if (punch.count_totals != 0)
if (current_selected_output->Get_totals().size() > 0)
{
sprintf(token, "\t-tot ");
snprintf(token, sizeof(token), "\t-tot ");
fs << token;
for (size_t i = 0; i < current_selected_output->Get_totals().size(); i++)
{
sprintf(token, " %s", current_selected_output->Get_totals()[i].first.c_str());
snprintf(token, sizeof(token), " %s", current_selected_output->Get_totals()[i].first.c_str());
fs << token;
}
sprintf(token, "\n");
snprintf(token, sizeof(token), "\n");
fs << token;
}
if (current_selected_output->Get_molalities().size() > 0)
{
sprintf(token, "\t-mol ");
snprintf(token, sizeof(token), "\t-mol ");
fs << token;
for (size_t i = 0; i < current_selected_output->Get_molalities().size(); i++)
{
sprintf(token, " %s", current_selected_output->Get_molalities()[i].first.c_str());
snprintf(token, sizeof(token), " %s", current_selected_output->Get_molalities()[i].first.c_str());
fs << token;
}
sprintf(token, "\n");
snprintf(token, sizeof(token), "\n");
fs << token;
}
if (current_selected_output->Get_activities().size() > 0)
{
sprintf(token, "\t-act ");
snprintf(token, sizeof(token), "\t-act ");
fs << token;
for (size_t i = 0; i < current_selected_output->Get_activities().size(); i++)
{
sprintf(token, " %s", current_selected_output->Get_activities()[i].first.c_str());
snprintf(token, sizeof(token), " %s", current_selected_output->Get_activities()[i].first.c_str());
fs << token;
}
sprintf(token, "\n");
snprintf(token, sizeof(token), "\n");
fs << token;
}
if (current_selected_output->Get_pure_phases().size() > 0)
{
sprintf(token, "\t-equ ");
snprintf(token, sizeof(token), "\t-equ ");
fs << token;
for (size_t i = 0; i < current_selected_output->Get_pure_phases().size(); i++)
{
sprintf(token, " %s", current_selected_output->Get_pure_phases()[i].first.c_str());
snprintf(token, sizeof(token), " %s", current_selected_output->Get_pure_phases()[i].first.c_str());
fs << token;
}
sprintf(token, "\n");
snprintf(token, sizeof(token), "\n");
fs << token;
}
if (current_selected_output->Get_si().size() > 0)
{
sprintf(token, "\t-si ");
snprintf(token, sizeof(token), "\t-si ");
fs << token;
for (size_t i = 0; i < current_selected_output->Get_si().size(); i++)
{
sprintf(token, " %s", current_selected_output->Get_si()[i].first.c_str());
snprintf(token, sizeof(token), " %s", current_selected_output->Get_si()[i].first.c_str());
fs << token;
}
sprintf(token, "\n");
snprintf(token, sizeof(token), "\n");
fs << token;
}
if (current_selected_output->Get_gases().size() > 0)
{
sprintf(token, "\t-gas ");
snprintf(token, sizeof(token), "\t-gas ");
fs << token;
for (size_t i = 0; i < current_selected_output->Get_gases().size(); i++)
{
sprintf(token, " %s", current_selected_output->Get_gases()[i].first.c_str());
snprintf(token, sizeof(token), " %s", current_selected_output->Get_gases()[i].first.c_str());
fs << token;
}
sprintf(token, "\n");
snprintf(token, sizeof(token), "\n");
fs << token;
}
if (current_selected_output->Get_s_s().size() > 0)
{
sprintf(token, "\t-solid_solutions ");
snprintf(token, sizeof(token), "\t-solid_solutions ");
fs << token;
for (size_t i = 0; i < current_selected_output->Get_s_s().size(); i++)
{
sprintf(token, " %s", current_selected_output->Get_s_s()[i].first.c_str());
snprintf(token, sizeof(token), " %s", current_selected_output->Get_s_s()[i].first.c_str());
fs << token;
}
sprintf(token, "\n");
snprintf(token, sizeof(token), "\n");
fs << token;
}
if (current_selected_output->Get_kinetics().size() > 0)
{
sprintf(token, "\t-kin ");
snprintf(token, sizeof(token), "\t-kin ");
fs << token;
for (size_t i = 0; i < current_selected_output->Get_kinetics().size(); i++)
{
sprintf(token, " %s", current_selected_output->Get_kinetics()[i].first.c_str());
snprintf(token, sizeof(token), " %s", current_selected_output->Get_kinetics()[i].first.c_str());
fs << token;
}
sprintf(token, "\n");
snprintf(token, sizeof(token), "\n");
fs << token;
}
}
sprintf(token, "TRANSPORT\n");
snprintf(token, sizeof(token), "TRANSPORT\n");
fs << token;
sprintf(token, "\t-cells %6d\n", count_cells);
snprintf(token, sizeof(token), "\t-cells %6d\n", count_cells);
fs << token;
sprintf(token, "\t-shifts%6d%6d\n", count_shifts, ishift);
snprintf(token, sizeof(token), "\t-shifts%6d%6d\n", count_shifts, ishift);
fs << token;
sprintf(token, "\t-output_frequency %6d\n", print_modulus);
snprintf(token, sizeof(token), "\t-output_frequency %6d\n", print_modulus);
fs << token;
sprintf(token, "\t-selected_output_frequency %6d\n",
snprintf(token, sizeof(token), "\t-selected_output_frequency %6d\n",
punch_modulus);
fs << token;
sprintf(token, "\t-bcon %6d%6d\n", bcon_first, bcon_last);
snprintf(token, sizeof(token), "\t-bcon %6d%6d\n", bcon_first, bcon_last);
fs << token;
sprintf(token, "\t-timest %13.5e\n", (double)timest);
snprintf(token, sizeof(token), "\t-timest %13.5e\n", (double)timest);
fs << token;
if (!high_precision)
{
sprintf(token, "\t-diffc %13.5e\n", (double)diffc);
snprintf(token, sizeof(token), "\t-diffc %13.5e\n", (double)diffc);
fs << token;
}
else
{
sprintf(token, "\t-diffc %20.12e\n", (double)diffc);
snprintf(token, sizeof(token), "\t-diffc %20.12e\n", (double)diffc);
fs << token;
}
sprintf(token, "\t-tempr %13.5e\n", (double)tempr);
snprintf(token, sizeof(token), "\t-tempr %13.5e\n", (double)tempr);
fs << token;
if (correct_disp == TRUE)
{
sprintf(token, "\t-correct_disp %s\n", "True");
snprintf(token, sizeof(token), "\t-correct_disp %s\n", "True");
fs << token;
}
else
{
sprintf(token, "\t-correct_disp %s\n", "False");
snprintf(token, sizeof(token), "\t-correct_disp %s\n", "False");
fs << token;
}
sprintf(token, "\t-length\n");
snprintf(token, sizeof(token), "\t-length\n");
fs << token;
for (int i = 1; i <= count_cells; i++)
{
sprintf(token, "%12.3e", (double)cell_data[i].length);
snprintf(token, sizeof(token), "%12.3e", (double)cell_data[i].length);
fs << token;
if (i > 0 && (i % 8) == 0)
{
sprintf(token, "\n");
snprintf(token, sizeof(token), "\n");
fs << token;
}
}
sprintf(token, "\n");
snprintf(token, sizeof(token), "\n");
fs << token;
sprintf(token, "\t-disp\n");
snprintf(token, sizeof(token), "\t-disp\n");
fs << token;
for (int i = 1; i <= count_cells; i++)
{
if (!high_precision)
{
sprintf(token, "%12.3e", (double)cell_data[i].disp);
snprintf(token, sizeof(token), "%12.3e", (double)cell_data[i].disp);
fs << token;
}
else
{
sprintf(token, "%20.12e", (double)cell_data[i].disp);
snprintf(token, sizeof(token), "%20.12e", (double)cell_data[i].disp);
fs << token;
}
if (i > 0 && (i % 8) == 0)
{
sprintf(token, "\n");
snprintf(token, sizeof(token), "\n");
fs << token;
}
}
sprintf(token, "\n");
snprintf(token, sizeof(token), "\n");
fs << token;
sprintf(token, "\t-punch_cells");
snprintf(token, sizeof(token), "\t-punch_cells");
fs << token;
l = 0;
for (int i = 0; i < all_cells; i++)
{
if (cell_data[i].punch != TRUE)
continue;
sprintf(token, " %d", i);
snprintf(token, sizeof(token), " %d", i);
fs << token;
l++;
if ((l % 20) == 0)
{
sprintf(token, "\n");
snprintf(token, sizeof(token), "\n");
fs << token;
}
}
sprintf(token, "\n");
snprintf(token, sizeof(token), "\n");
fs << token;
sprintf(token, "\t-print_cells");
snprintf(token, sizeof(token), "\t-print_cells");
fs << token;
l = 0;
for (int i = 0; i < all_cells; i++)
{
if (cell_data[i].print != TRUE)
continue;
sprintf(token, " %d", i);
snprintf(token, sizeof(token), " %d", i);
fs << token;
l++;
if ((l % 20) == 0)
{
sprintf(token, "\n");
snprintf(token, sizeof(token), "\n");
fs << token;
}
}
sprintf(token, "\n");
snprintf(token, sizeof(token), "\n");
fs << token;
sprintf(token, "\t-dump $$$.dmp\n");
snprintf(token, sizeof(token), "\t-dump $$$.dmp\n");
fs << token;
sprintf(token, "\t-dump_frequency %d\n", dump_modulus);
snprintf(token, sizeof(token), "\t-dump_frequency %d\n", dump_modulus);
fs << token;
sprintf(token, "\t-dump_restart %d\n", transport_step + 1);
snprintf(token, sizeof(token), "\t-dump_restart %d\n", transport_step + 1);
fs << token;
#if defined MULTICHART
@ -1473,7 +1473,7 @@ dump_cpp(void)
chart_handler.dump(fs, 0);
#endif
sprintf(token, "END\n");
snprintf(token, sizeof(token), "END\n");
fs << token;
return (OK);
}

View File

@ -372,7 +372,7 @@ transport(void)
/* multi_D calc's are OK if all cells have the same amount of water */
if (multi_Dflag == TRUE)
{
sprintf(token, "multi_D calc's and stagnant: define MIXing factors explicitly, or \n\t give in -multi_D the Dw used for calculating the mobile-immobile exchange factor.");
snprintf(token, sizeof(token), "multi_D calc's and stagnant: define MIXing factors explicitly, or \n\t give in -multi_D the Dw used for calculating the mobile-immobile exchange factor.");
warning_msg(token);
}
@ -497,10 +497,10 @@ transport(void)
* Now transport
*/
if (implicit)
sprintf(token, "\nCalculating implicit transport: %d (mobile) cells, %d shifts, %d mixruns, max. mixf = %g.\n\n",
snprintf(token, sizeof(token), "\nCalculating implicit transport: %d (mobile) cells, %d shifts, %d mixruns, max. mixf = %g.\n\n",
count_cells, count_shifts - transport_start + 1, nmix, max_mixf);
else
sprintf(token, "\nCalculating transport: %d (mobile) cells, %d shifts, %d mixruns...\n\n",
snprintf(token, sizeof(token), "\nCalculating transport: %d (mobile) cells, %d shifts, %d mixruns...\n\n",
count_cells, count_shifts - transport_start + 1, nmix);
warning_msg(token);
max_iter = 0;
@ -544,14 +544,14 @@ transport(void)
mixrun = j;
if (multi_Dflag && j == floor((LDBLE)nmix / 2))
{
//sprintf(token,
//snprintf(token, sizeof(token),
// "Transport step %3d. Multicomponent diffusion run %3d.",
// transport_step, j);
//dup_print(token, FALSE);
}
else if (!multi_Dflag)
{
sprintf(token, "Transport step %3d. Mixrun %3d.",
snprintf(token, sizeof(token), "Transport step %3d. Mixrun %3d.",
transport_step, j);
dup_print(token, FALSE);
}
@ -595,11 +595,11 @@ transport(void)
max_iter = overall_iterations;
cell_no = i;
if (multi_Dflag)
sprintf(token,
snprintf(token, sizeof(token),
"Transport step %3d. MCDrun %3d. Cell %3d. (Max. iter %3d)",
transport_step, j, i, max_iter);
else
sprintf(token,
snprintf(token, sizeof(token),
"Transport step %3d. Mixrun %3d. Cell %3d. (Max. iter %3d)",
transport_step, j, i, max_iter);
status(0, token);
@ -665,7 +665,7 @@ transport(void)
*/
if (ishift != 0)
{
sprintf(token, "Transport step %3d.", transport_step);
snprintf(token, sizeof(token), "Transport step %3d.", transport_step);
dup_print(token, FALSE);
if (b_c == 1)
rate_sim_time_start = ((double)transport_step - 1) *
@ -758,11 +758,11 @@ transport(void)
kin_time /= 2;
cell_no = i;
if (multi_Dflag)
sprintf(token,
snprintf(token, sizeof(token),
"Transport step %3d. MCDrun %3d. Cell %3d. (Max. iter %3d)",
transport_step, 0, i, max_iter);
else
sprintf(token,
snprintf(token, sizeof(token),
"Transport step %3d. Mixrun %3d. Cell %3d. (Max. iter %3d)",
transport_step, 0, i, max_iter);
status(0, token);
@ -807,14 +807,14 @@ transport(void)
mixrun = j;
if (multi_Dflag && j == nmix && (transport_step % print_modulus == 0))
{
sprintf(token,
snprintf(token, sizeof(token),
"Transport step %3d. Multicomponent diffusion run %3d.",
transport_step, j);
dup_print(token, FALSE);
}
else if (!multi_Dflag)
{
sprintf(token, "Transport step %3d. Mixrun %3d.",
snprintf(token, sizeof(token), "Transport step %3d. Mixrun %3d.",
transport_step, j);
dup_print(token, FALSE);
}
@ -862,11 +862,11 @@ transport(void)
max_iter = overall_iterations;
cell_no = i;
if (multi_Dflag)
sprintf(token,
snprintf(token, sizeof(token),
"Transport step %3d. MCDrun %3d. Cell %3d. (Max. iter %3d)",
transport_step, j, i, max_iter);
else
sprintf(token,
snprintf(token, sizeof(token),
"Transport step %3d. Mixrun %3d. Cell %3d. (Max. iter %3d)",
transport_step, j, i, max_iter);
status(0, token);
@ -959,14 +959,14 @@ transport(void)
if (multi_Dflag && moles_added[0].moles > 0)
{
sprintf(token,
snprintf(token, sizeof(token),
"\nFor balancing negative concentrations in MCD, added in total to the system:");
warning_msg(token);
for (i = 0; i < count_moles_added; i++)
{
if (!moles_added[i].moles)
break;
sprintf(token,
snprintf(token, sizeof(token),
"\t %.4e moles %s.",
(double)moles_added[i].moles, moles_added[i].name);
warning_msg(token);
@ -1246,7 +1246,7 @@ init_mix(void)
m = (LDBLE *)free_check_null(m);
m1 = (LDBLE *)free_check_null(m1);
char token[MAX_LENGTH];
sprintf(token, "Calculated number of mixes %g, is beyond program limit,\nERROR: please set implicit true, or decrease time_step, or increase cell-lengths.", 2.25 * maxmix);
snprintf(token, sizeof(token), "Calculated number of mixes %g, is beyond program limit,\nERROR: please set implicit true, or decrease time_step, or increase cell-lengths.", 2.25 * maxmix);
error_msg(token, STOP);
}
if (bcon_first == 1 || bcon_last == 1)
@ -1367,7 +1367,7 @@ init_mix(void)
m = (LDBLE *)free_check_null(m);
m1 = (LDBLE *)free_check_null(m1);
char token[MAX_LENGTH];
sprintf(token, "Calculated number of mixes %g, is beyond program limit,\nERROR: please set implicit true, or decrease time_step, or increase cell-lengths.", 1.5 * maxmix);
snprintf(token, sizeof(token), "Calculated number of mixes %g, is beyond program limit,\nERROR: please set implicit true, or decrease time_step, or increase cell-lengths.", 1.5 * maxmix);
error_msg(token, STOP);
}
l_nmix = 1 + (int) floor(1.5 * maxmix);
@ -1950,7 +1950,7 @@ fill_spec(int l_cell_no, int ref_cell)
{
if (!warn_MCD_X)
{
sprintf(token,
snprintf(token, sizeof(token),
"MCD found more than 1 exchanger, uses X for interlayer diffusion.");
warning_msg(token);
warn_MCD_X = 1;
@ -3593,7 +3593,7 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant)
}
if (temp < -1e-12)
{
sprintf(token,
snprintf(token, sizeof(token),
"Negative concentration in MCD: added %.4e moles %s in cell %d",
(double)-temp, it->first.c_str(), i);
warning_msg(token);

View File

@ -567,7 +567,7 @@ get_token(const char** eqnaddr, std::string& string, LDBLE* l_z, int* l)
/*
* Charge has been written, now need to check if charge has legal format
*/
if (get_charge(charge, l_z) == OK)
if (get_charge(charge, MAX_LENGTH, l_z) == OK)
{
string.append(charge);
}
@ -1193,37 +1193,37 @@ status(int count, const char *str, bool rk_string)
{
stdstr = str;
}
sprintf(sim_str, "\rSimulation %d.", simulation);
sprintf(state_str, " ");
sprintf(spin_str, " ");
snprintf(sim_str, sizeof(sim_str), "\rSimulation %d.", simulation);
snprintf(state_str, sizeof(state_str), " ");
snprintf(spin_str, sizeof(spin_str), " ");
switch (state)
{
default:
break;
case INITIAL_SOLUTION:
sprintf(state_str, "Initial solution %d.", use.Get_solution_ptr()->Get_n_user());
snprintf(state_str, sizeof(state_str), "Initial solution %d.", use.Get_solution_ptr()->Get_n_user());
break;
case INITIAL_EXCHANGE:
sprintf(state_str, "Initial exchange %d.", use.Get_exchange_ptr()->Get_n_user());
snprintf(state_str, sizeof(state_str), "Initial exchange %d.", use.Get_exchange_ptr()->Get_n_user());
break;
case INITIAL_SURFACE:
sprintf(state_str, "Initial surface %d.", use.Get_surface_ptr()->Get_n_user());
snprintf(state_str, sizeof(state_str), "Initial surface %d.", use.Get_surface_ptr()->Get_n_user());
break;
case INVERSE:
sprintf(state_str, "Inverse %d. Models = %d.", use.Get_inverse_ptr()->n_user, count);
snprintf(state_str, sizeof(state_str), "Inverse %d. Models = %d.", use.Get_inverse_ptr()->n_user, count);
break;
case REACTION:
if (use.Get_kinetics_in() == TRUE)
{
sprintf(state_str, "Kinetic step %d.", reaction_step);
snprintf(state_str, sizeof(state_str), "Kinetic step %d.", reaction_step);
}
else
{
sprintf(state_str, "Reaction step %d.", reaction_step);
snprintf(state_str, sizeof(state_str), "Reaction step %d.", reaction_step);
}
break;
case ADVECTION:
sprintf(state_str, "Advection, shift %d.", advection_step);
snprintf(state_str, sizeof(state_str), "Advection, shift %d.", advection_step);
break;
}
spinner++;