Replaced some uses of sprintf with snprintf.

This commit is contained in:
Julie Marchant 2018-04-21 10:44:33 -04:00
parent 341ef6907a
commit cbdbf94498
2 changed files with 7 additions and 7 deletions

View File

@ -174,25 +174,25 @@ void engine_setupConfigDirectory()
strcpy(dir, ""); strcpy(dir, "");
sprintf(dir, "%s/.config", userHome); snprintf(dir, PATH_MAX, "%s/.config", userHome);
#ifdef _WIN32 #ifdef _WIN32
if ((mkdir(dir) != 0) && (errno != EEXIST)) if ((mkdir(dir) != 0) && (errno != EEXIST))
engine_showError(2, dir); engine_showError(2, dir);
sprintf(dir, "%s/.config/starfighter", userHome); snprintf(dir, PATH_MAX, "%s/.config/starfighter", userHome);
if ((mkdir(dir) != 0) && (errno != EEXIST)) if ((mkdir(dir) != 0) && (errno != EEXIST))
engine_showError(2, dir); engine_showError(2, dir);
#else #else
if ((mkdir(dir, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) != 0) && (errno != EEXIST)) if ((mkdir(dir, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) != 0) && (errno != EEXIST))
engine_showError(2, dir); engine_showError(2, dir);
sprintf(dir, "%s/.config/starfighter", userHome); snprintf(dir, PATH_MAX, "%s/.config/starfighter", userHome);
if ((mkdir(dir, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) != 0) && (errno != EEXIST)) if ((mkdir(dir, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) != 0) && (errno != EEXIST))
engine_showError(2, dir); engine_showError(2, dir);
#endif #endif
sprintf(engine.configDirectory, "%s/.config/starfighter/", userHome); snprintf(engine.configDirectory, PATH_MAX, "%s/.config/starfighter/", userHome);
} }
/* /*
@ -218,7 +218,7 @@ void engine_setMode()
int autoPause = 0; int autoPause = 0;
FILE *fp; FILE *fp;
sprintf(filename, "%sconf", engine.configDirectory); snprintf(filename, PATH_MAX, "%sconf", engine.configDirectory);
fp = fopen(filename, "r"); fp = fopen(filename, "r");
if (fp != NULL) if (fp != NULL)
@ -382,7 +382,7 @@ void engine_cleanup()
// Save the config using current settings // Save the config using current settings
FILE *fp; FILE *fp;
sprintf(filename, "%sconf", engine.configDirectory); snprintf(filename, PATH_MAX, "%sconf", engine.configDirectory);
fp = fopen(filename, "w"); fp = fopen(filename, "w");
if (fp != NULL) if (fp != NULL)
{ {

View File

@ -91,7 +91,7 @@ typedef struct Engine_ {
int fullScreen; int fullScreen;
int autoPause; int autoPause;
char configDirectory[1024]; char configDirectory[PATH_MAX];
char keyState[KEY_LAST]; char keyState[KEY_LAST];