Skip to content

Commit 60fced8

Browse files
authored
Merge pull request #47 from usgs-coupled/46-replace-sprintf-with-snprintf
2 parents ca7d0c5 + dcdec01 commit 60fced8

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/mainsubs.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ initial_solutions(int print)
381381
}
382382
if (print == TRUE)
383383
{
384-
sprintf(token, "Initial solution %d.\t%.350s",
384+
snprintf(token, sizeof(token), "Initial solution %d.\t%.350s",
385385
solution_ref.Get_n_user(), solution_ref.Get_description().c_str());
386386
dup_print(token, FALSE);
387387
}
@@ -521,7 +521,7 @@ initial_exchangers(int print)
521521
}
522522
if (print == TRUE)
523523
{
524-
sprintf(token, "Exchange %d.\t%.350s",
524+
snprintf(token, sizeof(token), "Exchange %d.\t%.350s",
525525
exchange_ptr->Get_n_user(), exchange_ptr->Get_description().c_str());
526526
dup_print(token, FALSE);
527527
}
@@ -613,7 +613,7 @@ initial_gas_phases(int print)
613613
}
614614
if (print == TRUE)
615615
{
616-
sprintf(token, "Gas_Phase %d.\t%.350s",
616+
snprintf(token, sizeof(token), "Gas_Phase %d.\t%.350s",
617617
gas_phase_ptr->Get_n_user(), gas_phase_ptr->Get_description().c_str());
618618
dup_print(token, FALSE);
619619
}
@@ -664,7 +664,7 @@ initial_gas_phases(int print)
664664
}
665665
if (fabs(gas_phase_ptr->Get_total_p() - use.Get_solution_ptr()->Get_patm()) > 5)
666666
{
667-
sprintf(token,
667+
snprintf(token, sizeof(token),
668668
"WARNING: While initializing gas phase composition by equilibrating:\n%s (%.2f atm) %s (%.2f atm).\n%s.",
669669
" Gas phase pressure",
670670
(double) gas_phase_ptr->Get_total_p(),
@@ -835,7 +835,7 @@ reactions(void)
835835
for (reaction_step = 1; reaction_step <= count_steps; reaction_step++)
836836
{
837837
overall_iterations = 0;
838-
sprintf(token, "Reaction step %d.", reaction_step);
838+
snprintf(token, sizeof(token), "Reaction step %d.", reaction_step);
839839
if (reaction_step > 1 && incremental_reactions == FALSE)
840840
{
841841
copy_use(-2);
@@ -941,7 +941,7 @@ saver(void)
941941

942942
if (save.solution == TRUE)
943943
{
944-
sprintf(token, "Solution after simulation %d.", simulation);
944+
snprintf(token, sizeof(token), "Solution after simulation %d.", simulation);
945945
description_x = token;
946946
n = save.n_solution_user;
947947
xsolution_save(n);
@@ -1032,7 +1032,7 @@ xexchange_save(int n_user)
10321032
temp_exchange.Set_n_user(n_user);
10331033
temp_exchange.Set_n_user_end(n_user);
10341034
temp_exchange.Set_new_def(false);
1035-
sprintf(token, "Exchange assemblage after simulation %d.", simulation);
1035+
snprintf(token, sizeof(token), "Exchange assemblage after simulation %d.", simulation);
10361036
temp_exchange.Set_description(token);
10371037
temp_exchange.Set_solution_equilibria(false);
10381038
temp_exchange.Set_n_solution(-999);
@@ -1115,7 +1115,7 @@ xgas_save(int n_user)
11151115
*/
11161116
temp_gas_phase.Set_n_user(n_user);
11171117
temp_gas_phase.Set_n_user_end(n_user);
1118-
sprintf(token, "Gas phase after simulation %d.", simulation);
1118+
snprintf(token, sizeof(token), "Gas phase after simulation %d.", simulation);
11191119
temp_gas_phase.Set_description(token);
11201120
temp_gas_phase.Set_new_def(false);
11211121
temp_gas_phase.Set_solution_equilibria(false);
@@ -2102,18 +2102,18 @@ run_simulations(void)
21022102
#endif
21032103

21042104
#if defined PHREEQCI_GUI
2105-
sprintf(token, "\nSimulation %d\n", simulation);
2105+
snprintf(token, sizeof(token), "\nSimulation %d\n", simulation);
21062106
screen_msg(token);
21072107
#endif
2108-
sprintf(token, "Reading input data for simulation %d.", simulation);
2108+
snprintf(token, sizeof(token), "Reading input data for simulation %d.", simulation);
21092109

21102110
dup_print(token, TRUE);
21112111
if (read_input() == EOF)
21122112
break;
21132113

21142114
if (title_x.size() > 0)
21152115
{
2116-
sprintf(token, "TITLE");
2116+
snprintf(token, sizeof(token), "TITLE");
21172117
dup_print(token, TRUE);
21182118
if (pr.headings == TRUE)
21192119
{

0 commit comments

Comments
 (0)