Skip to content

Commit

Permalink
Squashed 'src/' changes from bd2e2b68..3e6c2e94
Browse files Browse the repository at this point in the history
3e6c2e94 Merge commit 'c4958bb740964f1804a6a4e6ae5d8df52c5c64ad'
c4958bb7 Squashed 'common/' changes from b9af572..740bdd5
625f6f14 Fixed bugs in inverse
ea9e0eff strcpy_safe and strcat_safe
9b061572 trying different header files
e8902694 added <cstring>
c370c7be warnings, strcat, strcpy
14ed59f2 Try using goto(s)
d2d31d2c Try updated logical expression
d2a3eacf Turn off optimizing on k_temp

git-subtree-dir: src
git-subtree-split: 3e6c2e94e308d95c2be3b98e50cf0f253f327a29
  • Loading branch information
Darth Vader committed Nov 16, 2023
1 parent ab1ae74 commit cbb5296
Show file tree
Hide file tree
Showing 22 changed files with 209 additions and 277 deletions.
2 changes: 1 addition & 1 deletion NameDouble.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ cxxNameDouble::add(const char *token, LDBLE total)
//
{
char key[MAX_LENGTH];
strcpy(key, token);
Utilities::strcpy_safe(key, MAX_LENGTH, token);

cxxNameDouble::iterator current = (*this).find(key);
if (current != (*this).end())
Expand Down
32 changes: 17 additions & 15 deletions PBasic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,8 @@ numtostr(char * Result, LDBLE n)
l_s[i] = '\0';
* p2c: basic.p, line 248:
* Note: Modification of string length may translate incorrectly [146] *
return strcpy(Result, strltrim(l_s));
Utilities::strcpy_safe(Result, MAX_LENGTH, strltrim(l_s));
return Result;
} */
}

Expand Down Expand Up @@ -1746,33 +1747,33 @@ void PBasic::
snerr(const char * l_s)
{
char str[MAX_LENGTH] = {0};
strcpy(str, "Syntax_error ");
Utilities::strcpy_safe(str, MAX_LENGTH, "Syntax_error ");
if (phreeqci_gui)
{
_ASSERTE(nIDErrPrompt == 0);
nIDErrPrompt = IDS_ERR_SYNTAX;
}
strcat(str, l_s);
strcat(str, " in line: ");
Utilities::strcat_safe(str, MAX_LENGTH, l_s);
Utilities::strcat_safe(str, MAX_LENGTH, " in line: ");
if (strcmp(inbuf, "run"))
strcat(str, inbuf);
Utilities::strcat_safe(str, MAX_LENGTH, inbuf);
errormsg(str);
}

void PBasic::
tmerr(const char * l_s)
{
char str[MAX_LENGTH] = {0};
strcpy(str, "Type mismatch error");
Utilities::strcpy_safe(str, MAX_LENGTH, "Type mismatch error");
if (phreeqci_gui)
{
_ASSERTE(nIDErrPrompt == 0);
nIDErrPrompt = IDS_ERR_MISMATCH;
}
strcat(str, l_s);
strcat(str, " in line: ");
Utilities::strcat_safe(str, MAX_LENGTH, l_s);
Utilities::strcat_safe(str, MAX_LENGTH, " in line: ");
if (strcmp(inbuf, "run"))
strcat(str, inbuf);
Utilities::strcat_safe(str, MAX_LENGTH, inbuf);
errormsg(str);
}

Expand Down Expand Up @@ -1901,8 +1902,9 @@ require(int k, struct LOC_exec *LINK)
if (item == command_tokens.end())
snerr(": missing unknown command");
else {
strcpy(str, ": missing ");
snerr(strcat(str, item->first.c_str()));
Utilities::strcpy_safe(str, MAX_LENGTH, ": missing ");
Utilities::strcat_safe(str, MAX_LENGTH, item->first.c_str());
snerr(str);
}
#if !defined(R_SO)
exit(4);
Expand Down Expand Up @@ -2544,7 +2546,7 @@ factor(struct LOC_exec * LINK)
size_t l = elt_name.size();
l = l < 256 ? 256 : l + 1;
char* token = (char*)PhreeqcPtr->PHRQ_malloc(l * sizeof(char));
strcpy(token, elt_name.c_str());
Utilities::strcpy_safe(token, l, elt_name.c_str());
*elt_varrec->UU.U1.sval = token;
}
break;
Expand Down Expand Up @@ -6240,9 +6242,9 @@ exec(void)
_ASSERTE(nIDErrPrompt == 0);
nIDErrPrompt = IDS_ERR_ILLEGAL;
}
strcat(STR1, "Illegal command in line: ");
Utilities::strcat_safe(STR1, MAX_LENGTH, "Illegal command in line: ");
if (strcmp(inbuf, "run"))
strcat(STR1, inbuf);
Utilities::strcat_safe(STR1, MAX_LENGTH, inbuf);
errormsg(STR1);
break;
}
Expand Down Expand Up @@ -6392,7 +6394,7 @@ cmdplot_xy(struct LOC_exec *LINK)
n[i] = expr(LINK);
if (n[i].stringval)
{
strcpy(STR[i], n[i].UU.sval);
Utilities::strcpy_safe(STR[i], MAX_LENGTH, n[i].UU.sval);
PhreeqcPtr->PHRQ_free(n[i].UU.sval);
}
else
Expand Down
3 changes: 2 additions & 1 deletion Phreeqc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "PBasic.h"
#include "Temperature.h"
#include "SSassemblage.h"
#include "Utils.h"

#if defined(PHREEQCI_GUI)
#ifdef _DEBUG
Expand Down Expand Up @@ -173,7 +174,7 @@ size_t Phreeqc::list_components(std::list<std::string> &list_c)
{
if (it->first == "Charge") continue;
char string[MAX_LENGTH];
strcpy(string, it->first.c_str());
Utilities::strcpy_safe(string, MAX_LENGTH, it->first.c_str());
class master *master_ptr = master_bsearch_primary(string);
if (master_ptr == NULL) continue;
if (master_ptr->type != AQ) continue;
Expand Down
1 change: 0 additions & 1 deletion Phreeqc.h
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,6 @@ class Phreeqc
int get_token(const char** eqnaddr, std::string& string, LDBLE* z, int* l);
int islegit(const char c);
void malloc_error(void);
int parse_couple(char* token);
int print_centered(const char* string);
static int replace(const char* str1, const char* str2, char* str);
static void replace(std::string &stds, const char* str1, const char* str2);
Expand Down
8 changes: 4 additions & 4 deletions System.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "cxxMix.h"
#include "Reaction.h"
#include "Temperature.h"

#include "Utils.h"
#if defined(PHREEQCI_GUI)
#ifdef _DEBUG
#define new DEBUG_NEW
Expand Down Expand Up @@ -66,11 +66,11 @@ cxxSystem::totalize(Phreeqc * phreeqc_ptr)
if (this->solution != NULL)
{
char token[MAX_LENGTH];
strcpy(token, "O");
Utilities::strcpy_safe(token, MAX_LENGTH, "O");
this->totals[token] = this->solution->Get_total_o();
strcpy(token, "H");
Utilities::strcpy_safe(token, MAX_LENGTH, "H");
this->totals[token] = this->solution->Get_total_h();
strcpy(token, "Charge");
Utilities::strcpy_safe(token, MAX_LENGTH, "Charge");
this->totals[token] = this->solution->Get_cb();
this->totals.add_extensive(this->solution->Get_totals(), 1.0);
}
Expand Down
Loading

0 comments on commit cbb5296

Please # to comment.