Skip to content

Commit

Permalink
Fix warnings about sprintf from Apple Clang
Browse files Browse the repository at this point in the history
Starting in macOS 13.2, the use of sprintf started generating
deprecation warnings, even though it's not deprecated by the C++ standard.
  • Loading branch information
speth committed Feb 25, 2023
1 parent 5810a2a commit 26fcb39
Showing 1 changed file with 31 additions and 25 deletions.
56 changes: 31 additions & 25 deletions src/equil/vcs_solve_TP.cpp
Expand Up @@ -20,6 +20,8 @@ using namespace std;
namespace {
enum stages {MAIN, EQUILIB_CHECK, ELEM_ABUND_CHECK,
RECHECK_DELETED, RETURN_A, RETURN_B};

const int anote_size = 128;
}

namespace Cantera
Expand Down Expand Up @@ -56,7 +58,7 @@ int VCS_SOLVE::vcs_solve_TP(int print_lvl, int printDetails, int maxit)
bool uptodate_minors = true;
int forceComponentCalc = 1;

char ANOTE[128];
char ANOTE[anote_size];
// Set the debug print lvl to the same as the print lvl.
m_debug_print_lvl = printDetails;
if (printDetails > 0 && print_lvl == 0) {
Expand Down Expand Up @@ -476,7 +478,7 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1,
if (iph == iphasePop) {
dx = m_deltaMolNumSpecies[kspec];
m_molNumSpecies_new[kspec] = m_molNumSpecies_old[kspec] + m_deltaMolNumSpecies[kspec];
sprintf(ANOTE, "Phase pop");
snprintf(ANOTE, anote_size, "Phase pop");
} else {
dx = 0.0;
m_molNumSpecies_new[kspec] = m_molNumSpecies_old[kspec];
Expand All @@ -500,15 +502,18 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1,
m_molNumSpecies_new[kspec] = m_molNumSpecies_old[kspec];
m_deltaMolNumSpecies[kspec] = 0.0;
resurrect = false;
sprintf(ANOTE, "Species stays zeroed: DG = %11.4E", m_deltaGRxn_new[irxn]);
snprintf(ANOTE, anote_size, "Species stays zeroed: DG = %11.4E",
m_deltaGRxn_new[irxn]);
if (m_deltaGRxn_new[irxn] < 0.0) {
if (m_speciesStatus[kspec] == VCS_SPECIES_STOICHZERO) {
sprintf(ANOTE, "Species stays zeroed even though dg neg due to "
"STOICH/PHASEPOP constraint: DG = %11.4E",
m_deltaGRxn_new[irxn]);
snprintf(ANOTE, anote_size,
"Species stays zeroed even though dg neg due to "
"STOICH/PHASEPOP constraint: DG = %11.4E",
m_deltaGRxn_new[irxn]);
} else {
sprintf(ANOTE, "Species stays zeroed even though dg neg: DG = %11.4E, ds zeroed",
m_deltaGRxn_new[irxn]);
snprintf(ANOTE, anote_size, "Species stays zeroed even"
" though dg neg: DG = %11.4E, ds zeroed",
m_deltaGRxn_new[irxn]);
}
}
} else {
Expand All @@ -519,9 +524,9 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1,
if (atomComp > 0.0) {
double maxPermissible = m_elemAbundancesGoal[j] / atomComp;
if (maxPermissible < VCS_DELETE_MINORSPECIES_CUTOFF) {
sprintf(ANOTE, "Species stays zeroed even though dG "
"neg, because of %s elemAbund",
m_elementName[j].c_str());
snprintf(ANOTE, anote_size, "Species stays zeroed"
" even though dG neg, because of %s elemAbund",
m_elementName[j].c_str());
resurrect = false;
break;
}
Expand Down Expand Up @@ -554,7 +559,8 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1,
dx = m_molNumSpecies_new[kspec] - m_molNumSpecies_old[kspec];
}
m_deltaMolNumSpecies[kspec] = dx;
sprintf(ANOTE, "Born:IC=-1 to IC=1:DG=%11.4E", m_deltaGRxn_new[irxn]);
snprintf(ANOTE, anote_size, "Born:IC=-1 to IC=1:DG=%11.4E",
m_deltaGRxn_new[irxn]);
} else {
m_molNumSpecies_new[kspec] = m_molNumSpecies_old[kspec];
m_deltaMolNumSpecies[kspec] = 0.0;
Expand All @@ -569,7 +575,7 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1,
m_molNumSpecies_new[kspec] = m_molNumSpecies_old[kspec];
m_deltaMolNumSpecies[kspec] = 0.0;
dx = 0.0;
sprintf(ANOTE,"minor species not considered");
snprintf(ANOTE, anote_size, "minor species not considered");
if (m_debug_print_lvl >= 2) {
plogf(" --- %-12s%3d% 11.4E %11.4E %11.4E | %s\n",
m_speciesName[kspec], m_speciesStatus[kspec], m_molNumSpecies_old[kspec], m_molNumSpecies_new[kspec],
Expand Down Expand Up @@ -623,7 +629,7 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1,
}
} else {
// MAJOR SPECIES
sprintf(ANOTE, "Normal Major Calc");
snprintf(ANOTE, anote_size, "Normal Major Calc");

// Check for superconvergence of the formation reaction. Do
// nothing if it is superconverged. Skip to the end of the irxn
Expand All @@ -632,7 +638,7 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1,
m_molNumSpecies_new[kspec] = m_molNumSpecies_old[kspec];
m_deltaMolNumSpecies[kspec] = 0.0;
dx = 0.0;
sprintf(ANOTE, "major species is converged");
snprintf(ANOTE, anote_size, "major species is converged");
if (m_debug_print_lvl >= 2) {
plogf(" --- %-12s %3d %11.4E %11.4E %11.4E | %s\n",
m_speciesName[kspec], m_speciesStatus[kspec], m_molNumSpecies_old[kspec], m_molNumSpecies_new[kspec],
Expand All @@ -653,8 +659,8 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1,
} else {
dx = 0.0;
m_deltaMolNumSpecies[kspec] = 0.0;
sprintf(ANOTE, "dx set to 0, DG flipped sign due to "
"changed initial point");
snprintf(ANOTE, anote_size, "dx set to 0, DG flipped sign due to "
"changed initial point");
}

//Form a tentative value of the new species moles
Expand All @@ -665,8 +671,8 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1,
// the outcome, we branch to sections below, or we restart the
// entire iteration.
if (m_molNumSpecies_new[kspec] <= 0.0) {
sprintf(ANOTE, "initial nonpos kmoles= %11.3E",
m_molNumSpecies_new[kspec]);
snprintf(ANOTE, anote_size, "initial nonpos kmoles= %11.3E",
m_molNumSpecies_new[kspec]);
// NON-POSITIVE MOLES OF MAJOR SPECIES
//
// We are here when a tentative value of a mole fraction
Expand Down Expand Up @@ -705,15 +711,15 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1,
m_molNumSpecies_new[kspec] = m_molNumSpecies_old[kspec] + dx;
if (m_molNumSpecies_new[kspec] > 0.0) {
m_deltaMolNumSpecies[kspec] = dx;
sprintf(ANOTE,
"zeroing SS phase created a neg component species "
"-> reducing step size instead");
snprintf(ANOTE, anote_size,
"zeroing SS phase created a neg component species "
"-> reducing step size instead");
} else {
// We are going to zero the single species phase.
// Set the existence flag
iph = m_phaseID[kspec];
Vphase = m_VolPhaseList[iph].get();
sprintf(ANOTE, "zeroing out SS phase: ");
snprintf(ANOTE, anote_size, "zeroing out SS phase: ");

// Change the base mole numbers for the iteration.
// We need to do this here, because we have decided
Expand Down Expand Up @@ -1365,7 +1371,7 @@ double VCS_SOLVE::vcs_minor_alt_calc(size_t kspec, size_t irxn, bool* do_delete,
}
dg_irxn = std::max(dg_irxn, -200.0);
if (ANOTE) {
sprintf(ANOTE,"minor species alternative calc");
snprintf(ANOTE, anote_size, "minor species alternative calc");
}
if (dg_irxn >= 23.0) {
double molNum_kspec_new = w_kspec * 1.0e-10;
Expand Down Expand Up @@ -1428,7 +1434,7 @@ double VCS_SOLVE::vcs_minor_alt_calc(size_t kspec, size_t irxn, bool* do_delete,
// Need to check the sign -> This is good for electrons
double dx = m_deltaGRxn_old[irxn]/ m_Faraday_dim;
if (ANOTE) {
sprintf(ANOTE,"voltage species alternative calc");
snprintf(ANOTE, anote_size, "voltage species alternative calc");
}
return dx;
}
Expand Down

0 comments on commit 26fcb39

Please sign in to comment.