diff --git a/src/exch.c b/src/exch.c index 6054472..68e9dcb 100644 --- a/src/exch.c +++ b/src/exch.c @@ -92,7 +92,7 @@ void exchange_stock (void) } else { char *buf = malloc(BUFSIZE); if (buf == NULL) { - err_exit("out of memory"); + err_exit_nomem(); } // Handle the locale's currency symbol @@ -245,7 +245,7 @@ void visit_bank (void) buf = malloc(BUFSIZE); if (buf == NULL) { - err_exit("out of memory"); + err_exit_nomem(); } credit_limit = (total_value(current_player) - player[current_player].debt) @@ -481,7 +481,7 @@ void trade_shares (int num, bool *bid_used) buf = malloc(BUFSIZE); if (buf == NULL) { - err_exit("out of memory"); + err_exit_nomem(); } ownership = (company[num].stock_issued == 0) ? 0.0 : diff --git a/src/fileio.c b/src/fileio.c index fb80f49..92ad89f 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -96,7 +96,7 @@ static const int game_file_crypt_key[] = { \ s = malloc(strlen(buf) + 1); \ if (s == NULL) { \ - err_exit("out of memory"); \ + err_exit_nomem(); \ } \ \ strcpy(s, buf); \ @@ -159,7 +159,7 @@ bool load_game (int num) buf = malloc(BUFSIZE); if (buf == NULL) { - err_exit("out of memory"); + err_exit_nomem(); } filename = game_filename(num); @@ -326,7 +326,7 @@ bool save_game (int num) buf = malloc(BUFSIZE); if (buf == NULL) { - err_exit("out of memory"); + err_exit_nomem(); } crypt_key = game_file_crypt_key[randi(GAME_FILE_CRYPT_KEY_SIZE)]; diff --git a/src/game.c b/src/game.c index d680679..cc98f7b 100644 --- a/src/game.c +++ b/src/game.c @@ -434,7 +434,7 @@ void end_game (void) buf = malloc(BUFSIZE); if (buf == NULL) { - err_exit("out of memory"); + err_exit_nomem(); } newtxwin(7, 40, LINE_OFFSET + 9, COL_CENTER(40)); @@ -554,7 +554,7 @@ void show_map (bool closewin) char *buf = malloc(BUFSIZE); if (buf == NULL) { - err_exit("out of memory"); + err_exit_nomem(); } int len1 = strlen(initial); @@ -659,7 +659,7 @@ void show_status (int num) } else { char *buf = malloc(BUFSIZE); if (buf == NULL) { - err_exit("out of memory"); + err_exit_nomem(); } // Check to see if any companies are on the map diff --git a/src/intf.c b/src/intf.c index 4511482..222076a 100644 --- a/src/intf.c +++ b/src/intf.c @@ -318,7 +318,7 @@ int center (WINDOW *win, int y, int attr, const char *format, ...) buf = malloc(BUFSIZE); if (buf == NULL) { - err_exit("out of memory"); + err_exit_nomem(); } oldattr = getbkgd(win) & ~A_CHARTEXT; @@ -374,7 +374,7 @@ int center2 (WINDOW *win, int y, int attr_initial, int attr_string, buf = malloc(BUFSIZE); if (buf == NULL) { - err_exit("out of memory"); + err_exit_nomem(); } oldattr = getbkgd(win) & ~A_CHARTEXT; @@ -438,7 +438,7 @@ int center3 (WINDOW *win, int y, int attr_initial, int attr_final, buf = malloc(BUFSIZE); if (buf == NULL) { - err_exit("out of memory"); + err_exit_nomem(); } oldattr = getbkgd(win) & ~A_CHARTEXT; @@ -1250,7 +1250,7 @@ int gettxstring (WINDOW *win, char **bufptr, bool multifield, int y, int x, if (*bufptr == NULL) { *bufptr = malloc(BUFSIZE); if (*bufptr == NULL) { - err_exit("out of memory"); + err_exit_nomem(); } **bufptr = '\0'; @@ -1303,27 +1303,27 @@ int gettxdouble (WINDOW *win, double *result, double min, double max, buf = malloc(BUFSIZE); if (buf == NULL) { - err_exit("out of memory"); + err_exit_nomem(); } buf_copy = malloc(BUFSIZE); if (buf_copy == NULL) { - err_exit("out of memory"); + err_exit_nomem(); } allowed = malloc(BUFSIZE); if (allowed == NULL) { - err_exit("out of memory"); + err_exit_nomem(); } emptystr = malloc(BUFSIZE); if (emptystr == NULL) { - err_exit("out of memory"); + err_exit_nomem(); } defaultstr = malloc(BUFSIZE); if (defaultstr == NULL) { - err_exit("out of memory"); + err_exit_nomem(); } *buf = '\0'; @@ -1443,27 +1443,27 @@ int gettxlong (WINDOW *win, long *result, long min, long max, long emptyval, buf = malloc(BUFSIZE); if (buf == NULL) { - err_exit("out of memory"); + err_exit_nomem(); } buf_copy = malloc(BUFSIZE); if (buf_copy == NULL) { - err_exit("out of memory"); + err_exit_nomem(); } allowed = malloc(BUFSIZE); if (allowed == NULL) { - err_exit("out of memory"); + err_exit_nomem(); } emptystr = malloc(BUFSIZE); if (emptystr == NULL) { - err_exit("out of memory"); + err_exit_nomem(); } defaultstr = malloc(BUFSIZE); if (defaultstr == NULL) { - err_exit("out of memory"); + err_exit_nomem(); } *buf = '\0'; diff --git a/src/move.c b/src/move.c index 83d23fd..3c7ae24 100644 --- a/src/move.c +++ b/src/move.c @@ -755,7 +755,7 @@ void merge_companies (map_val_t a, map_val_t b) char *buf = malloc(BUFSIZE); if (buf == NULL) { - err_exit("out of memory"); + err_exit_nomem(); } @@ -965,7 +965,7 @@ void adjust_values (void) buf = malloc(BUFSIZE); if (buf == NULL) { - err_exit("out of memory"); + err_exit_nomem(); } for (i = 0; i < number_players; i++) { @@ -1081,7 +1081,7 @@ void adjust_values (void) buf = malloc(BUFSIZE); if (buf == NULL) { - err_exit("out of memory"); + err_exit_nomem(); } impounded = MIN(player[current_player].cash, diff --git a/src/utils.c b/src/utils.c index 9534519..222a6e1 100644 --- a/src/utils.c +++ b/src/utils.c @@ -261,6 +261,20 @@ void errno_exit (const char *format, ...) } +/*----------------------------------------------------------------------- + Function: err_exit_nomem - Print an "out of memory" error and exit + Arguments: (none) + Returns: (does not return) + + This function calls err_exit with an "out of memory" error message. +*/ + +void err_exit_nomem (void) +{ + err_exit("out of memory"); +} + + /*----------------------------------------------------------------------- Function: init_rand - Initialise the random number generator Arguments: (none) diff --git a/src/utils.h b/src/utils.h index a87dc80..3a44445 100644 --- a/src/utils.h +++ b/src/utils.h @@ -70,6 +70,8 @@ extern void err_exit (const char *format, ...) __attribute__((noreturn, format (printf, 1, 2))); extern void errno_exit (const char *format, ...) __attribute__((noreturn, format (printf, 1, 2))); +extern void err_exit_nomem (void) + __attribute__((noreturn)); // Random number functions