Skip to content

Commit

Permalink
Most string issues found. All the tests pass some of the time. Next u…
Browse files Browse the repository at this point in the history
…p is valgrind.
  • Loading branch information
Rory Barnes committed Aug 9, 2024
1 parent c15999e commit 74609fc
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 23 deletions.
17 changes: 13 additions & 4 deletions src/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ void sort_output(OUTPUT *output, int sorted[]) {
SORTED_OUTPUT sorted_output[MODULEOUTEND];
for (iOpt = 0; iOpt < MODULEOUTEND; iOpt++) {
sorted_output[iOpt].index = iOpt;
sorted_output[iOpt].name=NULL;
fvFormattedString(&sorted_output[iOpt].name, output[iOpt].cName);
}
qsort(sorted_output, MODULEOUTEND, sizeof(sorted_output[0]),
Expand All @@ -93,13 +94,16 @@ void sort_output(OUTPUT *output, int sorted[]) {
*/

void InitializeFiles(FILES *files, int iNumBodies) {
int iBody;
int iBody,iOption;

files->cLog = NULL;
files->cExe = NULL;
for (iBody = 0; iBody < iNumBodies; iBody++) {
// Infile must be initilized in ReadBodyNames
files->Outfile[iBody].cOut = NULL;
for (iOption=0;iOption<MODULEOPTEND;iOption++) {
files->Outfile[iBody].caGrid[iOption] = NULL;
}
}
}

Expand Down Expand Up @@ -299,8 +303,12 @@ void WriteDescription(char cLongDescr[], char cDescr[], int iMaxChars) {
char **cLine;

cLine = malloc(MAXARRAY * sizeof(char *));
for (iWord=0;iWord<MAXARRAY;iWord++) {
cLine[iWord]=NULL;
}

for (iLineWordNow = 0; iLineWordNow < MAXARRAY; iLineWordNow++) {
memset(cLine[iLineWordNow], '\0', OPTLEN);
//memset(cLine[iLineWordNow], '\0', OPTLEN);
memset(cDescription[iLineWordNow], '\0', OPTLEN);
}

Expand Down Expand Up @@ -347,7 +355,8 @@ void WriteDescription(char cLongDescr[], char cDescr[], int iMaxChars) {
// Now reset counters
iCharsLeft = iMaxChars;
for (iLineWordNow = 0; iLineWordNow < MAXARRAY; iLineWordNow++) {
memset(cLine[iLineWordNow], '\0', OPTLEN);
//memset(cLine[iLineWordNow], '\0', OPTLEN);
cLine[iLineWordNow]=NULL;
}
iLine++;
iLineWord = 0;
Expand Down Expand Up @@ -1045,7 +1054,7 @@ void fsUnitsViscosity(UNITS *units, char **cUnit) {
// strcat(cUnit, "^2/");
// fsUnitsTime(units->iTime, cTmp);
// strcat(cUnit, cTmp);
fvFormattedString(cUnit, cUnitLength, "^2/", cUnitTime);
fvFormattedString(cUnit, "%s^2/%s",cUnitLength,cUnitTime);
free(cUnitLength);
free(cUnitTime);
}
Expand Down
4 changes: 2 additions & 2 deletions src/distorb.c
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,6 @@ double fndCalcLongA(double dLongP, double dArgP) {

void VerifyOrbitModel(CONTROL *control, FILES *files, OPTIONS *options) {
int iFile, iFound = 0;
char *cTmp;

for (iFile = 0; iFile < files->iNumInputs; iFile++) {
if (options[OPT_ORBITMODEL].iLine[iFile] >= 0) {
Expand All @@ -499,6 +498,7 @@ void VerifyOrbitModel(CONTROL *control, FILES *files, OPTIONS *options) {
}

if (iFound == 0) {
char *cTmp;
fvFormattedString(&cTmp, options[OPT_ORBITMODEL].cDefault);
if (!memcmp(sLower(cTmp), "ll2", 3)) {
control->Evolve.iDistOrbModel = LL2;
Expand All @@ -513,8 +513,8 @@ void VerifyOrbitModel(CONTROL *control, FILES *files, OPTIONS *options) {
/* Chicanery. Since I only want this set once, I will
make it seem like the user set it. */
options[OPT_ORBITMODEL].iLine[0] = 1;
free(cTmp);
}
free(cTmp);
}


Expand Down
2 changes: 1 addition & 1 deletion src/eqtide.c
Original file line number Diff line number Diff line change
Expand Up @@ -1774,7 +1774,7 @@ void VerifyTideModel(CONTROL *control, FILES *files, OPTIONS *options) {
}

if (iFound == 0) {
char *cTmp;
char *cTmp=NULL;
fvFormattedString(&cTmp, options[OPT_TIDEMODEL].cDefault);
if (!memcmp(sLower(cTmp), "p2", 2)) {
control->Evolve.iEqtideModel = CPL;
Expand Down
5 changes: 5 additions & 0 deletions src/flare.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ void InitializeOptionsFlare(OPTIONS *options, fnReadOption fnRead[]) {
options[OPT_FLAREYINT].bMultiFile = 1;
options[OPT_FLAREYINT].dNeg = 1.0 / DAYSEC;
fvFormattedString(&options[OPT_FLAREYINT].cNeg, "1/day");
fvFormattedString(&options[OPT_FLAREYINT].cDimension,"1/time");
fnRead[OPT_FLAREYINT] = &ReadFlareYInt;
fvFormattedString(&options[OPT_FLAREYINT].cLongDescr,
" Y-Intercept for flare frequency distribution. Where the curve "
Expand Down Expand Up @@ -465,6 +466,7 @@ void InitializeOptionsFlare(OPTIONS *options, fnReadOption fnRead[]) {
options[OPT_FLARESLOPE].bMultiFile = 1;
options[OPT_FLARESLOPE].dNeg = 1.0 / (DAYSEC * log10(1.0e7));
fvFormattedString(&options[OPT_FLARESLOPE].cNeg, "1/day 1/log10(erg)");
fvFormattedString(&options[OPT_FLARESLOPE].cDimension,"1/time/energy");
fnRead[OPT_FLARESLOPE] = &ReadFlareSlope;
fvFormattedString(
&options[OPT_FLARESLOPE].cLongDescr,
Expand Down Expand Up @@ -501,6 +503,7 @@ void InitializeOptionsFlare(OPTIONS *options, fnReadOption fnRead[]) {
options[OPT_FLAREMINENERGY].bMultiFile = 1;
options[OPT_FLAREMINENERGY].dNeg = 1e-7;
fvFormattedString(&options[OPT_FLAREMINENERGY].cNeg, "ergs");
fvFormattedString(&options[OPT_FLAREMINENERGY].cDimension, "energy");
fnRead[OPT_FLAREMINENERGY] = &ReadFlareMinEnergy;

fvFormattedString(&options[OPT_FLAREMAXENERGY].cName, "dFlareMaxEnergy");
Expand All @@ -512,6 +515,7 @@ void InitializeOptionsFlare(OPTIONS *options, fnReadOption fnRead[]) {
options[OPT_FLAREMAXENERGY].bMultiFile = 1;
options[OPT_FLAREMAXENERGY].dNeg = 1e-7;
fvFormattedString(&options[OPT_FLAREMAXENERGY].cNeg, "ergs");
fvFormattedString(&options[OPT_FLAREMAXENERGY].cDimension, "energy");
fnRead[OPT_FLAREMAXENERGY] = &ReadFlareMaxEnergy;

fvFormattedString(&options[OPT_LXUVFLARECONST].cName, "dLXUVFlareConst");
Expand All @@ -537,6 +541,7 @@ void InitializeOptionsFlare(OPTIONS *options, fnReadOption fnRead[]) {
options[OPT_FLAREENERGYBIN].bMultiFile = 1;
options[OPT_FLAREENERGYBIN].dNeg = 1;
fvFormattedString(&options[OPT_FLAREENERGYBIN].cNeg, "None");
fvFormattedString(&options[OPT_FLAREENERGYBIN].cDimension,"energy");
fnRead[OPT_FLAREENERGYBIN] = &ReadFlareEnergyBin;

fvFormattedString(&options[OPT_FLAREFFD].cName, "sFlareFFD");
Expand Down
24 changes: 16 additions & 8 deletions src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -2669,13 +2669,16 @@ void ReadCosObl(BODY *body, CONTROL *control, FILES *files, OPTIONS *options,

void ReadOutputOrder(FILES *files, MODULE *module, OPTIONS *options,
OUTPUT *output, int iFile, int iVerbose) {
int i, j, count, iLen, iNumIndices = 0, bNeg[MAXARRAY], ok = 1, iNumGrid = 0;
int i, j, count, iLen, iNumIndices = 0, bNeg[MAXARRAY], ok = 1, iNumGrid = 0,iOption;
int k, iOut = -1, *lTmp, iCol, jCol;
char **saTmp, *cTmp = NULL, **cOption, *cOut;
int iLen1, iLen2;

lTmp = malloc(MAXLINES * sizeof(int));
cOption = malloc(MAXARRAY * sizeof(char *));
for (iOption=0;iOption<MAXARRAY;iOption++) {
cOption[iOption]=NULL;
}

AddOptionStringArray(files->Infile[iFile].cIn, options[OPT_OUTPUTORDER].cName,
&saTmp, &iNumIndices, &files->Infile[iFile].iNumLines,
Expand Down Expand Up @@ -2875,13 +2878,16 @@ void ReadOutputOrder(FILES *files, MODULE *module, OPTIONS *options,

void ReadGridOutput(FILES *files, OPTIONS *options, OUTPUT *output, int iFile,
int iVerbose) {
int i, j, count, iLen, iNumIndices = 0, bNeg[MAXARRAY], ok = 0, iNumGrid = 0;
int i, j, count, iLen, iNumIndices = 0, bNeg[MAXARRAY], ok = 0, iNumGrid = 0,iOption;
int k, iOut = -1, *lTmp;
char **saTmp, *cTmp, **cOption, *cOut;
char **saTmp, *cTmp=NULL, **cOption, *cOut;
int iLen1, iLen2;

lTmp = malloc(MAXLINES * sizeof(int));
cOption = malloc(MAXARRAY * sizeof(char *));
for (iOption=0;iOption<MAXARRAY;iOption++) {
cOption[iOption]=NULL;
}

AddOptionStringArray(files->Infile[iFile].cIn, options[OPT_GRIDOUTPUT].cName,
&saTmp, &iNumIndices, &files->Infile[iFile].iNumLines,
Expand Down Expand Up @@ -2909,9 +2915,9 @@ void ReadGridOutput(FILES *files, OPTIONS *options, OUTPUT *output, int iFile,
/* Check for ambiguity */
for (i = 0; i < iNumIndices; i++) {
count = 0; /* Number of possibilities */
for (j = 0; j < OPTLEN; j++) {
cTmp[j] = 0;
}
// for (j = 0; j < OPTLEN; j++) {
// cTmp[j] = 0;
// }
fvFormattedString(&cTmp, saTmp[i]);
for (j = 0; j < MODULEOUTEND; j++) {
for (k = 0; k < OPTLEN; k++) {
Expand All @@ -2930,7 +2936,7 @@ void ReadGridOutput(FILES *files, OPTIONS *options, OUTPUT *output, int iFile,
if (output[j].bGrid == 1 || output[j].bGrid == 2) {
iNumGrid += 1;
}
j = MODULEOUTEND; /* Poor man's break! */
j = MODULEOUTEND; /* Break! */
} else {
if (iLen1 < iLen2) {
iLen = iLen1;
Expand Down Expand Up @@ -3001,7 +3007,7 @@ void ReadGridOutput(FILES *files, OPTIONS *options, OUTPUT *output, int iFile,
fvFormattedString(&files->Outfile[iFile - 1].caCol[i],
output[iOut].cName);
} else {
memset(files->Outfile[iFile - 1].caGrid[iNumGrid - 1], '\0', OPTLEN);
//memset(files->Outfile[iFile - 1].caGrid[iNumGrid - 1], '\0', OPTLEN);
fvFormattedString(&files->Outfile[iFile - 1].caGrid[iNumGrid - 1],
output[iOut].cName);
}
Expand All @@ -3016,6 +3022,8 @@ void ReadGridOutput(FILES *files, OPTIONS *options, OUTPUT *output, int iFile,
files->Outfile[iFile - 1].iNumGrid = iNumGrid;

free(lTmp);
free(cTmp);
free(cOption);
}

void ReadOverwrite(BODY *body, CONTROL *control, FILES *files, OPTIONS *options,
Expand Down
2 changes: 1 addition & 1 deletion src/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -2218,7 +2218,7 @@ void WriteOutput(BODY *body, CONTROL *control, FILES *files, OUTPUT *output,
int iBody, iCol, iOut, iSubOut, iExtra = 0, iGrid, iLat, jBody, j;
double dCol[NUMOPT], *dTmp, dGrid[NUMOPT];
FILE *fp;
char *cUnit, *cPoiseGrid, *cLaplaceFunc;
char *cUnit, *cPoiseGrid=NULL, *cLaplaceFunc;

/* Write out all data columns for each body. As some data may span more than
1 column, we search the input list sequentially, adding iExtra to the
Expand Down
19 changes: 14 additions & 5 deletions src/poise.c
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,7 @@ void InitializeOptionsPoise(OPTIONS *options, fnReadOption fnRead[]) {
fvFormattedString(&options[OPT_PLANCKA].cName, "dPlanckA");
fvFormattedString(&options[OPT_PLANCKA].cDescr, "Constant 'A' used in OLR calculation");
fvFormattedString(&options[OPT_PLANCKA].cDefault, "203.3");
fvFormattedString(&options[OPT_PLANCKA].cDimension, "nd");
options[OPT_PLANCKA].dDefault = 203.3;
options[OPT_PLANCKA].iType = 2;
options[OPT_PLANCKA].bMultiFile = 1;
Expand Down Expand Up @@ -3331,7 +3332,7 @@ void WriteDailyInsol(BODY *body, CONTROL *control, OUTPUT *output,
SYSTEM *system, UNITS *units, UPDATE *update, int iBody,
double *dTmp, char **cUnit) {

char *cOut;
char *cOut=NULL;
FILE *fp;
int iLat, iDay;
double dTime;
Expand Down Expand Up @@ -3378,13 +3379,14 @@ void WriteDailyInsol(BODY *body, CONTROL *control, OUTPUT *output,
}

fclose(fp);
free(cOut);
}

void WritePlanckB(BODY *body, CONTROL *control, OUTPUT *output, SYSTEM *system,
UNITS *units, UPDATE *update, int iBody, double *dTmp,
char **cUnit) {

char *cOut;
char *cOut=NULL;
FILE *fp;
int iLat, iDay;
double dTime;
Expand Down Expand Up @@ -3432,13 +3434,14 @@ void WritePlanckB(BODY *body, CONTROL *control, OUTPUT *output, SYSTEM *system,
}

fclose(fp);
free(cOut);
}

void WriteSeasonalTemp(BODY *body, CONTROL *control, OUTPUT *output,
SYSTEM *system, UNITS *units, UPDATE *update, int iBody,
double *dTmp, char **cUnit) {

char *cOut;
char *cOut=NULL;
FILE *fp;
int iLat, iDay;
double dTime;
Expand Down Expand Up @@ -3488,13 +3491,14 @@ void WriteSeasonalTemp(BODY *body, CONTROL *control, OUTPUT *output,
}

fclose(fp);
free(cOut);
}

void WriteSeasonalFluxes(BODY *body, CONTROL *control, OUTPUT *output,
SYSTEM *system, UNITS *units, UPDATE *update,
int iBody, double *dTmp, char **cUnit) {

char *cOutM, *cOutI, *cOutO, *cOutD;
char *cOutM=NULL, *cOutI=NULL, *cOutO=NULL, *cOutD=NULL;
FILE *fpM, *fpI, *fpO, *fpD;
int iLat, iDay;
double dTime;
Expand Down Expand Up @@ -3584,13 +3588,17 @@ void WriteSeasonalFluxes(BODY *body, CONTROL *control, OUTPUT *output,
fclose(fpI);
fclose(fpO);
fclose(fpD);
free(cOutM);
free(cOutI);
free(cOutO);
free(cOutD);
}

void WriteSeasonalIceBalance(BODY *body, CONTROL *control, OUTPUT *output,
SYSTEM *system, UNITS *units, UPDATE *update,
int iBody, double *dTmp, char **cUnit) {

char *cOut;
char *cOut=NULL;
FILE *fp;
int iLat, iDay;
double dTime;
Expand Down Expand Up @@ -3637,6 +3645,7 @@ void WriteSeasonalIceBalance(BODY *body, CONTROL *control, OUTPUT *output,
}

fclose(fp);
free(cOut);
}

void WriteFluxMerid(BODY *body, CONTROL *control, OUTPUT *output,
Expand Down
1 change: 0 additions & 1 deletion src/vplanet.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ We need this wrapper so we can call `main_impl` from Python.
int main_impl(int argc, char *argv[]) {
#ifdef DEBUG
#ifdef __x86_64__
// feenableexcept(FE_INVALID | FE_OVERFLOW);
_MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() & ~_MM_MASK_INVALID);
_MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() & ~_MM_MASK_OVERFLOW);
_MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() & ~_MM_MASK_DIV_ZERO);
Expand Down
2 changes: 1 addition & 1 deletion tests/Help/test_Help.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

def test_Help():
try:
subprocess.check_output("bin/vplanet -H", shell=True)
subprocess.check_output("../../bin/vplanet -H", shell=True)
except subprocess.CalledProcessError:
raise ValueError(f"Long help failed")
else:
Expand Down

0 comments on commit 74609fc

Please sign in to comment.