From 8450e74b5bd7f23c8bda95d8e0c16f83f058a8d4 Mon Sep 17 00:00:00 2001 From: Rory Barnes Date: Thu, 5 Sep 2024 13:13:43 -0700 Subject: [PATCH] Added error handling for reading in options. Forced setup.py to include VERSION. --- setup.py | 1 + src/options.c | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 5962f534b..3c2dab6d9 100644 --- a/setup.py +++ b/setup.py @@ -93,6 +93,7 @@ def run(self): ext_modules=ext_modules, cmdclass=cmdclass, include_package_data=True, + data_files=[('', ['VERSION'])], zip_safe=False, entry_points={"console_scripts": ["vplanet=vplanet.wrapper:_entry_point"]}, ) diff --git a/src/options.c b/src/options.c index 17b3409f8..d4fc8e10f 100644 --- a/src/options.c +++ b/src/options.c @@ -343,7 +343,12 @@ void AddOptionDouble(char *cFile, char *cOption, double *dInput, int *iLine, GetLine(cFile, cOption, &cLine, iLine, iVerbose); if (*iLine >= 0) { - sscanf(cLine, "%s %lf", cTmp, dInput); + int iNumOptionsRead = sscanf(cLine, "%s %lf", cTmp, dInput); + if (iNumOptionsRead != 2) { + printf("ERROR: %d arguments read for option %s.\n",iNumOptionsRead,cOption); + printf("\tcLine=%s, cTmp=%s, dInput=%lf\n", cLine, cTmp, *dInput ); + exit(EXIT_INPUT); + } } free(cLine); } @@ -354,7 +359,12 @@ void AddOptionInt(char *cFile, char *cOption, int *iInput, int *iLine, GetLine(cFile, cOption, &cLine, iLine, iVerbose); if (*iLine >= 0) { - sscanf(cLine, "%s %d", cTmp, iInput); + int iNumOptionsRead = sscanf(cLine, "%s %d", cTmp, iInput); + if (iNumOptionsRead != 2) { + printf("ERROR: %d arguments read for option %s.\n",iNumOptionsRead,cOption); + printf("\tcLine=%s, cTmp=%s, dInput=%d\n", cLine, cTmp, *iInput ); + exit(EXIT_INPUT); + } } free(cLine); } @@ -384,7 +394,12 @@ void AddOptionString(char *cFile, char *cOption, char cInput[], int *iLine, GetLine(cFile, cOption, &cLine, iLine, iVerbose); if (*iLine >= 0) { - sscanf(cLine, "%s %s", cTmp, cInput); + int iNumOptionsRead = sscanf(cLine, "%s %s", cTmp, cInput); + if (iNumOptionsRead != 2) { + printf("ERROR: %d arguments read for option %s.\n",iNumOptionsRead,cOption); + printf("\tcLine=%s, cTmp=%s, dInput=%s\n", cLine, cTmp, cInput ); + exit(EXIT_INPUT); + } } free(cLine); }