Return error messages as 'const char *', not 'char *'.

They're never dynamically allocated, and are almost always string
literals, so const is more appropriate.
This commit is contained in:
Simon Tatham
2017-10-01 13:53:24 +01:00
parent de67801b0f
commit b3243d7504
52 changed files with 266 additions and 231 deletions

View File

@ -1002,7 +1002,7 @@ void print(frontend *fe)
document *doc;
midend *nme = NULL; /* non-interactive midend for bulk puzzle generation */
int i;
char *err = NULL;
const char *err = NULL;
/*
* Create our document structure and fill it up with puzzles.
@ -1586,7 +1586,7 @@ static midend *midend_for_new_game(frontend *fe, const game *cgame,
midend_new_game(me);
} else {
FILE *fp;
char *err_param, *err_load;
const char *err_param, *err_load;
/*
* See if arg is a valid filename of a save game file.
@ -2103,7 +2103,8 @@ static config_item *frontend_get_config(frontend *fe, int which,
}
}
static char *frontend_set_config(frontend *fe, int which, config_item *cfg)
static const char *frontend_set_config(
frontend *fe, int which, config_item *cfg)
{
if (which < CFG_FRONTEND_SPECIFIC) {
return midend_set_config(fe->me, which, cfg);
@ -2276,7 +2277,8 @@ static int CALLBACK ConfigDlgProc(HWND hwnd, UINT msg,
*/
if ((LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)) {
if (LOWORD(wParam) == IDOK) {
char *err = frontend_set_config(fe, fe->cfg_which, fe->cfg);
const char *err = frontend_set_config(
fe, fe->cfg_which, fe->cfg);
if (err) {
MessageBox(hwnd, err, "Validation error",
@ -3015,7 +3017,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
break;
case IDM_SOLVE:
{
char *msg = midend_solve(fe->me);
const char *msg = midend_solve(fe->me);
if (msg)
MessageBox(hwnd, msg, "Unable to solve",
MB_ICONERROR | MB_OK);
@ -3107,7 +3109,8 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
fclose(fp);
} else {
FILE *fp = fopen(filename, "r");
char *err = NULL;
const char *err = NULL;
char *err_w = NULL;
midend *me = fe->me;
#ifdef COMBINED
char *id_name;
@ -3135,7 +3138,8 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
"supported by this program";
} else {
me = midend_for_new_game(fe, gamelist[i], NULL,
FALSE, FALSE, &err);
FALSE, FALSE, &err_w);
err = err_w;
rewind(fp); /* for the actual load */
}
sfree(id_name);
@ -3148,6 +3152,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
if (err) {
MessageBox(hwnd, err, "Error", MB_ICONERROR|MB_OK);
sfree(err_w);
break;
}