1
0
mirror of https://git.zap.org.au/git/trader.git synced 2024-11-03 17:27:29 -05:00

Replace "out of memory" errors with calls to err_exit_nomem()

This commit is contained in:
John Zaitseff 2011-07-19 19:16:34 +10:00
parent 7bfdcff969
commit ccbe7405f8
7 changed files with 42 additions and 26 deletions

View File

@ -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 :

View File

@ -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)];

View File

@ -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

View File

@ -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';

View File

@ -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,

View File

@ -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)

View File

@ -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