<div dir="ltr"><div>Hello,<br><br></div>I read a FIXME in src/main.c talking about missing return values, so I added what was needed to the LoadSettings() function, that didn't check itself the return value of the function it calls. I don't exit the main if it fails as it was the previous behaviour of the program, and not having a setting file isn't a real problem with the use of default values :<br>
<br>From dd9e77ef531c4010e4dddb5859e303d495e40726 Mon Sep 17 00:00:00 2001<br>From: Jerome Portal <<a href="mailto:jerome.portal.2@gmail.com">jerome.portal.2@gmail.com</a>><br>Date: Fri, 12 Apr 2013 15:03:18 +0200<br>
Subject: [PATCH 2/2] Add and check a return value to LoadSettings().<br><br>---<br> src/funcs.h | 2 +-<br> src/main.c | 5 ++++-<br> src/setup.c | 10 ++++++++--<br> 3 files changed, 13 insertions(+), 4 deletions(-)<br>
<br>diff --git a/src/funcs.h b/src/funcs.h<br>index cfe8a73..0a16332 100644<br>--- a/src/funcs.h<br>+++ b/src/funcs.h<br>@@ -108,7 +108,7 @@ void InstructLaser(void);<br> /* In setup.c: */<br> void GraphicsInit(void);<br>
void LibInit(Uint32 lib_flags);<br>-void LoadSettings(void);<br>+int LoadSettings(void);<br> void SaveSettings(void);<br> int SetupPaths(const char* theme_dir);<br> void Cleanup(void);<br>diff --git a/src/main.c b/src/main.c<br>
index 34b2d6c..feb5201 100644<br>--- a/src/main.c<br>+++ b/src/main.c<br>@@ -55,7 +55,10 @@ int main(int argc, char *argv[])<br> fprintf(stderr, "Error - SetupPaths() failed, exiting program.\n");<br> return 0;<br>
} <br>- LoadSettings(); // Second, read saved any saved settings<br>+ if (!LoadSettings()) // Second, read saved any saved settings<br>+ {<br>+ fprintf(stderr, "Warning - LoadSettings() failed, continuing with default settings.\n");<br>
+ }<br> <br> // Third, check command line args as these should override saved settings<br> if (argc > 1) /* FIXME this could go into something like HandleCommandArgs() */<br>diff --git a/src/setup.c b/src/setup.c<br>
index 7e5ca3b..47a5e89 100644<br>--- a/src/setup.c<br>+++ b/src/setup.c<br>@@ -226,7 +226,7 @@ void LibInit(Uint32 lib_flags)<br> /* Load the settings from a file... make sure to update SaveSettings if you change<br> * what can be saved/loaded <br>
*/<br>-void LoadSettings(void)<br>+int LoadSettings(void)<br> {<br> char fn[FNLEN];<br> // char setting[FNLEN];<br>@@ -249,7 +249,13 @@ void LoadSettings(void)<br> <br> LOG("LoadSettings: trying to open settings file\n");<br>
<br>- load_settings_filename(fn);<br>+ if (load_settings_filename(fn) != 1)<br>+ {<br>+ fprintf(stderr, "LoadSettings: Failed to load settings\n");<br>+ return 0;<br>+ }<br>+ <br>+ return 1;<br> }<br>
<br> <br>-- <br>1.7.9.5<br><br></div>