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

This commit is contained in:
Charlton, Scott R 2023-01-14 22:14:20 -07:00 committed by GitHub
parent 190336d03b
commit 09619534e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 267 additions and 259 deletions

12
R/R.cpp
View File

@ -152,17 +152,17 @@ getCol(int ncol)
break; break;
case TT_LONG: case TT_LONG:
if (vv.u.lVal == -99) { if (vv.u.lVal == -99) {
sprintf(buffer, "NA"); snprintf(buffer, sizeof(buffer), "NA");
} else { } else {
sprintf(buffer, "%ld", vv.u.lVal); snprintf(buffer, sizeof(buffer), "%ld", vv.u.lVal);
} }
SET_STRING_ELT(ans, r-1, mkChar(buffer)); SET_STRING_ELT(ans, r-1, mkChar(buffer));
break; break;
case TT_DOUBLE: case TT_DOUBLE:
if (vv.u.dVal == -999.999 || vv.u.dVal == -99.) { if (vv.u.dVal == -999.999 || vv.u.dVal == -99.) {
sprintf(buffer, "NA"); snprintf(buffer, sizeof(buffer), "NA");
} else { } else {
sprintf(buffer, "%g", vv.u.dVal); snprintf(buffer, sizeof(buffer), "%g", vv.u.dVal);
} }
SET_STRING_ELT(ans, r-1, mkChar(buffer)); SET_STRING_ELT(ans, r-1, mkChar(buffer));
break; break;
@ -561,7 +561,7 @@ getSelectedOutputStringsLst(void)
int save = R::singleton().GetCurrentSelectedOutputUserNumber(); int save = R::singleton().GetCurrentSelectedOutputUserNumber();
for (int i = 0; i < n; ++i) { for (int i = 0; i < n; ++i) {
int d = R::singleton().GetNthSelectedOutputUserNumber(i); int d = R::singleton().GetNthSelectedOutputUserNumber(i);
::sprintf(buffer, "n%d", d); ::snprintf(buffer, sizeof(buffer), "n%d", d);
SET_STRING_ELT(attr, i, mkChar(buffer)); SET_STRING_ELT(attr, i, mkChar(buffer));
R::singleton().SetCurrentSelectedOutputUserNumber(d); R::singleton().SetCurrentSelectedOutputUserNumber(d);
PROTECT(so = getSelectedOutputStrings()); PROTECT(so = getSelectedOutputStrings());
@ -652,7 +652,7 @@ getSelOutLst(void)
int save = R::singleton().GetCurrentSelectedOutputUserNumber(); int save = R::singleton().GetCurrentSelectedOutputUserNumber();
for (int i = 0; i < n; ++i) { for (int i = 0; i < n; ++i) {
int d = R::singleton().GetNthSelectedOutputUserNumber(i); int d = R::singleton().GetNthSelectedOutputUserNumber(i);
::sprintf(buffer, "n%d", d); ::snprintf(buffer, sizeof(buffer), "n%d", d);
SET_STRING_ELT(attr, i, mkChar(buffer)); SET_STRING_ELT(attr, i, mkChar(buffer));
R::singleton().SetCurrentSelectedOutputUserNumber(d); R::singleton().SetCurrentSelectedOutputUserNumber(d);
PROTECT(so = getSelOut()); PROTECT(so = getSelOut());

View File

@ -28,7 +28,7 @@ int main(void)
for (i = 0; i < GetSelectedOutputCount(id); ++i) { for (i = 0; i < GetSelectedOutputCount(id); ++i) {
n = GetNthSelectedOutputUserNumber(id, i); n = GetNthSelectedOutputUserNumber(id, i);
sprintf(buffer, "sel_out.%d.out", n); snprintf(buffer, sizeof(buffer), "sel_out.%d.out", n);
if ((f = fopen(buffer, "w"))) { if ((f = fopen(buffer, "w"))) {
SetCurrentSelectedOutputUserNumber(id, n); SetCurrentSelectedOutputUserNumber(id, n);

View File

@ -23,7 +23,7 @@ void ExtractWrite(int cell)
switch (vt[j]) { switch (vt[j]) {
case TT_DOUBLE: case TT_DOUBLE:
dv[j] = v.dVal; dv[j] = v.dVal;
sprintf(sv[j], "%23.15e", v.dVal); snprintf(sv[j], sizeof(sv[j]), "%23.15e", v.dVal);
break; break;
case TT_STRING: case TT_STRING:
strcpy(sv[j], v.sVal); strcpy(sv[j], v.sVal);

View File

@ -19,7 +19,7 @@ bool FileExists(const char *szPathName)
if (fileHandle == INVALID_HANDLE_VALUE) if (fileHandle == INVALID_HANDLE_VALUE)
{ {
char buffer[100]; char buffer[100];
sprintf(buffer, "Could not open file (error %d)\n", GetLastError()); snprintf(buffer, sizeof(buffer), "Could not open file (error %d)\n", GetLastError());
retValue = false; retValue = false;
} }
else else

View File

@ -302,7 +302,7 @@ TEST(TestIPhreeqc, TestSetErrorOn2)
IPhreeqc obj; IPhreeqc obj;
char ERR_FILENAME[80]; char ERR_FILENAME[80];
sprintf(ERR_FILENAME, "error.%06d.out", ::rand()); snprintf(ERR_FILENAME, sizeof(ERR_FILENAME), "error.%06d.out", ::rand());
if (::FileExists(ERR_FILENAME)) if (::FileExists(ERR_FILENAME))
{ {
::DeleteFile(ERR_FILENAME); ::DeleteFile(ERR_FILENAME);
@ -331,7 +331,7 @@ TEST(TestIPhreeqc, TestSetErrorOnTakesPrecedence)
IPhreeqc obj; IPhreeqc obj;
char ERR_FILENAME[80]; char ERR_FILENAME[80];
sprintf(ERR_FILENAME, "error.%06d.out", ::rand()); snprintf(ERR_FILENAME, sizeof(ERR_FILENAME), "error.%06d.out", ::rand());
if (::FileExists(ERR_FILENAME)) if (::FileExists(ERR_FILENAME))
{ {
::DeleteFile(ERR_FILENAME); ::DeleteFile(ERR_FILENAME);
@ -604,8 +604,8 @@ TEST(TestIPhreeqc, TestRunString)
IPhreeqc obj; IPhreeqc obj;
char OUTPUT_FILE[80]; char OUTPUT_FILE[80];
//sprintf(OUTPUT_FILE, "phreeqc.%lu.out", (unsigned long)obj.GetId()); //snprintf(OUTPUT_FILE, sizeof(OUTPUT_FILE), "phreeqc.%lu.out", (unsigned long)obj.GetId());
sprintf(OUTPUT_FILE, "phreeqc.%lu.out", (unsigned long)obj.GetId()); snprintf(OUTPUT_FILE, sizeof(OUTPUT_FILE), "phreeqc.%lu.out", (unsigned long)obj.GetId());
FileTest ofile(OUTPUT_FILE); FileTest ofile(OUTPUT_FILE);
ASSERT_TRUE(ofile.RemoveExisting()); ASSERT_TRUE(ofile.RemoveExisting());
@ -1348,7 +1348,7 @@ TEST(TestIPhreeqc, TestCase1)
IPhreeqc obj; IPhreeqc obj;
char SELECTED_OUT[80]; char SELECTED_OUT[80];
sprintf(SELECTED_OUT, "selected_1.%lu.out", (unsigned long)obj.GetId()); snprintf(SELECTED_OUT, sizeof(SELECTED_OUT), "selected_1.%lu.out", (unsigned long)obj.GetId());
// remove punch file if it exists // remove punch file if it exists
FileTest sofile(SELECTED_OUT); FileTest sofile(SELECTED_OUT);
@ -1565,7 +1565,7 @@ void TestFileOnOff(const char* FILENAME_FORMAT, bool output_file_on, bool error_
IPhreeqc obj; IPhreeqc obj;
char FILENAME[80]; char FILENAME[80];
sprintf(FILENAME, FILENAME_FORMAT, obj.GetId()); snprintf(FILENAME, sizeof(FILENAME), FILENAME_FORMAT, obj.GetId());
// remove FILENAME if it exists // remove FILENAME if it exists
// //
@ -2085,7 +2085,7 @@ TEST(TestIPhreeqc, TestListComponents)
TEST(TestIPhreeqc, TestSetDumpFileName) TEST(TestIPhreeqc, TestSetDumpFileName)
{ {
char DUMP_FILENAME[80]; char DUMP_FILENAME[80];
sprintf(DUMP_FILENAME, "dump.%06d.out", ::rand()); snprintf(DUMP_FILENAME, sizeof(DUMP_FILENAME), "dump.%06d.out", ::rand());
if (::FileExists(DUMP_FILENAME)) if (::FileExists(DUMP_FILENAME))
{ {
::DeleteFile(DUMP_FILENAME); ::DeleteFile(DUMP_FILENAME);
@ -2167,7 +2167,7 @@ TEST(TestIPhreeqc, TestSetDumpFileName)
TEST(TestIPhreeqc, TestSetOutputFileName) TEST(TestIPhreeqc, TestSetOutputFileName)
{ {
char OUTPUT_FILENAME[80]; char OUTPUT_FILENAME[80];
sprintf(OUTPUT_FILENAME, "output.%06d.out", ::rand()); snprintf(OUTPUT_FILENAME, sizeof(OUTPUT_FILENAME), "output.%06d.out", ::rand());
if (::FileExists(OUTPUT_FILENAME)) if (::FileExists(OUTPUT_FILENAME))
{ {
::DeleteFile(OUTPUT_FILENAME); ::DeleteFile(OUTPUT_FILENAME);
@ -2346,7 +2346,7 @@ TEST(TestIPhreeqc, TestOutputStringOnOff)
TEST(TestIPhreeqc, TestGetOutputString) TEST(TestIPhreeqc, TestGetOutputString)
{ {
char OUTPUT_FILENAME[80]; char OUTPUT_FILENAME[80];
sprintf(OUTPUT_FILENAME, "output.%06d.out", ::rand()); snprintf(OUTPUT_FILENAME, sizeof(OUTPUT_FILENAME), "output.%06d.out", ::rand());
if (::FileExists(OUTPUT_FILENAME)) if (::FileExists(OUTPUT_FILENAME))
{ {
::DeleteFile(OUTPUT_FILENAME); ::DeleteFile(OUTPUT_FILENAME);
@ -2544,7 +2544,7 @@ TEST(TestIPhreeqc, TestGetOutputStringLine)
TEST(TestIPhreeqc, TestSetLogFileName) TEST(TestIPhreeqc, TestSetLogFileName)
{ {
char LOG_FILENAME[80]; char LOG_FILENAME[80];
sprintf(LOG_FILENAME, "log.%06d.out", ::rand()); snprintf(LOG_FILENAME, sizeof(LOG_FILENAME), "log.%06d.out", ::rand());
if (::FileExists(LOG_FILENAME)) if (::FileExists(LOG_FILENAME))
{ {
::DeleteFile(LOG_FILENAME); ::DeleteFile(LOG_FILENAME);
@ -2642,7 +2642,7 @@ TEST(TestIPhreeqc, TestLogStringOnOff)
TEST(TestIPhreeqc, TestGetLogString) TEST(TestIPhreeqc, TestGetLogString)
{ {
char LOG_FILENAME[80]; char LOG_FILENAME[80];
sprintf(LOG_FILENAME, "log.%06d.out", ::rand()); snprintf(LOG_FILENAME, sizeof(LOG_FILENAME), "log.%06d.out", ::rand());
if (::FileExists(LOG_FILENAME)) if (::FileExists(LOG_FILENAME))
{ {
::DeleteFile(LOG_FILENAME); ::DeleteFile(LOG_FILENAME);
@ -2888,7 +2888,7 @@ TEST(TestIPhreeqc, TestGetLogStringLine)
TEST(TestIPhreeqc, TestSetErrorFileName) TEST(TestIPhreeqc, TestSetErrorFileName)
{ {
char ERR_FILENAME[80]; char ERR_FILENAME[80];
sprintf(ERR_FILENAME, "error.%s.out", "TestIPhreeqc-TestSetErrorFileName"); snprintf(ERR_FILENAME, sizeof(ERR_FILENAME), "error.%s.out", "TestIPhreeqc-TestSetErrorFileName");
if (::FileExists(ERR_FILENAME)) if (::FileExists(ERR_FILENAME))
{ {
::DeleteFile(ERR_FILENAME); ::DeleteFile(ERR_FILENAME);
@ -2964,7 +2964,7 @@ TEST(TestIPhreeqc, TestErrorStringOnOff)
TEST(TestIPhreeqc, TestGetErrorString) TEST(TestIPhreeqc, TestGetErrorString)
{ {
char ERR_FILENAME[80]; char ERR_FILENAME[80];
sprintf(ERR_FILENAME, "error.%06d.out", ::rand()); snprintf(ERR_FILENAME, sizeof(ERR_FILENAME), "error.%06d.out", ::rand());
if (::FileExists(ERR_FILENAME)) if (::FileExists(ERR_FILENAME))
{ {
::DeleteFile(ERR_FILENAME); ::DeleteFile(ERR_FILENAME);
@ -3080,7 +3080,7 @@ TEST(TestIPhreeqc, TestGetErrorStringLineCount)
TEST(TestIPhreeqc, TestSetSelectedOutputFileName) TEST(TestIPhreeqc, TestSetSelectedOutputFileName)
{ {
char SELOUT_FILENAME[80]; char SELOUT_FILENAME[80];
sprintf(SELOUT_FILENAME, "selected_output.%06d.out", ::rand()); snprintf(SELOUT_FILENAME, sizeof(SELOUT_FILENAME), "selected_output.%06d.out", ::rand());
if (::FileExists(SELOUT_FILENAME)) if (::FileExists(SELOUT_FILENAME))
{ {
::DeleteFile(SELOUT_FILENAME); ::DeleteFile(SELOUT_FILENAME);
@ -3737,7 +3737,7 @@ TEST(TestIPhreeqc, TestDelete)
IPhreeqc obj; IPhreeqc obj;
char OUTPUT_FILE[80]; char OUTPUT_FILE[80];
sprintf(OUTPUT_FILE, "phreeqc.%lu.out", (unsigned long)obj.GetId()); snprintf(OUTPUT_FILE, sizeof(OUTPUT_FILE), "phreeqc.%lu.out", (unsigned long)obj.GetId());
if (::FileExists(OUTPUT_FILE)) if (::FileExists(OUTPUT_FILE))
{ {

View File

@ -434,7 +434,7 @@ TEST(TestIPhreeqcLib, TestRunString)
ASSERT_TRUE(n >= 0); ASSERT_TRUE(n >= 0);
char OUTPUT_FILE[80]; char OUTPUT_FILE[80];
sprintf(OUTPUT_FILE, "phreeqc.%d.out", n); snprintf(OUTPUT_FILE, sizeof(OUTPUT_FILE), "phreeqc.%d.out", n);
if (::FileExists(OUTPUT_FILE)) if (::FileExists(OUTPUT_FILE))
{ {
@ -1323,7 +1323,7 @@ TEST(TestIPhreeqcLib, TestCase1)
ASSERT_TRUE(n >= 0); ASSERT_TRUE(n >= 0);
char SELECTED_OUT[80]; char SELECTED_OUT[80];
sprintf(SELECTED_OUT, "selected_1.%d.out", n); snprintf(SELECTED_OUT, sizeof(SELECTED_OUT), "selected_1.%d.out", n);
// remove punch file if it exists // remove punch file if it exists
if (::FileExists(SELECTED_OUT)) if (::FileExists(SELECTED_OUT))
@ -1366,7 +1366,7 @@ TEST(TestIPhreeqcLib, TestCase2)
ASSERT_TRUE(n >= 0); ASSERT_TRUE(n >= 0);
char SELECTED_OUT[80]; char SELECTED_OUT[80];
sprintf(SELECTED_OUT, "selected_1.%d.out", n); snprintf(SELECTED_OUT, sizeof(SELECTED_OUT), "selected_1.%d.out", n);
// remove punch files if they exists // remove punch files if they exists
// //
@ -1543,7 +1543,7 @@ void TestFileOnOff(const char* FILENAME_FORMAT, int output_file_on, int error_fi
ASSERT_TRUE(n >= 0); ASSERT_TRUE(n >= 0);
char FILENAME[80]; char FILENAME[80];
sprintf(FILENAME, FILENAME_FORMAT, n); snprintf(FILENAME, sizeof(FILENAME), FILENAME_FORMAT, n);
// remove FILENAME if it exists // remove FILENAME if it exists
// //
@ -2081,7 +2081,7 @@ TEST(TestIPhreeqcLib, TestErrorFileOn)
ASSERT_TRUE(n >= 0); ASSERT_TRUE(n >= 0);
char FILENAME[80]; char FILENAME[80];
sprintf(FILENAME, "phreeqc.%d.err", n); snprintf(FILENAME, sizeof(FILENAME), "phreeqc.%d.err", n);
if (::FileExists(FILENAME)) if (::FileExists(FILENAME))
{ {
@ -2131,7 +2131,7 @@ TEST(TestIPhreeqcLib, TestLogFileOn)
ASSERT_TRUE(n >= 0); ASSERT_TRUE(n >= 0);
char FILENAME[80]; char FILENAME[80];
sprintf(FILENAME, "phreeqc.%d.log", n); snprintf(FILENAME, sizeof(FILENAME), "phreeqc.%d.log", n);
if (::FileExists(FILENAME)) if (::FileExists(FILENAME))
{ {
@ -2293,7 +2293,7 @@ TEST(TestIPhreeqcLib, TestClearAccumulatedLines)
TEST(TestIPhreeqcLib, TestSetDumpFileName) TEST(TestIPhreeqcLib, TestSetDumpFileName)
{ {
char DUMP_FILENAME[80]; char DUMP_FILENAME[80];
sprintf(DUMP_FILENAME, "dump.%06d.out", ::rand()); snprintf(DUMP_FILENAME, sizeof(DUMP_FILENAME), "dump.%06d.out", ::rand());
if (::FileExists(DUMP_FILENAME)) if (::FileExists(DUMP_FILENAME))
{ {
::DeleteFile(DUMP_FILENAME); ::DeleteFile(DUMP_FILENAME);
@ -2385,7 +2385,7 @@ TEST(TestIPhreeqcLib, TestSetDumpFileName)
TEST(TestIPhreeqcLib, TestSetOutputFileName) TEST(TestIPhreeqcLib, TestSetOutputFileName)
{ {
char OUTPUT_FILENAME[80]; char OUTPUT_FILENAME[80];
sprintf(OUTPUT_FILENAME, "output.%06d.out", ::rand()); snprintf(OUTPUT_FILENAME, sizeof(OUTPUT_FILENAME), "output.%06d.out", ::rand());
if (::FileExists(OUTPUT_FILENAME)) if (::FileExists(OUTPUT_FILENAME))
{ {
::DeleteFile(OUTPUT_FILENAME); ::DeleteFile(OUTPUT_FILENAME);
@ -2578,7 +2578,7 @@ TEST(TestIPhreeqcLib, TestGetOutputString)
ASSERT_TRUE(n >= 0); ASSERT_TRUE(n >= 0);
char OUTPUT_FILENAME[80]; char OUTPUT_FILENAME[80];
sprintf(OUTPUT_FILENAME, "output.%06d.out", ::rand()); snprintf(OUTPUT_FILENAME, sizeof(OUTPUT_FILENAME), "output.%06d.out", ::rand());
if (::FileExists(OUTPUT_FILENAME)) if (::FileExists(OUTPUT_FILENAME))
{ {
::DeleteFile(OUTPUT_FILENAME); ::DeleteFile(OUTPUT_FILENAME);
@ -2782,7 +2782,7 @@ TEST(TestIPhreeqcLib, TestGetOutputStringLine)
TEST(TestIPhreeqcLib, TestSetLogFileName) TEST(TestIPhreeqcLib, TestSetLogFileName)
{ {
char LOG_FILENAME[80]; char LOG_FILENAME[80];
sprintf(LOG_FILENAME, "log.%06d.out", ::rand()); snprintf(LOG_FILENAME, sizeof(LOG_FILENAME), "log.%06d.out", ::rand());
if (::FileExists(LOG_FILENAME)) if (::FileExists(LOG_FILENAME))
{ {
::DeleteFile(LOG_FILENAME); ::DeleteFile(LOG_FILENAME);
@ -2889,7 +2889,7 @@ TEST(TestIPhreeqcLib, TestLogStringOnOff)
TEST(TestIPhreeqcLib, TestGetLogString) TEST(TestIPhreeqcLib, TestGetLogString)
{ {
char LOG_FILENAME[80]; char LOG_FILENAME[80];
sprintf(LOG_FILENAME, "log.%06d.out", ::rand()); snprintf(LOG_FILENAME, sizeof(LOG_FILENAME), "log.%06d.out", ::rand());
if (::FileExists(LOG_FILENAME)) if (::FileExists(LOG_FILENAME))
{ {
::DeleteFile(LOG_FILENAME); ::DeleteFile(LOG_FILENAME);
@ -3159,7 +3159,7 @@ TEST(TestIPhreeqcLib, TestGetLogStringLine)
TEST(TestIPhreeqcLib, TestSetErrorFileName) TEST(TestIPhreeqcLib, TestSetErrorFileName)
{ {
char ERR_FILENAME[80]; char ERR_FILENAME[80];
sprintf(ERR_FILENAME, "error.%s.out", "TestIPhreeqcLib-TestSetErrorFileName"); snprintf(ERR_FILENAME, sizeof(ERR_FILENAME), "error.%s.out", "TestIPhreeqcLib-TestSetErrorFileName");
if (::FileExists(ERR_FILENAME)) if (::FileExists(ERR_FILENAME))
{ {
::DeleteFile(ERR_FILENAME); ::DeleteFile(ERR_FILENAME);
@ -3246,7 +3246,7 @@ TEST(TestIPhreeqcLib, TestErrorStringOnOff)
TEST(TestIPhreeqcLib, TestGetErrorString) TEST(TestIPhreeqcLib, TestGetErrorString)
{ {
char ERR_FILENAME[80]; char ERR_FILENAME[80];
sprintf(ERR_FILENAME, "error.%06d.out", ::rand()); snprintf(ERR_FILENAME, sizeof(ERR_FILENAME), "error.%06d.out", ::rand());
if (::FileExists(ERR_FILENAME)) if (::FileExists(ERR_FILENAME))
{ {
::DeleteFile(ERR_FILENAME); ::DeleteFile(ERR_FILENAME);
@ -3380,7 +3380,7 @@ TEST(TestIPhreeqcLib, TestGetErrorStringLineCount)
TEST(TestIPhreeqcLib, TestSetSelectedOutputFileName) TEST(TestIPhreeqcLib, TestSetSelectedOutputFileName)
{ {
char SELOUT_FILENAME[80]; char SELOUT_FILENAME[80];
sprintf(SELOUT_FILENAME, "selected_output.%06d.out", ::rand()); snprintf(SELOUT_FILENAME, sizeof(SELOUT_FILENAME), "selected_output.%06d.out", ::rand());
if (::FileExists(SELOUT_FILENAME)) if (::FileExists(SELOUT_FILENAME))
{ {
::DeleteFile(SELOUT_FILENAME); ::DeleteFile(SELOUT_FILENAME);
@ -4020,7 +4020,7 @@ TEST(TestIPhreeqcLib, TestDelete)
ASSERT_TRUE(n >= 0); ASSERT_TRUE(n >= 0);
char OUTPUT_FILE[80]; char OUTPUT_FILE[80];
sprintf(OUTPUT_FILE, "phreeqc.%d.out", n); snprintf(OUTPUT_FILE, sizeof(OUTPUT_FILE), "phreeqc.%d.out", n);
if (::FileExists(OUTPUT_FILE)) if (::FileExists(OUTPUT_FILE))
{ {

View File

@ -485,7 +485,7 @@ VRESULT IPhreeqc::GetSelectedOutputValue(int row, int col, VAR* pVAR)
{ {
char buffer[120]; char buffer[120];
v = VR_INVALIDARG; v = VR_INVALIDARG;
::sprintf(buffer, "GetSelectedOutputValue: VR_INVALIDARG Invalid selected-output user number %d.\n", this->CurrentSelectedOutputUserNumber); ::snprintf(buffer, sizeof(buffer), "GetSelectedOutputValue: VR_INVALIDARG Invalid selected-output user number %d.\n", this->CurrentSelectedOutputUserNumber);
this->AddError(buffer); this->AddError(buffer);
this->update_errors(); this->update_errors();
} }
@ -512,13 +512,13 @@ VRESULT IPhreeqc::GetSelectedOutputValue2(int row, int col, int *vtype, double*
case TT_LONG: case TT_LONG:
*vtype = TT_DOUBLE; *vtype = TT_DOUBLE;
*dvalue = (double)v.lVal; *dvalue = (double)v.lVal;
::sprintf(buffer, "%ld", v.lVal); ::snprintf(buffer, sizeof(buffer), "%ld", v.lVal);
::strncpy(svalue, buffer, svalue_length); ::strncpy(svalue, buffer, svalue_length);
break; break;
case TT_DOUBLE: case TT_DOUBLE:
*vtype = v.type; *vtype = v.type;
*dvalue = v.dVal; *dvalue = v.dVal;
::sprintf(buffer, "%23.15e", v.dVal); ::snprintf(buffer, sizeof(buffer), "%23.15e", v.dVal);
::strncpy(svalue, buffer, svalue_length); ::strncpy(svalue, buffer, svalue_length);
break; break;
case TT_STRING: case TT_STRING:
@ -1238,7 +1238,7 @@ void IPhreeqc::do_run(const char* sz_routine, std::istream* pis, PFN_PRERUN_CALL
#ifdef PHREEQ98 #ifdef PHREEQ98
AddSeries = !connect_simulations; AddSeries = !connect_simulations;
#endif #endif
::sprintf(token, "Reading input data for simulation %d.", this->PhreeqcPtr->simulation); ::snprintf(token, sizeof(token), "Reading input data for simulation %d.", this->PhreeqcPtr->simulation);
// bool save_punch_in = this->PhreeqcPtr->SelectedOutput_map.size() > 0; // bool save_punch_in = this->PhreeqcPtr->SelectedOutput_map.size() > 0;
@ -1270,7 +1270,7 @@ void IPhreeqc::do_run(const char* sz_routine, std::istream* pis, PFN_PRERUN_CALL
ASSERT(this->PhreeqcPtr->SelectedOutput_map.size() == this->SelectedOutputStringMap.size()); ASSERT(this->PhreeqcPtr->SelectedOutput_map.size() == this->SelectedOutputStringMap.size());
if (!this->PhreeqcPtr->title_x.empty()) if (!this->PhreeqcPtr->title_x.empty())
{ {
::sprintf(token, "TITLE"); ::snprintf(token, sizeof(token), "TITLE");
this->PhreeqcPtr->dup_print(token, TRUE); this->PhreeqcPtr->dup_print(token, TRUE);
if (this->PhreeqcPtr->pr.headings == TRUE) if (this->PhreeqcPtr->pr.headings == TRUE)
{ {

View File

@ -318,13 +318,13 @@ GetSelectedOutputValueF(int *id, int *row, int *col, int *vtype, double* dvalue,
case TT_LONG: case TT_LONG:
*vtype = TT_DOUBLE; *vtype = TT_DOUBLE;
*dvalue = (double)v.lVal; *dvalue = (double)v.lVal;
::sprintf(buffer, "%ld", v.lVal); ::snprintf(buffer, sizeof(buffer), "%ld", v.lVal);
padfstring(svalue, buffer, svalue_length); padfstring(svalue, buffer, svalue_length);
break; break;
case TT_DOUBLE: case TT_DOUBLE:
*vtype = v.type; *vtype = v.type;
*dvalue = v.dVal; *dvalue = v.dVal;
::sprintf(buffer, "%23.15e", v.dVal); ::snprintf(buffer, sizeof(buffer), "%23.15e", v.dVal);
padfstring(svalue, buffer, svalue_length); padfstring(svalue, buffer, svalue_length);
break; break;
case TT_STRING: case TT_STRING:

View File

@ -347,13 +347,13 @@ GetSelectedOutputValueF(int *id, int *row, int *col, int *vtype, double* dvalue,
case TT_LONG: case TT_LONG:
*vtype = TT_DOUBLE; *vtype = TT_DOUBLE;
*dvalue = (double)v.lVal; *dvalue = (double)v.lVal;
::sprintf(buffer, "%ld", v.lVal); ::snprintf(buffer, sizeof(buffer), "%ld", v.lVal);
padfstring(svalue, buffer, (unsigned int) svalue_length); padfstring(svalue, buffer, (unsigned int) svalue_length);
break; break;
case TT_DOUBLE: case TT_DOUBLE:
*vtype = v.type; *vtype = v.type;
*dvalue = v.dVal; *dvalue = v.dVal;
::sprintf(buffer, "%23.15e", v.dVal); ::snprintf(buffer, sizeof(buffer), "%23.15e", v.dVal);
padfstring(svalue, buffer, (unsigned int) svalue_length); padfstring(svalue, buffer, (unsigned int) svalue_length);
break; break;
case TT_STRING: case TT_STRING:

View File

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

View File

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

View File

@ -136,7 +136,7 @@ fpunchf_user(int user_index, const char *format, double d)
warning_msg(error_string); warning_msg(error_string);
fpunchf_user_s_warning = 1; 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); (user_index - user_punch_count_headings) + 1);
name = fpunchf_user_buffer; name = fpunchf_user_buffer;
} }
@ -173,7 +173,7 @@ fpunchf_user(int user_index, const char *format, char * d)
warning_msg(error_string); warning_msg(error_string);
fpunchf_user_s_warning = 1; 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); (user_index - user_punch_count_headings) + 1);
name = fpunchf_user_buffer; name = fpunchf_user_buffer;
} }

View File

@ -481,7 +481,7 @@ public:
// parse.cpp ------------------------------- // parse.cpp -------------------------------
int check_eqn(int association); 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_elt(const char** t_ptr, std::string& element, int* i);
int get_elts_in_species(const char** t_ptr, LDBLE coef); int get_elts_in_species(const char** t_ptr, LDBLE coef);
int get_num(const char** t_ptr, LDBLE* num); int get_num(const char** t_ptr, LDBLE* num);

View File

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

View File

@ -2097,12 +2097,13 @@ match_elts_in_species(const char *name, const char *mytemplate)
* write out string * write out string
*/ */
token[0] = '\0'; token[0] = '\0';
assert(MAX_LENGTH == sizeof(token1));
for (i = 0; i < count_match_tokens; i++) for (i = 0; i < count_match_tokens; i++)
{ {
strcat(token, match_vector[i].first.c_str()); strcat(token, match_vector[i].first.c_str());
if (match_vector[i].second != 1.0) 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); strcat(token, token1);
} }
} }

View File

@ -1,3 +1,6 @@
#ifdef DOS
#include <windows.h>
#endif
#include "Phreeqc.h" #include "Phreeqc.h"
#include "NameDouble.h" #include "NameDouble.h"
@ -296,9 +299,9 @@ write_banner(void)
/* version */ /* version */
#ifdef NPP #ifdef NPP
len = sprintf(buffer, "* PHREEQC-%s *", "3.7.1"); len = snprintf(buffer, sizeof(buffer), "* PHREEQC-%s *", "3.7.1");
#else #else
len = sprintf(buffer, "* PHREEQC-%s *", "@VERSION@"); len = snprintf(buffer, sizeof(buffer), "* PHREEQC-%s *", "@VERSION@");
#endif #endif
indent = (44 - len) / 2; indent = (44 - len) / 2;
screen_msg(sformatf("%14c║%*c%s%*c║\n", ' ', indent, ' ', buffer, screen_msg(sformatf("%14c║%*c%s%*c║\n", ' ', indent, ' ', buffer,
@ -320,9 +323,9 @@ write_banner(void)
/* date */ /* date */
#ifdef NPP #ifdef NPP
len = sprintf(buffer, "%s", "July 5, 2021"); len = snprintf(buffer, sizeof(buffer), "%s", "July 5, 2021");
#else #else
len = sprintf(buffer, "%s", "@VER_DATE@"); len = snprintf(buffer, sizeof(buffer), "%s", "@VER_DATE@");
#endif #endif
indent = (44 - len) / 2; indent = (44 - len) / 2;
screen_msg(sformatf("%14c║%*c%s%*c║\n", ' ', indent, ' ', buffer, 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; f = -1.0;
} }
column = i; column = i;
sprintf(token, "soln %d", i); snprintf(token, sizeof(token), "soln %d", i);
col_name[column] = string_hsave(token); col_name[column] = string_hsave(token);
for (j = 0; j < (int)master.size(); j++) 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; 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); col_name[column] = string_hsave(token);
column++; column++;
} }
@ -549,13 +549,13 @@ setup_inverse(class inverse *inv_ptr)
for (i = 0; i < inv_ptr->count_solns; i++) 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); col_name[column] = string_hsave(token);
column++; column++;
} }
/* put names in col_name for water */ /* put names in col_name for water */
sprintf(token, "water"); snprintf(token, sizeof(token), "water");
col_name[column] = string_hsave(token); col_name[column] = string_hsave(token);
column++; column++;
@ -564,7 +564,7 @@ setup_inverse(class inverse *inv_ptr)
{ {
for (j = 0; j < inv_ptr->isotope_unknowns.size(); j++) 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, (int) inv_ptr->isotope_unknowns[j].isotope_number,
inv_ptr->isotope_unknowns[j].elt_name, i); inv_ptr->isotope_unknowns[j].elt_name, i);
col_name[column] = string_hsave(token); 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++) 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, (int) inv_ptr->isotopes[j].isotope_number,
inv_ptr->isotopes[j].elt_name, inv_ptr->isotopes[j].elt_name,
inv_ptr->phases[i].phase->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; 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); row_name[count_rows] = string_hsave(token);
count_rows++; count_rows++;
} }
@ -672,7 +672,7 @@ setup_inverse(class inverse *inv_ptr)
my_array[count_rows * max_column_count + (size_t)column] = my_array[count_rows * max_column_count + (size_t)column] =
inv_ptr->dalk_dc[i]; 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); row_name[count_rows] = string_hsave(token);
count_rows++; count_rows++;
} }
@ -688,7 +688,7 @@ setup_inverse(class inverse *inv_ptr)
for (size_t j = 0; j < inv_ptr->isotopes.size(); j++) for (size_t j = 0; j < inv_ptr->isotopes.size(); j++)
{ {
isotope_balance_equation(inv_ptr, (int)count_rows, (int)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); inv_ptr->isotopes[j].elt_name);
row_name[count_rows] = string_hsave(token); row_name[count_rows] = string_hsave(token);
count_rows++; 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)column] = 1.0 * f;
my_array[count_rows * max_column_count + (size_t)i] = -coef * 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); row_name[count_rows] = string_hsave(token);
count_rows++; 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)i] = -coef * f;
my_array[count_rows * max_column_count + (size_t)column] = -1.0 * 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-"); "eps-");
row_name[count_rows] = string_hsave(token); row_name[count_rows] = string_hsave(token);
count_rows++; 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)column] = 1.0;
my_array[count_rows * max_column_count + (size_t)i] = -coef; 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); row_name[count_rows] = string_hsave(token);
count_rows++; 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)column] = -1.0;
my_array[count_rows * max_column_count + (size_t)i] = -coef; 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); row_name[count_rows] = string_hsave(token);
count_rows++; count_rows++;
} }
@ -845,7 +845,7 @@ setup_inverse(class inverse *inv_ptr)
/* set upper limit of change in positive direction */ /* 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)column] = 1.0;
my_array[count_rows * max_column_count + count_unknowns] = coef; 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); row_name[count_rows] = string_hsave(token);
count_rows++; 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 + (size_t)column] = -1.0;
my_array[count_rows * max_column_count + count_unknowns] = coef; 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); row_name[count_rows] = string_hsave(token);
count_rows++; count_rows++;
} }
@ -890,7 +890,7 @@ setup_inverse(class inverse *inv_ptr)
/* set upper limit of change in positive direction */ /* 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)column] = 1.0;
my_array[count_rows * max_column_count + (size_t)i] = -coef; 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(), (int) kit->second.Get_isotope_number(),
kit->second.Get_elt_name().c_str(), "eps+"); kit->second.Get_elt_name().c_str(), "eps+");
row_name[count_rows] = string_hsave(token); 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)column] = -1.0;
my_array[count_rows * max_column_count + (size_t)i] = -coef; 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(), (int) kit->second.Get_isotope_number(),
kit->second.Get_elt_name().c_str(), "eps-"); kit->second.Get_elt_name().c_str(), "eps-");
row_name[count_rows] = string_hsave(token); row_name[count_rows] = string_hsave(token);
@ -1777,7 +1777,7 @@ print_model(class inverse *inv_ptr)
d2 = 0.0; d2 = 0.0;
if (equal(d3, 0.0, MIN_TOTAL_INVERSE) == TRUE) if (equal(d3, 0.0, MIN_TOTAL_INVERSE) == TRUE)
d3 = 0.0; d3 = 0.0;
sprintf(token, "%d%s", snprintf(token, sizeof(token), "%d%s",
(int) inv_ptr->isotope_unknowns[j]. (int) inv_ptr->isotope_unknowns[j].
isotope_number, isotope_number,
inv_ptr->isotope_unknowns[j].elt_name); inv_ptr->isotope_unknowns[j].elt_name);
@ -1853,7 +1853,7 @@ print_model(class inverse *inv_ptr)
d2 = 0.0; d2 = 0.0;
if (equal(d3, 0.0, 1e-7) == TRUE) if (equal(d3, 0.0, 1e-7) == TRUE)
d3 = 0.0; d3 = 0.0;
sprintf(token, "%d%s %s", snprintf(token, sizeof(token), "%d%s %s",
(int) inv_ptr->isotopes[j].isotope_number, (int) inv_ptr->isotopes[j].isotope_number,
inv_ptr->isotopes[j].elt_name, inv_ptr->isotopes[j].elt_name,
inv_ptr->phases[i].phase->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++) 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); std::string tok1(token);
tok1.append("_min"); tok1.append("_min");
std::string tok2(token); std::string tok2(token);
@ -3618,7 +3618,7 @@ check_isotopes(class inverse *inv_ptr)
} }
else else
{ {
sprintf(token, "%g%s", snprintf(token, sizeof(token), "%g%s",
(double) kit->second.Get_isotope_number(), (double) kit->second.Get_isotope_number(),
kit->second.Get_elt_name().c_str()); kit->second.Get_elt_name().c_str());
for (l = 0; l < count_iso_defaults; l++) 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] = my_array[count_rows * max_column_count + (size_t)col_phases + (size_t)i] =
inv_ptr->phases[i].isotopes[j].ratio_uncertainty; inv_ptr->phases[i].isotopes[j].ratio_uncertainty;
my_array[count_rows * max_column_count + (size_t)column] = 1.0; 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"); "iso pos");
row_name[count_rows] = string_hsave(token); row_name[count_rows] = string_hsave(token);
count_rows++; 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] = my_array[count_rows * max_column_count + (size_t)col_phases + (size_t)i] =
inv_ptr->phases[i].isotopes[j].ratio_uncertainty; inv_ptr->phases[i].isotopes[j].ratio_uncertainty;
my_array[count_rows * max_column_count + (size_t)column] = -1.0; 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"); "iso neg");
row_name[count_rows] = string_hsave(token); row_name[count_rows] = string_hsave(token);
count_rows++; 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] = my_array[count_rows * max_column_count + (size_t)col_phases + (size_t)i] =
-inv_ptr->phases[i].isotopes[j].ratio_uncertainty; -inv_ptr->phases[i].isotopes[j].ratio_uncertainty;
my_array[count_rows * max_column_count + (size_t)column] = -1.0; 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"); "iso pos");
row_name[count_rows] = string_hsave(token); row_name[count_rows] = string_hsave(token);
count_rows++; 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] = my_array[count_rows * max_column_count + (size_t)col_phases + (size_t)i] =
-inv_ptr->phases[i].isotopes[j].ratio_uncertainty; -inv_ptr->phases[i].isotopes[j].ratio_uncertainty;
my_array[count_rows * max_column_count + (size_t)column] = 1.0; 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"); "iso neg");
row_name[count_rows] = string_hsave(token); row_name[count_rows] = string_hsave(token);
count_rows++; count_rows++;
@ -3829,7 +3829,7 @@ write_optimize_names(class inverse *inv_ptr)
{ {
for (i = 0; i < inv_ptr->count_solns; i++) 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]); inv_ptr->elts[j].master->elt->name, inv_ptr->solns[i]);
row_name[row] = string_hsave(token); row_name[row] = string_hsave(token);
row++; row++;
@ -3842,7 +3842,7 @@ write_optimize_names(class inverse *inv_ptr)
{ {
for (i = 0; i < inv_ptr->count_solns; i++) 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_name[row] = string_hsave(token);
row++; row++;
} }
@ -3850,7 +3850,7 @@ write_optimize_names(class inverse *inv_ptr)
/* /*
* water * water
*/ */
sprintf(token, "%s %s", "optimize", "water"); snprintf(token, sizeof(token), "%s %s", "optimize", "water");
row_name[row] = string_hsave(token); row_name[row] = string_hsave(token);
row++; row++;
/* /*
@ -3860,7 +3860,7 @@ write_optimize_names(class inverse *inv_ptr)
{ {
for (j = 0; j < inv_ptr->isotope_unknowns.size(); j++) 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, (int) inv_ptr->isotope_unknowns[j].isotope_number,
inv_ptr->isotope_unknowns[j].elt_name, inv_ptr->solns[i]); inv_ptr->isotope_unknowns[j].elt_name, inv_ptr->solns[i]);
row_name[row] = string_hsave(token); 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++) 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, inv_ptr->phases[i].phase->name,
(int) inv_ptr->isotopes[j].isotope_number, (int) inv_ptr->isotopes[j].isotope_number,
inv_ptr->isotopes[j].elt_name); 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]; 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)); step_ok, (int) (100 * h_sum / kin_time));
status(0, str, true); status(0, str, true);
} }

View File

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

View File

@ -259,7 +259,7 @@ check_eqn(int association)
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
int Phreeqc:: 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 * 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 (abs(i) > 1)
{ {
if (sprintf(charge, "%-+d", i) == EOF) if (snprintf(charge, charge_size, "%-+d", i) == EOF)
{ {
error_string = sformatf( error_string = sformatf(
"Error converting charge to character string, %s.", "Error converting charge to character string, %s.",

View File

@ -129,7 +129,7 @@ pitzer_tidy(void)
{ {
for (j = i + 1; j < count_cations; j++) 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 = pitz_param_read(line, 2);
pzp_ptr->type = TYPE_ETHETA; pzp_ptr->type = TYPE_ETHETA;
size_t count_pitz_param = pitz_params.size(); 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++) 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 = pitz_param_read(line, 2);
pzp_ptr->type = TYPE_ETHETA; pzp_ptr->type = TYPE_ETHETA;
size_t count_pitz_param = pitz_params.size(); size_t count_pitz_param = pitz_params.size();

View File

@ -590,7 +590,7 @@ print_gas_phase(void)
return (OK); return (OK);
if (gas_unknown->moles < 1e-12) 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()); use.Get_n_gas_phase_user());
print_centered(info); print_centered(info);
return (OK); return (OK);
@ -1378,7 +1378,7 @@ print_pp_assemblage(void)
x[j]->moles = 0.0; x[j]->moles = 0.0;
if (state != TRANSPORT && state != PHAST) 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() + (double) (comp_ptr->Get_moles() +
comp_ptr->Get_delta()), (double) x[j]->moles, comp_ptr->Get_delta()), (double) x[j]->moles,
(double) (x[j]->moles - comp_ptr->Get_moles() - (double) (x[j]->moles - comp_ptr->Get_moles() -
@ -1386,7 +1386,7 @@ print_pp_assemblage(void)
} }
else 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) comp_ptr->Get_initial_moles(),
(double) x[j]->moles, (double) x[j]->moles,
(double) (x[j]->moles - comp_ptr->Get_initial_moles())); (double) (x[j]->moles - comp_ptr->Get_initial_moles()));

View File

@ -749,21 +749,21 @@ read_transport(void)
{ {
if (max_cells == count_length) if (max_cells == count_length)
{ {
sprintf(token, snprintf(token, sizeof(token),
"Number of cells is increased to number of 'lengths' %d.", "Number of cells is increased to number of 'lengths' %d.",
count_length); count_length);
warning_msg(token); warning_msg(token);
} }
else if (max_cells == count_disp) else if (max_cells == count_disp)
{ {
sprintf(token, snprintf(token, sizeof(token),
"Number of cells is increased to number of dispersivities %d.", "Number of cells is increased to number of dispersivities %d.",
count_disp); count_disp);
warning_msg(token); warning_msg(token);
} }
else else
{ {
sprintf(token, snprintf(token, sizeof(token),
"Number of mobile cells is increased to (ceil)(number of porosities) / (1 + number of stagnant zones) = %d.", "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)))); (int) ceil(((double)count_por / (1 + (double)stag_data.count_stag))));
warning_msg(token); warning_msg(token);
@ -1222,26 +1222,26 @@ dump_cpp(void)
fs << "END" << "\n"; fs << "END" << "\n";
char token[MAX_LENGTH]; char token[MAX_LENGTH];
sprintf(token, "KNOBS\n"); snprintf(token, sizeof(token), "KNOBS\n");
fs << token; fs << token;
sprintf(token, "\t-iter%15d\n", itmax); snprintf(token, sizeof(token), "\t-iter%15d\n", itmax);
fs << token; 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; 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; 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; fs << token;
sprintf(token, "\t-diag "); snprintf(token, sizeof(token), "\t-diag ");
fs << token; fs << token;
if (diagonal_scale == TRUE) if (diagonal_scale == TRUE)
{ {
sprintf(token, "true\n"); snprintf(token, sizeof(token), "true\n");
fs << token; fs << token;
} }
else else
{ {
sprintf(token, "false\n"); snprintf(token, sizeof(token), "false\n");
fs << token; fs << token;
} }
std::map < int, SelectedOutput >::iterator so_it = SelectedOutput_map.begin(); std::map < int, SelectedOutput >::iterator so_it = SelectedOutput_map.begin();
@ -1249,223 +1249,223 @@ dump_cpp(void)
{ {
current_selected_output = &(so_it->second); 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; 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 << token;
fs << "\t-file " << "sel_o$$$" << current_selected_output->Get_n_user() << ".prn\n"; fs << "\t-file " << "sel_o$$$" << current_selected_output->Get_n_user() << ".prn\n";
//if (punch.count_totals != 0) //if (punch.count_totals != 0)
if (current_selected_output->Get_totals().size() > 0) if (current_selected_output->Get_totals().size() > 0)
{ {
sprintf(token, "\t-tot "); snprintf(token, sizeof(token), "\t-tot ");
fs << token; fs << token;
for (size_t i = 0; i < current_selected_output->Get_totals().size(); i++) 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; fs << token;
} }
sprintf(token, "\n"); snprintf(token, sizeof(token), "\n");
fs << token; fs << token;
} }
if (current_selected_output->Get_molalities().size() > 0) if (current_selected_output->Get_molalities().size() > 0)
{ {
sprintf(token, "\t-mol "); snprintf(token, sizeof(token), "\t-mol ");
fs << token; fs << token;
for (size_t i = 0; i < current_selected_output->Get_molalities().size(); i++) 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; fs << token;
} }
sprintf(token, "\n"); snprintf(token, sizeof(token), "\n");
fs << token; fs << token;
} }
if (current_selected_output->Get_activities().size() > 0) if (current_selected_output->Get_activities().size() > 0)
{ {
sprintf(token, "\t-act "); snprintf(token, sizeof(token), "\t-act ");
fs << token; fs << token;
for (size_t i = 0; i < current_selected_output->Get_activities().size(); i++) 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; fs << token;
} }
sprintf(token, "\n"); snprintf(token, sizeof(token), "\n");
fs << token; fs << token;
} }
if (current_selected_output->Get_pure_phases().size() > 0) if (current_selected_output->Get_pure_phases().size() > 0)
{ {
sprintf(token, "\t-equ "); snprintf(token, sizeof(token), "\t-equ ");
fs << token; fs << token;
for (size_t i = 0; i < current_selected_output->Get_pure_phases().size(); i++) 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; fs << token;
} }
sprintf(token, "\n"); snprintf(token, sizeof(token), "\n");
fs << token; fs << token;
} }
if (current_selected_output->Get_si().size() > 0) if (current_selected_output->Get_si().size() > 0)
{ {
sprintf(token, "\t-si "); snprintf(token, sizeof(token), "\t-si ");
fs << token; fs << token;
for (size_t i = 0; i < current_selected_output->Get_si().size(); i++) 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; fs << token;
} }
sprintf(token, "\n"); snprintf(token, sizeof(token), "\n");
fs << token; fs << token;
} }
if (current_selected_output->Get_gases().size() > 0) if (current_selected_output->Get_gases().size() > 0)
{ {
sprintf(token, "\t-gas "); snprintf(token, sizeof(token), "\t-gas ");
fs << token; fs << token;
for (size_t i = 0; i < current_selected_output->Get_gases().size(); i++) 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; fs << token;
} }
sprintf(token, "\n"); snprintf(token, sizeof(token), "\n");
fs << token; fs << token;
} }
if (current_selected_output->Get_s_s().size() > 0) if (current_selected_output->Get_s_s().size() > 0)
{ {
sprintf(token, "\t-solid_solutions "); snprintf(token, sizeof(token), "\t-solid_solutions ");
fs << token; fs << token;
for (size_t i = 0; i < current_selected_output->Get_s_s().size(); i++) 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; fs << token;
} }
sprintf(token, "\n"); snprintf(token, sizeof(token), "\n");
fs << token; fs << token;
} }
if (current_selected_output->Get_kinetics().size() > 0) if (current_selected_output->Get_kinetics().size() > 0)
{ {
sprintf(token, "\t-kin "); snprintf(token, sizeof(token), "\t-kin ");
fs << token; fs << token;
for (size_t i = 0; i < current_selected_output->Get_kinetics().size(); i++) 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; fs << token;
} }
sprintf(token, "\n"); snprintf(token, sizeof(token), "\n");
fs << token; fs << token;
} }
} }
sprintf(token, "TRANSPORT\n"); snprintf(token, sizeof(token), "TRANSPORT\n");
fs << token; fs << token;
sprintf(token, "\t-cells %6d\n", count_cells); snprintf(token, sizeof(token), "\t-cells %6d\n", count_cells);
fs << token; 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; fs << token;
sprintf(token, "\t-output_frequency %6d\n", print_modulus); snprintf(token, sizeof(token), "\t-output_frequency %6d\n", print_modulus);
fs << token; fs << token;
sprintf(token, "\t-selected_output_frequency %6d\n", snprintf(token, sizeof(token), "\t-selected_output_frequency %6d\n",
punch_modulus); punch_modulus);
fs << token; 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; fs << token;
sprintf(token, "\t-timest %13.5e\n", (double)timest); snprintf(token, sizeof(token), "\t-timest %13.5e\n", (double)timest);
fs << token; fs << token;
if (!high_precision) 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; fs << token;
} }
else else
{ {
sprintf(token, "\t-diffc %20.12e\n", (double)diffc); snprintf(token, sizeof(token), "\t-diffc %20.12e\n", (double)diffc);
fs << token; fs << token;
} }
sprintf(token, "\t-tempr %13.5e\n", (double)tempr); snprintf(token, sizeof(token), "\t-tempr %13.5e\n", (double)tempr);
fs << token; fs << token;
if (correct_disp == TRUE) if (correct_disp == TRUE)
{ {
sprintf(token, "\t-correct_disp %s\n", "True"); snprintf(token, sizeof(token), "\t-correct_disp %s\n", "True");
fs << token; fs << token;
} }
else else
{ {
sprintf(token, "\t-correct_disp %s\n", "False"); snprintf(token, sizeof(token), "\t-correct_disp %s\n", "False");
fs << token; fs << token;
} }
sprintf(token, "\t-length\n"); snprintf(token, sizeof(token), "\t-length\n");
fs << token; fs << token;
for (int i = 1; i <= count_cells; i++) 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; fs << token;
if (i > 0 && (i % 8) == 0) if (i > 0 && (i % 8) == 0)
{ {
sprintf(token, "\n"); snprintf(token, sizeof(token), "\n");
fs << token; fs << token;
} }
} }
sprintf(token, "\n"); snprintf(token, sizeof(token), "\n");
fs << token; fs << token;
sprintf(token, "\t-disp\n"); snprintf(token, sizeof(token), "\t-disp\n");
fs << token; fs << token;
for (int i = 1; i <= count_cells; i++) for (int i = 1; i <= count_cells; i++)
{ {
if (!high_precision) 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; fs << token;
} }
else else
{ {
sprintf(token, "%20.12e", (double)cell_data[i].disp); snprintf(token, sizeof(token), "%20.12e", (double)cell_data[i].disp);
fs << token; fs << token;
} }
if (i > 0 && (i % 8) == 0) if (i > 0 && (i % 8) == 0)
{ {
sprintf(token, "\n"); snprintf(token, sizeof(token), "\n");
fs << token; fs << token;
} }
} }
sprintf(token, "\n"); snprintf(token, sizeof(token), "\n");
fs << token; fs << token;
sprintf(token, "\t-punch_cells"); snprintf(token, sizeof(token), "\t-punch_cells");
fs << token; fs << token;
l = 0; l = 0;
for (int i = 0; i < all_cells; i++) for (int i = 0; i < all_cells; i++)
{ {
if (cell_data[i].punch != TRUE) if (cell_data[i].punch != TRUE)
continue; continue;
sprintf(token, " %d", i); snprintf(token, sizeof(token), " %d", i);
fs << token; fs << token;
l++; l++;
if ((l % 20) == 0) if ((l % 20) == 0)
{ {
sprintf(token, "\n"); snprintf(token, sizeof(token), "\n");
fs << token; fs << token;
} }
} }
sprintf(token, "\n"); snprintf(token, sizeof(token), "\n");
fs << token; fs << token;
sprintf(token, "\t-print_cells"); snprintf(token, sizeof(token), "\t-print_cells");
fs << token; fs << token;
l = 0; l = 0;
for (int i = 0; i < all_cells; i++) for (int i = 0; i < all_cells; i++)
{ {
if (cell_data[i].print != TRUE) if (cell_data[i].print != TRUE)
continue; continue;
sprintf(token, " %d", i); snprintf(token, sizeof(token), " %d", i);
fs << token; fs << token;
l++; l++;
if ((l % 20) == 0) if ((l % 20) == 0)
{ {
sprintf(token, "\n"); snprintf(token, sizeof(token), "\n");
fs << token; fs << token;
} }
} }
sprintf(token, "\n"); snprintf(token, sizeof(token), "\n");
fs << token; fs << token;
sprintf(token, "\t-dump $$$.dmp\n"); snprintf(token, sizeof(token), "\t-dump $$$.dmp\n");
fs << token; fs << token;
sprintf(token, "\t-dump_frequency %d\n", dump_modulus); snprintf(token, sizeof(token), "\t-dump_frequency %d\n", dump_modulus);
fs << token; 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; fs << token;
#if defined MULTICHART #if defined MULTICHART
@ -1473,7 +1473,7 @@ dump_cpp(void)
chart_handler.dump(fs, 0); chart_handler.dump(fs, 0);
#endif #endif
sprintf(token, "END\n"); snprintf(token, sizeof(token), "END\n");
fs << token; fs << token;
return (OK); 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 */ /* multi_D calc's are OK if all cells have the same amount of water */
if (multi_Dflag == TRUE) 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); warning_msg(token);
} }
@ -497,10 +497,10 @@ transport(void)
* Now transport * Now transport
*/ */
if (implicit) 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); count_cells, count_shifts - transport_start + 1, nmix, max_mixf);
else 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); count_cells, count_shifts - transport_start + 1, nmix);
warning_msg(token); warning_msg(token);
max_iter = 0; max_iter = 0;
@ -544,14 +544,14 @@ transport(void)
mixrun = j; mixrun = j;
if (multi_Dflag && j == floor((LDBLE)nmix / 2)) if (multi_Dflag && j == floor((LDBLE)nmix / 2))
{ {
//sprintf(token, //snprintf(token, sizeof(token),
// "Transport step %3d. Multicomponent diffusion run %3d.", // "Transport step %3d. Multicomponent diffusion run %3d.",
// transport_step, j); // transport_step, j);
//dup_print(token, FALSE); //dup_print(token, FALSE);
} }
else if (!multi_Dflag) else if (!multi_Dflag)
{ {
sprintf(token, "Transport step %3d. Mixrun %3d.", snprintf(token, sizeof(token), "Transport step %3d. Mixrun %3d.",
transport_step, j); transport_step, j);
dup_print(token, FALSE); dup_print(token, FALSE);
} }
@ -595,11 +595,11 @@ transport(void)
max_iter = overall_iterations; max_iter = overall_iterations;
cell_no = i; cell_no = i;
if (multi_Dflag) if (multi_Dflag)
sprintf(token, snprintf(token, sizeof(token),
"Transport step %3d. MCDrun %3d. Cell %3d. (Max. iter %3d)", "Transport step %3d. MCDrun %3d. Cell %3d. (Max. iter %3d)",
transport_step, j, i, max_iter); transport_step, j, i, max_iter);
else else
sprintf(token, snprintf(token, sizeof(token),
"Transport step %3d. Mixrun %3d. Cell %3d. (Max. iter %3d)", "Transport step %3d. Mixrun %3d. Cell %3d. (Max. iter %3d)",
transport_step, j, i, max_iter); transport_step, j, i, max_iter);
status(0, token); status(0, token);
@ -665,7 +665,7 @@ transport(void)
*/ */
if (ishift != 0) if (ishift != 0)
{ {
sprintf(token, "Transport step %3d.", transport_step); snprintf(token, sizeof(token), "Transport step %3d.", transport_step);
dup_print(token, FALSE); dup_print(token, FALSE);
if (b_c == 1) if (b_c == 1)
rate_sim_time_start = ((double)transport_step - 1) * rate_sim_time_start = ((double)transport_step - 1) *
@ -758,11 +758,11 @@ transport(void)
kin_time /= 2; kin_time /= 2;
cell_no = i; cell_no = i;
if (multi_Dflag) if (multi_Dflag)
sprintf(token, snprintf(token, sizeof(token),
"Transport step %3d. MCDrun %3d. Cell %3d. (Max. iter %3d)", "Transport step %3d. MCDrun %3d. Cell %3d. (Max. iter %3d)",
transport_step, 0, i, max_iter); transport_step, 0, i, max_iter);
else else
sprintf(token, snprintf(token, sizeof(token),
"Transport step %3d. Mixrun %3d. Cell %3d. (Max. iter %3d)", "Transport step %3d. Mixrun %3d. Cell %3d. (Max. iter %3d)",
transport_step, 0, i, max_iter); transport_step, 0, i, max_iter);
status(0, token); status(0, token);
@ -807,14 +807,14 @@ transport(void)
mixrun = j; mixrun = j;
if (multi_Dflag && j == nmix && (transport_step % print_modulus == 0)) 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 %3d. Multicomponent diffusion run %3d.",
transport_step, j); transport_step, j);
dup_print(token, FALSE); dup_print(token, FALSE);
} }
else if (!multi_Dflag) else if (!multi_Dflag)
{ {
sprintf(token, "Transport step %3d. Mixrun %3d.", snprintf(token, sizeof(token), "Transport step %3d. Mixrun %3d.",
transport_step, j); transport_step, j);
dup_print(token, FALSE); dup_print(token, FALSE);
} }
@ -862,11 +862,11 @@ transport(void)
max_iter = overall_iterations; max_iter = overall_iterations;
cell_no = i; cell_no = i;
if (multi_Dflag) if (multi_Dflag)
sprintf(token, snprintf(token, sizeof(token),
"Transport step %3d. MCDrun %3d. Cell %3d. (Max. iter %3d)", "Transport step %3d. MCDrun %3d. Cell %3d. (Max. iter %3d)",
transport_step, j, i, max_iter); transport_step, j, i, max_iter);
else else
sprintf(token, snprintf(token, sizeof(token),
"Transport step %3d. Mixrun %3d. Cell %3d. (Max. iter %3d)", "Transport step %3d. Mixrun %3d. Cell %3d. (Max. iter %3d)",
transport_step, j, i, max_iter); transport_step, j, i, max_iter);
status(0, token); status(0, token);
@ -959,14 +959,14 @@ transport(void)
if (multi_Dflag && moles_added[0].moles > 0) 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:"); "\nFor balancing negative concentrations in MCD, added in total to the system:");
warning_msg(token); warning_msg(token);
for (i = 0; i < count_moles_added; i++) for (i = 0; i < count_moles_added; i++)
{ {
if (!moles_added[i].moles) if (!moles_added[i].moles)
break; break;
sprintf(token, snprintf(token, sizeof(token),
"\t %.4e moles %s.", "\t %.4e moles %s.",
(double)moles_added[i].moles, moles_added[i].name); (double)moles_added[i].moles, moles_added[i].name);
warning_msg(token); warning_msg(token);
@ -1246,7 +1246,7 @@ init_mix(void)
m = (LDBLE *)free_check_null(m); m = (LDBLE *)free_check_null(m);
m1 = (LDBLE *)free_check_null(m1); m1 = (LDBLE *)free_check_null(m1);
char token[MAX_LENGTH]; 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); error_msg(token, STOP);
} }
if (bcon_first == 1 || bcon_last == 1) if (bcon_first == 1 || bcon_last == 1)
@ -1367,7 +1367,7 @@ init_mix(void)
m = (LDBLE *)free_check_null(m); m = (LDBLE *)free_check_null(m);
m1 = (LDBLE *)free_check_null(m1); m1 = (LDBLE *)free_check_null(m1);
char token[MAX_LENGTH]; 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); error_msg(token, STOP);
} }
l_nmix = 1 + (int) floor(1.5 * maxmix); 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) if (!warn_MCD_X)
{ {
sprintf(token, snprintf(token, sizeof(token),
"MCD found more than 1 exchanger, uses X for interlayer diffusion."); "MCD found more than 1 exchanger, uses X for interlayer diffusion.");
warning_msg(token); warning_msg(token);
warn_MCD_X = 1; warn_MCD_X = 1;
@ -3593,7 +3593,7 @@ multi_D(LDBLE DDt, int mobile_cell, int stagnant)
} }
if (temp < -1e-12) if (temp < -1e-12)
{ {
sprintf(token, snprintf(token, sizeof(token),
"Negative concentration in MCD: added %.4e moles %s in cell %d", "Negative concentration in MCD: added %.4e moles %s in cell %d",
(double)-temp, it->first.c_str(), i); (double)-temp, it->first.c_str(), i);
warning_msg(token); 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 * 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); string.append(charge);
} }
@ -1193,37 +1193,37 @@ status(int count, const char *str, bool rk_string)
{ {
stdstr = str; stdstr = str;
} }
sprintf(sim_str, "\rSimulation %d.", simulation); snprintf(sim_str, sizeof(sim_str), "\rSimulation %d.", simulation);
sprintf(state_str, " "); snprintf(state_str, sizeof(state_str), " ");
sprintf(spin_str, " "); snprintf(spin_str, sizeof(spin_str), " ");
switch (state) switch (state)
{ {
default: default:
break; break;
case INITIAL_SOLUTION: 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; break;
case INITIAL_EXCHANGE: 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; break;
case INITIAL_SURFACE: 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; break;
case INVERSE: 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; break;
case REACTION: case REACTION:
if (use.Get_kinetics_in() == TRUE) 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 else
{ {
sprintf(state_str, "Reaction step %d.", reaction_step); snprintf(state_str, sizeof(state_str), "Reaction step %d.", reaction_step);
} }
break; break;
case ADVECTION: case ADVECTION:
sprintf(state_str, "Advection, shift %d.", advection_step); snprintf(state_str, sizeof(state_str), "Advection, shift %d.", advection_step);
break; break;
} }
spinner++; spinner++;

View File

@ -19,7 +19,7 @@ bool FileExists(const char *szPathName)
if (fileHandle == INVALID_HANDLE_VALUE) if (fileHandle == INVALID_HANDLE_VALUE)
{ {
char buffer[100]; char buffer[100];
sprintf(buffer, "Could not open file (error %d)\n", GetLastError()); snprintf(buffer, sizeof(buffer), "Could not open file (error %d)\n", GetLastError());
retValue = false; retValue = false;
} }
else else

View File

@ -530,7 +530,7 @@ void TestIPhreeqc::TestRunString(void)
IPhreeqc obj; IPhreeqc obj;
char OUTPUT_FILE[80]; char OUTPUT_FILE[80];
sprintf(OUTPUT_FILE, "phreeqc.%lu.out", (unsigned long)obj.Index); snprintf(OUTPUT_FILE, sizeof(OUTPUT_FILE), "phreeqc.%lu.out", (unsigned long)obj.Index);
FileTest ofile(OUTPUT_FILE); FileTest ofile(OUTPUT_FILE);
CPPUNIT_ASSERT( ofile.RemoveExisting() ); CPPUNIT_ASSERT( ofile.RemoveExisting() );
@ -1271,7 +1271,7 @@ void TestIPhreeqc::TestCase1(void)
IPhreeqc obj; IPhreeqc obj;
char SELECTED_OUT[80]; char SELECTED_OUT[80];
sprintf(SELECTED_OUT, "selected_1.%lu.out", (unsigned long)obj.Index); snprintf(SELECTED_OUT, sizeof(SELECTED_OUT), "selected_1.%lu.out", (unsigned long)obj.Index);
// remove punch file if it exists // remove punch file if it exists
FileTest sofile(SELECTED_OUT); FileTest sofile(SELECTED_OUT);
@ -1484,7 +1484,7 @@ void TestIPhreeqc::TestFileOnOff(const char* FILENAME_FORMAT, bool output_file_o
IPhreeqc obj; IPhreeqc obj;
char FILENAME[80]; char FILENAME[80];
sprintf(FILENAME, FILENAME_FORMAT, obj.GetId()); snprintf(FILENAME, sizeof(FILENAME), FILENAME_FORMAT, obj.GetId());
// remove FILENAME if it exists // remove FILENAME if it exists
// //
@ -2004,7 +2004,7 @@ void TestIPhreeqc::TestListComponents(void)
void TestIPhreeqc::TestSetDumpFileName(void) void TestIPhreeqc::TestSetDumpFileName(void)
{ {
char DUMP_FILENAME[80]; char DUMP_FILENAME[80];
sprintf(DUMP_FILENAME, "dump.%06d.out", ::rand()); snprintf(DUMP_FILENAME, sizeof(DUMP_FILENAME), "dump.%06d.out", ::rand());
if (::FileExists(DUMP_FILENAME)) if (::FileExists(DUMP_FILENAME))
{ {
::DeleteFile(DUMP_FILENAME); ::DeleteFile(DUMP_FILENAME);
@ -2086,7 +2086,7 @@ void TestIPhreeqc::TestSetDumpFileName(void)
void TestIPhreeqc::TestSetOutputFileName(void) void TestIPhreeqc::TestSetOutputFileName(void)
{ {
char OUTPUT_FILENAME[80]; char OUTPUT_FILENAME[80];
sprintf(OUTPUT_FILENAME, "output.%06d.out", ::rand()); snprintf(OUTPUT_FILENAME, sizeof(OUTPUT_FILENAME), "output.%06d.out", ::rand());
if (::FileExists(OUTPUT_FILENAME)) if (::FileExists(OUTPUT_FILENAME))
{ {
::DeleteFile(OUTPUT_FILENAME); ::DeleteFile(OUTPUT_FILENAME);
@ -2161,7 +2161,7 @@ void TestIPhreeqc::TestSetOutputFileName(void)
CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " Mass of water (kg) = ") != NULL ); CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " Mass of water (kg) = ") != NULL );
CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " Total alkalinity (eq/kg) = ") != NULL ); CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " Total alkalinity (eq/kg) = ") != NULL );
CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " Total CO2 (mol/kg) = ") != NULL ); CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " Total CO2 (mol/kg) = ") != NULL );
CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " Temperature (°C) = ") != NULL ); CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " Temperature (<EFBFBD>C) = ") != NULL );
CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " Electrical balance (eq) = ") != NULL ); CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " Electrical balance (eq) = ") != NULL );
CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " Percent error, 100*(Cat-|An|)/(Cat+|An|) = ") != NULL ); CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " Percent error, 100*(Cat-|An|)/(Cat+|An|) = ") != NULL );
CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " Iterations = ") != NULL ); CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " Iterations = ") != NULL );
@ -2171,7 +2171,7 @@ void TestIPhreeqc::TestSetOutputFileName(void)
CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), "----------------------------Distribution of species----------------------------") != NULL ); CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), "----------------------------Distribution of species----------------------------") != NULL );
CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), "") != NULL ); CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), "") != NULL );
CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " Log Log Log mole V") != NULL ); CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " Log Log Log mole V") != NULL );
CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " Species Molality Activity Molality Activity Gamma cm³/mol")!= NULL ); CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " Species Molality Activity Molality Activity Gamma cm<EFBFBD>/mol")!= NULL );
CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), "") != NULL ); CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), "") != NULL );
CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " OH- ") != NULL ); CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " OH- ") != NULL );
CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " H+ ") != NULL ); CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " H+ ") != NULL );
@ -2253,7 +2253,7 @@ void TestIPhreeqc::TestOutputStringOnOff(void)
void TestIPhreeqc::TestGetOutputString(void) void TestIPhreeqc::TestGetOutputString(void)
{ {
char OUTPUT_FILENAME[80]; char OUTPUT_FILENAME[80];
sprintf(OUTPUT_FILENAME, "output.%06d.out", ::rand()); snprintf(OUTPUT_FILENAME, sizeof(OUTPUT_FILENAME), "output.%06d.out", ::rand());
if (::FileExists(OUTPUT_FILENAME)) if (::FileExists(OUTPUT_FILENAME))
{ {
::DeleteFile(OUTPUT_FILENAME); ::DeleteFile(OUTPUT_FILENAME);
@ -2439,7 +2439,7 @@ void TestIPhreeqc::TestGetOutputStringLine(void)
void TestIPhreeqc::TestSetLogFileName(void) void TestIPhreeqc::TestSetLogFileName(void)
{ {
char LOG_FILENAME[80]; char LOG_FILENAME[80];
sprintf(LOG_FILENAME, "log.%06d.out", ::rand()); snprintf(LOG_FILENAME, sizeof(LOG_FILENAME), "log.%06d.out", ::rand());
if (::FileExists(LOG_FILENAME)) if (::FileExists(LOG_FILENAME))
{ {
::DeleteFile(LOG_FILENAME); ::DeleteFile(LOG_FILENAME);
@ -2531,7 +2531,7 @@ void TestIPhreeqc::TestLogStringOnOff(void)
void TestIPhreeqc::TestGetLogString(void) void TestIPhreeqc::TestGetLogString(void)
{ {
char LOG_FILENAME[80]; char LOG_FILENAME[80];
sprintf(LOG_FILENAME, "log.%06d.out", ::rand()); snprintf(LOG_FILENAME, sizeof(LOG_FILENAME), "log.%06d.out", ::rand());
if (::FileExists(LOG_FILENAME)) if (::FileExists(LOG_FILENAME))
{ {
::DeleteFile(LOG_FILENAME); ::DeleteFile(LOG_FILENAME);
@ -2767,7 +2767,7 @@ void TestIPhreeqc::TestGetLogStringLine(void)
void TestIPhreeqc::TestSetErrorFileName(void) void TestIPhreeqc::TestSetErrorFileName(void)
{ {
char ERR_FILENAME[80]; char ERR_FILENAME[80];
sprintf(ERR_FILENAME, "error.%s.out", "TestIPhreeqc-TestSetErrorFileName"); snprintf(ERR_FILENAME, sizeof(ERR_FILENAME), "error.%s.out", "TestIPhreeqc-TestSetErrorFileName");
if (::FileExists(ERR_FILENAME)) if (::FileExists(ERR_FILENAME))
{ {
::DeleteFile(ERR_FILENAME); ::DeleteFile(ERR_FILENAME);
@ -2843,7 +2843,7 @@ void TestIPhreeqc::TestErrorStringOnOff(void)
void TestIPhreeqc::TestGetErrorString(void) void TestIPhreeqc::TestGetErrorString(void)
{ {
char ERR_FILENAME[80]; char ERR_FILENAME[80];
sprintf(ERR_FILENAME, "error.%06d.out", ::rand()); snprintf(ERR_FILENAME, sizeof(ERR_FILENAME), "error.%06d.out", ::rand());
if (::FileExists(ERR_FILENAME)) if (::FileExists(ERR_FILENAME))
{ {
::DeleteFile(ERR_FILENAME); ::DeleteFile(ERR_FILENAME);
@ -2959,7 +2959,7 @@ void TestIPhreeqc::TestGetErrorStringLineCount(void)
void TestIPhreeqc::TestSetSelectedOutputFileName(void) void TestIPhreeqc::TestSetSelectedOutputFileName(void)
{ {
char SELOUT_FILENAME[80]; char SELOUT_FILENAME[80];
sprintf(SELOUT_FILENAME, "selected_output.%06d.out", ::rand()); snprintf(SELOUT_FILENAME, sizeof(SELOUT_FILENAME), "selected_output.%06d.out", ::rand());
if (::FileExists(SELOUT_FILENAME)) if (::FileExists(SELOUT_FILENAME))
{ {
::DeleteFile(SELOUT_FILENAME); ::DeleteFile(SELOUT_FILENAME);
@ -3616,7 +3616,7 @@ void TestIPhreeqc::TestDelete(void)
IPhreeqc obj; IPhreeqc obj;
char OUTPUT_FILE[80]; char OUTPUT_FILE[80];
sprintf(OUTPUT_FILE, "phreeqc.%lu.out", (unsigned long)obj.Index); snprintf(OUTPUT_FILE, sizeof(OUTPUT_FILE), "phreeqc.%lu.out", (unsigned long)obj.Index);
if (::FileExists(OUTPUT_FILE)) if (::FileExists(OUTPUT_FILE))
{ {

View File

@ -438,7 +438,7 @@ void TestIPhreeqcLib::TestRunString(void)
CPPUNIT_ASSERT(n >= 0); CPPUNIT_ASSERT(n >= 0);
char OUTPUT_FILE[80]; char OUTPUT_FILE[80];
sprintf(OUTPUT_FILE, "phreeqc.%d.out", n); snprintf(OUTPUT_FILE, sizeof(OUTPUT_FILE), "phreeqc.%d.out", n);
if (::FileExists(OUTPUT_FILE)) if (::FileExists(OUTPUT_FILE))
{ {
@ -1325,7 +1325,7 @@ void TestIPhreeqcLib::TestCase1(void)
CPPUNIT_ASSERT(n >= 0); CPPUNIT_ASSERT(n >= 0);
char SELECTED_OUT[80]; char SELECTED_OUT[80];
sprintf(SELECTED_OUT, "selected_1.%d.out", n); snprintf(SELECTED_OUT, sizeof(SELECTED_OUT), "selected_1.%d.out", n);
// remove punch file if it exists // remove punch file if it exists
if (::FileExists(SELECTED_OUT)) if (::FileExists(SELECTED_OUT))
@ -1368,7 +1368,7 @@ void TestIPhreeqcLib::TestCase2(void)
CPPUNIT_ASSERT(n >= 0); CPPUNIT_ASSERT(n >= 0);
char SELECTED_OUT[80]; char SELECTED_OUT[80];
sprintf(SELECTED_OUT, "selected_1.%d.out", n); snprintf(SELECTED_OUT, sizeof(SELECTED_OUT), "selected_1.%d.out", n);
// remove punch files if they exists // remove punch files if they exists
// //
@ -1544,7 +1544,7 @@ void TestIPhreeqcLib::TestFileOnOff(const char* FILENAME_FORMAT, int output_file
CPPUNIT_ASSERT(n >= 0); CPPUNIT_ASSERT(n >= 0);
char FILENAME[80]; char FILENAME[80];
sprintf(FILENAME, FILENAME_FORMAT, n); snprintf(FILENAME, sizeof(FILENAME), FILENAME_FORMAT, n);
// remove FILENAME if it exists // remove FILENAME if it exists
// //
@ -2082,7 +2082,7 @@ void TestIPhreeqcLib::TestErrorFileOn(void)
CPPUNIT_ASSERT(n >= 0); CPPUNIT_ASSERT(n >= 0);
char FILENAME[80]; char FILENAME[80];
sprintf(FILENAME, "phreeqc.%d.err", n); snprintf(FILENAME, sizeof(FILENAME), "phreeqc.%d.err", n);
if (::FileExists(FILENAME)) if (::FileExists(FILENAME))
{ {
@ -2132,7 +2132,7 @@ void TestIPhreeqcLib::TestLogFileOn(void)
CPPUNIT_ASSERT(n >= 0); CPPUNIT_ASSERT(n >= 0);
char FILENAME[80]; char FILENAME[80];
sprintf(FILENAME, "phreeqc.%d.log", n); snprintf(FILENAME, sizeof(FILENAME), "phreeqc.%d.log", n);
if (::FileExists(FILENAME)) if (::FileExists(FILENAME))
{ {
@ -2294,7 +2294,7 @@ void TestIPhreeqcLib::TestClearAccumulatedLines(void)
void TestIPhreeqcLib::TestSetDumpFileName(void) void TestIPhreeqcLib::TestSetDumpFileName(void)
{ {
char DUMP_FILENAME[80]; char DUMP_FILENAME[80];
sprintf(DUMP_FILENAME, "dump.%06d.out", ::rand()); snprintf(DUMP_FILENAME, sizeof(DUMP_FILENAME), "dump.%06d.out", ::rand());
if (::FileExists(DUMP_FILENAME)) if (::FileExists(DUMP_FILENAME))
{ {
::DeleteFile(DUMP_FILENAME); ::DeleteFile(DUMP_FILENAME);
@ -2386,7 +2386,7 @@ void TestIPhreeqcLib::TestSetDumpFileName(void)
void TestIPhreeqcLib::TestSetOutputFileName(void) void TestIPhreeqcLib::TestSetOutputFileName(void)
{ {
char OUTPUT_FILENAME[80]; char OUTPUT_FILENAME[80];
sprintf(OUTPUT_FILENAME, "output.%06d.out", ::rand()); snprintf(OUTPUT_FILENAME, sizeof(OUTPUT_FILENAME), "output.%06d.out", ::rand());
if (::FileExists(OUTPUT_FILENAME)) if (::FileExists(OUTPUT_FILENAME))
{ {
::DeleteFile(OUTPUT_FILENAME); ::DeleteFile(OUTPUT_FILENAME);
@ -2465,7 +2465,7 @@ void TestIPhreeqcLib::TestSetOutputFileName(void)
CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " Mass of water (kg) = ") != NULL ); CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " Mass of water (kg) = ") != NULL );
CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " Total alkalinity (eq/kg) = ") != NULL ); CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " Total alkalinity (eq/kg) = ") != NULL );
CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " Total CO2 (mol/kg) = ") != NULL ); CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " Total CO2 (mol/kg) = ") != NULL );
CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " Temperature (°C) = ") != NULL ); CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " Temperature (<EFBFBD>C) = ") != NULL );
CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " Electrical balance (eq) = ") != NULL ); CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " Electrical balance (eq) = ") != NULL );
CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " Percent error, 100*(Cat-|An|)/(Cat+|An|) = ") != NULL ); CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " Percent error, 100*(Cat-|An|)/(Cat+|An|) = ") != NULL );
CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " Iterations = ") != NULL ); CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " Iterations = ") != NULL );
@ -2475,7 +2475,7 @@ void TestIPhreeqcLib::TestSetOutputFileName(void)
CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), "----------------------------Distribution of species----------------------------") != NULL ); CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), "----------------------------Distribution of species----------------------------") != NULL );
CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), "") != NULL ); CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), "") != NULL );
CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " Log Log Log mole V") != NULL ); CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " Log Log Log mole V") != NULL );
CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " Species Molality Activity Molality Activity Gamma cm³/mol")!= NULL ); CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " Species Molality Activity Molality Activity Gamma cm<EFBFBD>/mol")!= NULL );
CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), "") != NULL ); CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), "") != NULL );
CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " OH- ") != NULL ); CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " OH- ") != NULL );
CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " H+ ") != NULL ); CPPUNIT_ASSERT( ::strstr(lines[line++].c_str(), " H+ ") != NULL );
@ -2572,7 +2572,7 @@ void TestIPhreeqcLib::TestGetOutputString(void)
CPPUNIT_ASSERT(n >= 0); CPPUNIT_ASSERT(n >= 0);
char OUTPUT_FILENAME[80]; char OUTPUT_FILENAME[80];
sprintf(OUTPUT_FILENAME, "output.%06d.out", ::rand()); snprintf(OUTPUT_FILENAME, sizeof(OUTPUT_FILENAME), "output.%06d.out", ::rand());
if (::FileExists(OUTPUT_FILENAME)) if (::FileExists(OUTPUT_FILENAME))
{ {
::DeleteFile(OUTPUT_FILENAME); ::DeleteFile(OUTPUT_FILENAME);
@ -2769,7 +2769,7 @@ void TestIPhreeqcLib::TestGetOutputStringLine(void)
void TestIPhreeqcLib::TestSetLogFileName(void) void TestIPhreeqcLib::TestSetLogFileName(void)
{ {
char LOG_FILENAME[80]; char LOG_FILENAME[80];
sprintf(LOG_FILENAME, "log.%06d.out", ::rand()); snprintf(LOG_FILENAME, sizeof(LOG_FILENAME), "log.%06d.out", ::rand());
if (::FileExists(LOG_FILENAME)) if (::FileExists(LOG_FILENAME))
{ {
::DeleteFile(LOG_FILENAME); ::DeleteFile(LOG_FILENAME);
@ -2872,7 +2872,7 @@ void TestIPhreeqcLib::TestLogStringOnOff(void)
void TestIPhreeqcLib::TestGetLogString(void) void TestIPhreeqcLib::TestGetLogString(void)
{ {
char LOG_FILENAME[80]; char LOG_FILENAME[80];
sprintf(LOG_FILENAME, "log.%06d.out", ::rand()); snprintf(LOG_FILENAME, sizeof(LOG_FILENAME), "log.%06d.out", ::rand());
if (::FileExists(LOG_FILENAME)) if (::FileExists(LOG_FILENAME))
{ {
::DeleteFile(LOG_FILENAME); ::DeleteFile(LOG_FILENAME);
@ -3134,7 +3134,7 @@ void TestIPhreeqcLib::TestGetLogStringLine(void)
void TestIPhreeqcLib::TestSetErrorFileName(void) void TestIPhreeqcLib::TestSetErrorFileName(void)
{ {
char ERR_FILENAME[80]; char ERR_FILENAME[80];
sprintf(ERR_FILENAME, "error.%s.out", "TestIPhreeqcLib-TestSetErrorFileName"); snprintf(ERR_FILENAME, sizeof(ERR_FILENAME), "error.%s.out", "TestIPhreeqcLib-TestSetErrorFileName");
if (::FileExists(ERR_FILENAME)) if (::FileExists(ERR_FILENAME))
{ {
::DeleteFile(ERR_FILENAME); ::DeleteFile(ERR_FILENAME);
@ -3221,7 +3221,7 @@ void TestIPhreeqcLib::TestErrorStringOnOff(void)
void TestIPhreeqcLib::TestGetErrorString(void) void TestIPhreeqcLib::TestGetErrorString(void)
{ {
char ERR_FILENAME[80]; char ERR_FILENAME[80];
sprintf(ERR_FILENAME, "error.%06d.out", ::rand()); snprintf(ERR_FILENAME, sizeof(ERR_FILENAME), "error.%06d.out", ::rand());
if (::FileExists(ERR_FILENAME)) if (::FileExists(ERR_FILENAME))
{ {
::DeleteFile(ERR_FILENAME); ::DeleteFile(ERR_FILENAME);
@ -3355,7 +3355,7 @@ void TestIPhreeqcLib::TestGetErrorStringLineCount(void)
void TestIPhreeqcLib::TestSetSelectedOutputFileName(void) void TestIPhreeqcLib::TestSetSelectedOutputFileName(void)
{ {
char SELOUT_FILENAME[80]; char SELOUT_FILENAME[80];
sprintf(SELOUT_FILENAME, "selected_output.%06d.out", ::rand()); snprintf(SELOUT_FILENAME, sizeof(SELOUT_FILENAME), "selected_output.%06d.out", ::rand());
if (::FileExists(SELOUT_FILENAME)) if (::FileExists(SELOUT_FILENAME))
{ {
::DeleteFile(SELOUT_FILENAME); ::DeleteFile(SELOUT_FILENAME);
@ -3995,7 +3995,7 @@ void TestIPhreeqcLib::TestDelete(void)
CPPUNIT_ASSERT(n >= 0); CPPUNIT_ASSERT(n >= 0);
char OUTPUT_FILE[80]; char OUTPUT_FILE[80];
sprintf(OUTPUT_FILE, "phreeqc.%d.out", n); snprintf(OUTPUT_FILE, sizeof(OUTPUT_FILE), "phreeqc.%d.out", n);
if (::FileExists(OUTPUT_FILE)) if (::FileExists(OUTPUT_FILE))
{ {