home
·
contact
·
privacy
projects
/
plomrogue
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
483f257
)
Test return values of _all_ *printf() calls.
author
Christian Heller
<c.heller@plomlompom.de>
Wed, 9 Jul 2014 19:45:51 +0000
(21:45 +0200)
committer
Christian Heller
<c.heller@plomlompom.de>
Wed, 9 Jul 2014 19:45:51 +0000
(21:45 +0200)
15 files changed:
TODO
patch
|
blob
|
history
src/client/control.c
patch
|
blob
|
history
src/client/draw_wins.c
patch
|
blob
|
history
src/client/io.c
patch
|
blob
|
history
src/client/keybindings.c
patch
|
blob
|
history
src/client/main.c
patch
|
blob
|
history
src/client/wincontrol.c
patch
|
blob
|
history
src/client/windows.c
patch
|
blob
|
history
src/common/readwrite.c
patch
|
blob
|
history
src/common/rexit.c
patch
|
blob
|
history
src/server/init.c
patch
|
blob
|
history
src/server/io.c
patch
|
blob
|
history
src/server/run.c
patch
|
blob
|
history
src/server/thing_actions.c
patch
|
blob
|
history
src/server/things.c
patch
|
blob
|
history
diff --git
a/TODO
b/TODO
index a5a87c34fd62b8bbd2130eb55e35226ee91d0843..8ba459243520e95c96b518152f2895f08e5469c0 100644
(file)
--- a/
TODO
+++ b/
TODO
@@
-2,8
+2,6
@@
Next planned steps in plomrogue development:
IN GENERAL:
IN GENERAL:
-- check for return values of *printf()
-
- expand use of hardcoded_strings module(s)
BOTH SERVER/CLIENT:
- expand use of hardcoded_strings module(s)
BOTH SERVER/CLIENT:
diff --git
a/src/client/control.c
b/src/client/control.c
index f97f5bdcffe0b8a8e0a4ef2f70e5792af4dd5d93..02e4fed2360bf8fda263b7b4f54ef0b1eda7733d 100644
(file)
--- a/
src/client/control.c
+++ b/
src/client/control.c
@@
-5,7
+5,7
@@
#include <stdlib.h> /* free() */
#include <stdio.h> /* sprintf() */
#include <string.h> /* strlen() */
#include <stdlib.h> /* free() */
#include <stdio.h> /* sprintf() */
#include <string.h> /* strlen() */
-#include "../common/rexit.h" /* exit_err() */
+#include "../common/rexit.h" /* exit_err()
, exit_trouble()
*/
#include "../common/try_malloc.h" /* try_malloc() */
#include "interface_conf.h" /* reload_interface_conf(), save_interface_conf() */
#include "io.h" /* send() */
#include "../common/try_malloc.h" /* try_malloc() */
#include "interface_conf.h" /* reload_interface_conf(), save_interface_conf() */
#include "io.h" /* send() */
@@
-169,7
+169,8
@@
static uint8_t try_server_commands(struct Command * command)
uint8_t command_size = strlen(command->server_msg);
uint8_t arg_size = 3;
char * msg = try_malloc(command_size + 1 + arg_size + 1, f_name);
uint8_t command_size = strlen(command->server_msg);
uint8_t arg_size = 3;
char * msg = try_malloc(command_size + 1 + arg_size + 1, f_name);
- sprintf(msg, "%s %d", command->server_msg, arg);
+ int test = sprintf(msg, "%s %d", command->server_msg, arg);
+ exit_trouble(test < 0, f_name, "sprintf()");
send(msg);
free(msg);
return 1;
send(msg);
free(msg);
return 1;
diff --git
a/src/client/draw_wins.c
b/src/client/draw_wins.c
index b6a9c3e4506f94b69767363198534b7df5fac83f..f6ac7e293cb2ba9d5a415209878efc8800336416 100644
(file)
--- a/
src/client/draw_wins.c
+++ b/
src/client/draw_wins.c
@@
-8,7
+8,7
@@
#include <stdio.h> /* sprintf() */
#include <stdlib.h> /* free() */
#include <string.h> /* memset(), strchr(), strdup/(), strlen() */
#include <stdio.h> /* sprintf() */
#include <stdlib.h> /* free() */
#include <string.h> /* memset(), strchr(), strdup/(), strlen() */
-#include "../common/rexit.h" /* exit_err() */
+#include "../common/rexit.h" /* exit_err()
, exit_trouble()
*/
#include "../common/try_malloc.h" /* try_malloc() */
#include "keybindings.h" /* struct KeyBindingDB, get_keyname_to_keycode() */
#include "windows.h" /* yx_uint16, Win, get_win_by_id() */
#include "../common/try_malloc.h" /* try_malloc() */
#include "keybindings.h" /* struct KeyBindingDB, get_keyname_to_keycode() */
#include "windows.h" /* yx_uint16, Win, get_win_by_id() */
@@
-185,7
+185,8
@@
static void add_line_compact(struct Win * win, char * line, attr_t attri,
char * separator = last ? "" : " / ";
uint32_t len_line_new = len_line + strlen(separator);
char * line_new = try_malloc(len_line_new, f_name);
char * separator = last ? "" : " / ";
uint32_t len_line_new = len_line + strlen(separator);
char * line_new = try_malloc(len_line_new, f_name);
- sprintf(line_new, "%s%s", line, separator);
+ int test = sprintf(line_new, "%s%s", line, separator);
+ exit_trouble(test < 0, f_name, "sprintf()");
uint16_t x = 0;
uint16_t y;
uint32_t z;
uint16_t x = 0;
uint16_t y;
uint32_t z;
@@
-263,7
+264,8
@@
static char * get_kb_line(struct KeyBinding * kb)
char * keyname = get_keyname_to_keycode(kb->keycode);
uint16_t size = strlen(keyname) + 3 + strlen(kb->command->dsc_long) + 1;
char * kb_line = try_malloc(size, f_name);
char * keyname = get_keyname_to_keycode(kb->keycode);
uint16_t size = strlen(keyname) + 3 + strlen(kb->command->dsc_long) + 1;
char * kb_line = try_malloc(size, f_name);
- sprintf(kb_line, "%s - %s", keyname, kb->command->dsc_long);
+ int test = sprintf(kb_line, "%s - %s", keyname, kb->command->dsc_long);
+ exit_trouble(test < 0, f_name, "sprintf()");
free(keyname);
return kb_line;
}
free(keyname);
return kb_line;
}
@@
-362,8
+364,9
@@
extern void draw_win_info(struct Win * win)
char * dsc_hitpoints = "\nHitpoints: ";
uint16_t maxl = strlen(dsc_turn) + 5 + strlen(dsc_hitpoints) + 3;
char * text = try_malloc(maxl + 1, f_name);
char * dsc_hitpoints = "\nHitpoints: ";
uint16_t maxl = strlen(dsc_turn) + 5 + strlen(dsc_hitpoints) + 3;
char * text = try_malloc(maxl + 1, f_name);
- sprintf(text, "%s%d%s%d",
- dsc_turn, world.turn, dsc_hitpoints, world.player_lifepoints);
+ int test = sprintf(text, "%s%d%s%d", dsc_turn, world.turn, dsc_hitpoints,
+ world.player_lifepoints);
+ exit_trouble(test < 0, f_name, "sprintf()");
add_text_with_linebreaks(win, text);
free(text);
}
add_text_with_linebreaks(win, text);
free(text);
}
@@
-463,13
+466,15
@@
extern void draw_winconf_geometry(struct Win * win)
char * title = "Window's geometry:\n\n";
char * h_title = "Height to save: ";
char h_value[6 + 1]; /* 6: int16_t value max strlen */
char * title = "Window's geometry:\n\n";
char * h_title = "Height to save: ";
char h_value[6 + 1]; /* 6: int16_t value max strlen */
- sprintf(h_value, "%d", win->target_height);
+ int test = sprintf(h_value, "%d", win->target_height);
+ exit_trouble(test < 0, f_name, "sprintf()");
char * h_plus = " (width in cells)\n\n";
char * h_minus = " (negative diff: cells to screen width)\n\n";
char * h_type = (1 == win->target_height_type) ? h_minus : h_plus;
char * w_title = "Width to save: ";
char w_value[6 + 1];
char * h_plus = " (width in cells)\n\n";
char * h_minus = " (negative diff: cells to screen width)\n\n";
char * h_type = (1 == win->target_height_type) ? h_minus : h_plus;
char * w_title = "Width to save: ";
char w_value[6 + 1];
- sprintf(w_value, "%d", win->target_width);
+ test = sprintf(w_value, "%d", win->target_width);
+ exit_trouble(test < 0, f_name, "sprintf()");
char * w_plus = "(height in cells)\n\n";
char * w_minus = " (negative diff: cells to screen height)\n\n";
char * w_type = (1 == win->target_width_type) ? w_minus : w_plus;
char * w_plus = "(height in cells)\n\n";
char * w_minus = " (negative diff: cells to screen height)\n\n";
char * w_type = (1 == win->target_width_type) ? w_minus : w_plus;
@@
-481,8
+486,9
@@
extern void draw_winconf_geometry(struct Win * win)
+ strlen(w_title) + strlen(w_value) + strlen(w_type)
+ strlen(breaks_title) + strlen(breaks_type);
char * text = try_malloc(text_size + 1, f_name);
+ strlen(w_title) + strlen(w_value) + strlen(w_type)
+ strlen(breaks_title) + strlen(breaks_type);
char * text = try_malloc(text_size + 1, f_name);
- sprintf(text, "%s%s%s%s%s%s%s%s%s", title, h_title, h_value, h_type,
- w_title, w_value, w_type, breaks_title, breaks_type);
+ test = sprintf(text, "%s%s%s%s%s%s%s%s%s", title, h_title, h_value, h_type,
+ w_title, w_value, w_type, breaks_title, breaks_type);
+ exit_trouble(test < 0, f_name, "sprintf()");
add_text_with_linebreaks(win, text);
free(text);
}
add_text_with_linebreaks(win, text);
free(text);
}
diff --git
a/src/client/io.c
b/src/client/io.c
index 31387f26d8466aeade7e293d2be5d06b0937aad2..c047f6985d3f9526cc45eb4fa845be77ad9677e2 100644
(file)
--- a/
src/client/io.c
+++ b/
src/client/io.c
@@
-106,7
+106,8
@@
static void read_inventory(char * read_buf, uint32_t linemax, FILE * file)
int new_size = strlen(read_buf);
char * new_inventory = try_malloc(old_size + new_size + 1, f_name);
memcpy(new_inventory, world.player_inventory, old_size);
int new_size = strlen(read_buf);
char * new_inventory = try_malloc(old_size + new_size + 1, f_name);
memcpy(new_inventory, world.player_inventory, old_size);
- sprintf(new_inventory + old_size, "%s", read_buf);
+ int test = sprintf(new_inventory + old_size, "%s", read_buf);
+ exit_trouble(test < 0, f_name, "sprintf()");
free(world.player_inventory);
world.player_inventory = new_inventory;
}
free(world.player_inventory);
world.player_inventory = new_inventory;
}
@@
-150,7
+151,8
@@
static void read_log(char * read_buf, uint32_t linemax, FILE * file)
int new_size = strlen(read_buf);
char * new_log = try_malloc(old_size + new_size + 1, f_name);
memcpy(new_log, world.log, old_size);
int new_size = strlen(read_buf);
char * new_log = try_malloc(old_size + new_size + 1, f_name);
memcpy(new_log, world.log, old_size);
- sprintf(new_log + old_size, "%s", read_buf);
+ int test = sprintf(new_log + old_size, "%s", read_buf);
+ exit_trouble(test < 0, f_name, "sprintf()");
free(world.log);
world.log = new_log;
}
free(world.log);
world.log = new_log;
}
diff --git
a/src/client/keybindings.c
b/src/client/keybindings.c
index 4231da492531cf8a832f5e5bc817a8427e724682..b0b7c7a06fc496ee5cb9baa5cd5af8c70632d14a 100644
(file)
--- a/
src/client/keybindings.c
+++ b/
src/client/keybindings.c
@@
-5,6
+5,7
@@
#include <stddef.h> /* NULL */
#include <stdint.h> /* uint8_t, uint16_t, uint32_t */
#include <stdio.h> /* FILE, sprintf() */
#include <stddef.h> /* NULL */
#include <stdint.h> /* uint8_t, uint16_t, uint32_t */
#include <stdio.h> /* FILE, sprintf() */
+#include "../common/rexit.h" /* exit_trouble() */
#include "../common/try_malloc.h" /* try_malloc() */
#include "windows.h" /* draw_all_wins() */
#include "world.h" /* global world */
#include "../common/try_malloc.h" /* try_malloc() */
#include "windows.h" /* draw_all_wins() */
#include "world.h" /* global world */
@@
-49,9
+50,11
@@
static struct KeyBindingDB * char_selected_kb_db(char c)
static uint8_t try_keycode(uint16_t keycode_given, char * keyname,
uint16_t keycode_match, char * keyname_match)
{
static uint8_t try_keycode(uint16_t keycode_given, char * keyname,
uint16_t keycode_match, char * keyname_match)
{
+ char * f_name = "try_keycode()";
if (keycode_given == keycode_match)
{
if (keycode_given == keycode_match)
{
- sprintf(keyname, "%s", keyname_match);
+ int test = sprintf(keyname, "%s", keyname_match);
+ exit_trouble(test < 0, f_name, "sprintf()");
return 1;
}
return 0;
return 1;
}
return 0;
@@
-81,12
+84,12
@@
extern char * get_keyname_to_keycode(uint16_t keycode)
char * keyname = try_malloc(10, f_name); /* max keyname length + 1 */
if (32 < keycode && keycode < 127)
{
char * keyname = try_malloc(10, f_name); /* max keyname length + 1 */
if (32 < keycode && keycode < 127)
{
-
sprintf(keyname, "%c", keycode
);
+
exit_trouble(sprintf(keyname, "%c", keycode) < 0, f_name, "sprintf()"
);
}
else if (keycode >= KEY_F0 && keycode <= KEY_F(63))
{
uint16_t f = keycode - KEY_F0;
}
else if (keycode >= KEY_F0 && keycode <= KEY_F(63))
{
uint16_t f = keycode - KEY_F0;
-
sprintf(keyname, "F%d", f)
;
+
exit_trouble(sprintf(keyname, "F%d", f) < 0, f_name, "sprintf()");
;
}
else if ( try_keycode(keycode, keyname, 9, "TAB")
|| try_keycode(keycode, keyname, 10, "RETURN")
}
else if ( try_keycode(keycode, keyname, 9, "TAB")
|| try_keycode(keycode, keyname, 10, "RETURN")
@@
-108,7
+111,7
@@
extern char * get_keyname_to_keycode(uint16_t keycode)
}
else
{
}
else
{
-
sprintf(keyname, "(unknown
)");
+
exit_trouble(sprintf(keyname, "(unknown)") < 0, f_name, "sprintf(
)");
}
return keyname;
}
}
return keyname;
}
diff --git
a/src/client/main.c
b/src/client/main.c
index f2051a41ddb10956903887653aa798569fee48e3..344df6911aa9d19536c5bfdae8c4876df73b0d13 100644
(file)
--- a/
src/client/main.c
+++ b/
src/client/main.c
@@
-72,6
+72,6
@@
int main(int argc, char * argv[])
/* Leave properly. */
cleanup();
/* Leave properly. */
cleanup();
-
printf("%s\n", quit_msg
);
+
exit_trouble(printf("%s\n", quit_msg) < 0, f_name, "printf()"
);
exit(EXIT_SUCCESS);
}
exit(EXIT_SUCCESS);
}
diff --git
a/src/client/wincontrol.c
b/src/client/wincontrol.c
index e1a4fbd485a9dd0df65326f6d6d03b2966ee0934..c42516fd1f895180a68ebb89d7b91c27292a05ad 100644
(file)
--- a/
src/client/wincontrol.c
+++ b/
src/client/wincontrol.c
@@
-7,7
+7,7
@@
#include <stdio.h> /* sprintf() */
#include <stdlib.h> /* free() */
#include <string.h> /* memcpy(), memset(), strchr(), strlen() */
#include <stdio.h> /* sprintf() */
#include <stdlib.h> /* free() */
#include <string.h> /* memcpy(), memset(), strchr(), strlen() */
-#include "../common/rexit.h" /* exit_err() */
+#include "../common/rexit.h" /* exit_err()
, exit_trouble()
*/
#include "../common/try_malloc.h" /* try_malloc() */
#include "windows.h" /* Win,yx_uint16, get_win_by_id(),get_win_pos_in_order() */
#include "world.h" /* global world */
#include "../common/try_malloc.h" /* try_malloc() */
#include "windows.h" /* Win,yx_uint16, get_win_by_id(),get_win_pos_in_order() */
#include "world.h" /* global world */
@@
-200,7
+200,8
@@
static void suspend_win(struct Win * w)
char next_char = world.winDB.order[i + 1];
world.winDB.order[i] = '\0';
char * second_part = &world.winDB.order[i + 1];
char next_char = world.winDB.order[i + 1];
world.winDB.order[i] = '\0';
char * second_part = &world.winDB.order[i + 1];
- sprintf(new_order, "%s%s", world.winDB.order, second_part);
+ int test = sprintf(new_order, "%s%s", world.winDB.order, second_part);
+ exit_trouble(test < 0, f_name, "sprintf()");
free(world.winDB.order);
world.winDB.order = new_order;
world.winDB.active = world.winDB.order[i];
free(world.winDB.order);
world.winDB.order = new_order;
world.winDB.active = world.winDB.order[i];
diff --git
a/src/client/windows.c
b/src/client/windows.c
index 7327fc246f5ff8d939a425fee458bd120c60aee9..0fee3e3d5c2f19938ece7c208b4393f89d164d87 100644
(file)
--- a/
src/client/windows.c
+++ b/
src/client/windows.c
@@
-147,6
+147,8
@@
static char get_next_win_id()
static void scroll_hint(struct yx_uint16 fsize, char dir, uint16_t dist,
char * unit, struct yx_uint16 start)
{
static void scroll_hint(struct yx_uint16 fsize, char dir, uint16_t dist,
char * unit, struct yx_uint16 start)
{
+ char * f_name = "sprintf()";
+
/* Decide on alignment (vertical/horizontal?), thereby hint text space. */
char * more = "more";
uint16_t dsc_space = fsize.x;
/* Decide on alignment (vertical/horizontal?), thereby hint text space. */
char * more = "more";
uint16_t dsc_space = fsize.x;
@@
-155,8
+157,9
@@
static void scroll_hint(struct yx_uint16 fsize, char dir, uint16_t dist,
dsc_space = fsize.y;
} /* vv-- 10 = max strlen for uint16_t */
uint16_t size = 1 + strlen(more) + 1 + 10 + 1 + strlen(unit) + 1 + 1;
dsc_space = fsize.y;
} /* vv-- 10 = max strlen for uint16_t */
uint16_t size = 1 + strlen(more) + 1 + 10 + 1 + strlen(unit) + 1 + 1;
- char * scrolldsc = try_malloc(size, "scroll_hint()");
- sprintf(scrolldsc, " %d %s %s ", dist, more, unit);
+ char * scrolldsc = try_malloc(size, f_name);
+ int test = sprintf(scrolldsc, " %d %s %s ", dist, more, unit);
+ exit_trouble(test < 0, f_name, "sprintf()");
/* Decide on offset of the description text inside the scroll hint line. */
uint16_t dsc_offset = 1;
/* Decide on offset of the description text inside the scroll hint line. */
uint16_t dsc_offset = 1;
@@
-210,8
+213,6
@@
static void winscroll_hint(struct Win * w, char dir, uint16_t dist)
static void draw_win_borderlines(struct Win * w)
{
static void draw_win_borderlines(struct Win * w)
{
- char * f_name = "draw_win_borderlines()";
-
/* Draw vertical and horizontal border lines. */
uint16_t y, x;
for (y = w->start.y; y <= w->start.y + w->frame_size.y; y++)
/* Draw vertical and horizontal border lines. */
uint16_t y, x;
for (y = w->start.y; y <= w->start.y + w->frame_size.y; y++)
@@
-235,7
+236,7
@@
static void draw_win_borderlines(struct Win * w)
offset = (w->frame_size.x - (strlen(w->title) + 2)) / 2;
} /* +2 is for padding/decoration */
uint16_t length_visible = strnlen(w->title, w->frame_size.x - 2);
offset = (w->frame_size.x - (strlen(w->title) + 2)) / 2;
} /* +2 is for padding/decoration */
uint16_t length_visible = strnlen(w->title, w->frame_size.x - 2);
- char * title = try_malloc(length_visible + 3,
f_name
);
+ char * title = try_malloc(length_visible + 3,
"draw_win_borderlines()"
);
char decoration = ' ';
if (w->id == world.winDB.active)
{
char decoration = ' ';
if (w->id == world.winDB.active)
{
@@
-441,7
+442,8
@@
extern void reset_windows_on_winch()
endwin(); /* "[S]tandard way" to recalibrate ncurses post SIGWINCH, says */
refresh(); /* <http://invisible-island.net/ncurses/ncurses-intro.html>. */
char * tmp_order = try_malloc(strlen(world.winDB.order) + 1, f_name);
endwin(); /* "[S]tandard way" to recalibrate ncurses post SIGWINCH, says */
refresh(); /* <http://invisible-island.net/ncurses/ncurses-intro.html>. */
char * tmp_order = try_malloc(strlen(world.winDB.order) + 1, f_name);
- sprintf(tmp_order, "%s", world.winDB.order);
+ int test = sprintf(tmp_order, "%s", world.winDB.order);
+ exit_trouble(test < 0, f_name, "sprintf()");
uint8_t i;
char tmp_active = world.winDB.active;
for (i = 0; i < strlen(tmp_order); toggle_window(tmp_order[i]), i++);
uint8_t i;
char tmp_active = world.winDB.active;
for (i = 0; i < strlen(tmp_order); toggle_window(tmp_order[i]), i++);
diff --git
a/src/common/readwrite.c
b/src/common/readwrite.c
index abc8ca82b36ab8928c60804412934664a272c1c7..c27e86143bc7feb5ff0471df654f70ff960d4a33 100644
(file)
--- a/
src/common/readwrite.c
+++ b/
src/common/readwrite.c
@@
-24,7
+24,8
@@
extern FILE * try_fopen(char * path, char * mode, char * f)
uint16_t size = strlen(msg1) + strlen(msg2) + strlen(msg3) + strlen(msg4)
+ strlen(f) + strlen(path) + strlen(mode) + 1;
char * msg = try_malloc(size, f_name);
uint16_t size = strlen(msg1) + strlen(msg2) + strlen(msg3) + strlen(msg4)
+ strlen(f) + strlen(path) + strlen(mode) + 1;
char * msg = try_malloc(size, f_name);
- sprintf(msg, "%s%s%s%s%s%s%s", msg1, f, msg2, mode, msg3, path, msg4);
+ int test = sprintf(msg, "%s%s%s%s%s%s%s", msg1,f,msg2,mode,msg3,path,msg4);
+ exit_trouble(test < 0, f_name, "sprintf()");
FILE * file_p = fopen(path, mode);
exit_err(NULL == file_p, msg);
free(msg);
FILE * file_p = fopen(path, mode);
exit_err(NULL == file_p, msg);
free(msg);
@@
-87,7
+88,8
@@
extern void try_fclose_unlink_rename(FILE * file, char * p1, char * p2,
uint16_t size = strlen(msg1) + strlen(msg2) + strlen(msg4)
+ strlen(f) + strlen(p2) + 1;
char * msg = try_malloc(size, f_name);
uint16_t size = strlen(msg1) + strlen(msg2) + strlen(msg4)
+ strlen(f) + strlen(p2) + 1;
char * msg = try_malloc(size, f_name);
- sprintf(msg, "%s%s%s%s%s", msg1, f, msg2, p2, msg4);
+ int test = sprintf(msg, "%s%s%s%s%s", msg1, f, msg2, p2, msg4);
+ exit_trouble(test < 0, f_name, "sprintf()");
exit_err(unlink(p2), msg);
free(msg);
}
exit_err(unlink(p2), msg);
free(msg);
}
@@
-96,7
+98,8
@@
extern void try_fclose_unlink_rename(FILE * file, char * p1, char * p2,
uint16_t size = strlen(msg1) + strlen(f) + strlen(msg2) + strlen(p1)
+ strlen(msg3) + strlen(p2) + strlen(msg4) + 1;
char * msg = try_malloc(size, f_name);
uint16_t size = strlen(msg1) + strlen(f) + strlen(msg2) + strlen(p1)
+ strlen(msg3) + strlen(p2) + strlen(msg4) + 1;
char * msg = try_malloc(size, f_name);
- sprintf(msg, "%s%s%s%s%s%s%s", msg1, f, msg2, p1, msg3, p2, msg4);
+ int test = sprintf(msg, "%s%s%s%s%s%s%s", msg1,f,msg2,p1,msg3,p2,msg4);
+ exit_trouble(test < 0, f_name, "sprintf()");
exit_err(rename(p1, p2), msg);
free(msg);
}
exit_err(rename(p1, p2), msg);
free(msg);
}
diff --git
a/src/common/rexit.c
b/src/common/rexit.c
index d8598cd04888b519694b51250d3b349539387fa7..7e16f12f7c8bce1aeed17635c9f73ef8f963a8c1 100644
(file)
--- a/
src/common/rexit.c
+++ b/
src/common/rexit.c
@@
-51,7
+51,8
@@
extern void exit_trouble(int err, char * parent, char * child)
uint16_t size = strlen(p1) + strlen(parent) + strlen(p2) + strlen(child)
+ strlen(p3) + 1;
char * msg = try_malloc(size, f_name);
uint16_t size = strlen(p1) + strlen(parent) + strlen(p2) + strlen(child)
+ strlen(p3) + 1;
char * msg = try_malloc(size, f_name);
- sprintf(msg, "%s%s%s%s%s", p1, parent, p2, child, p3);
+ int test = sprintf(msg, "%s%s%s%s%s", p1, parent, p2, child, p3);
+ exit_err(test < 0, "Trouble in exit_trouble() with sprintf()");
exit_err(err, msg);
free(msg);
}
exit_err(err, msg);
free(msg);
}
diff --git
a/src/server/init.c
b/src/server/init.c
index a91bd2aaac3c5a4d7898d1f2f4b8d25699e255db..1060474c32a1fb1e1ef9de39049e1ec976057ce9 100644
(file)
--- a/
src/server/init.c
+++ b/
src/server/init.c
@@
-15,7
+15,7
@@
#include "../common/readwrite.h" /* try_fopen(), try_fclose(), textfile_width(),
* try_fgets(), try_fwrite()
*/
#include "../common/readwrite.h" /* try_fopen(), try_fclose(), textfile_width(),
* try_fgets(), try_fwrite()
*/
-#include "../common/rexit.h" /* exit_err() */
+#include "../common/rexit.h" /* exit_err()
, exit_trouble()
*/
#include "../common/try_malloc.h" /* try_malloc() */
#include "cleanup.h" /* set_cleanup_flag() */
#include "field_of_view.h" /* build_fov_map() */
#include "../common/try_malloc.h" /* try_malloc() */
#include "cleanup.h" /* set_cleanup_flag() */
#include "field_of_view.h" /* build_fov_map() */
@@
-100,7
+100,8
@@
extern void setup_server_io()
exit_trouble(test && EEXIST != errno, f_name, "mkdir()");
world.file_out = try_fopen(s[PATH_OUT], "w", f_name);
world.server_test = try_malloc(10 + 1 + 10 + 1 + 1, f_name);
exit_trouble(test && EEXIST != errno, f_name, "mkdir()");
world.file_out = try_fopen(s[PATH_OUT], "w", f_name);
world.server_test = try_malloc(10 + 1 + 10 + 1 + 1, f_name);
- sprintf(world.server_test, "%d %d\n", getpid(), (int) time(0));
+ test = sprintf(world.server_test, "%d %d\n", getpid(), (int) time(0));
+ exit_trouble(test < 0, f_name, "sprintf()");
try_fwrite(world.server_test, strlen(world.server_test), 1,
world.file_out, f_name);
fflush(world.file_out);
try_fwrite(world.server_test, strlen(world.server_test), 1,
world.file_out, f_name);
fflush(world.file_out);
@@
-186,7
+187,8
@@
extern void run_game()
{
char * command = s[CMD_MAKE_WORLD];
char * msg = try_malloc(strlen(command) + 1 + 11 + 1, f_name);
{
char * command = s[CMD_MAKE_WORLD];
char * msg = try_malloc(strlen(command) + 1 + 11 + 1, f_name);
- sprintf(msg, "%s %d", command, (int) time(NULL));
+ int test = sprintf(msg, "%s %d", command, (int) time(NULL));
+ exit_trouble(test < 0, f_name, "sprintf()");
obey_msg(msg, 1);
free(msg);
}
obey_msg(msg, 1);
free(msg);
}
diff --git
a/src/server/io.c
b/src/server/io.c
index bc9d8773feab3b68cb9c4705aa20a80afb9bbac9..258ec45f5da45673e6db7ed8113dac3128d6e35f 100644
(file)
--- a/
src/server/io.c
+++ b/
src/server/io.c
@@
-182,7
+182,8
@@
static void update_worldstate_file()
char * f_name = "update_worldstate_file()";
uint16_t size = strlen(s[PATH_WORLDSTATE]) + strlen(s[PATH_SUFFIX_TMP]) + 1;
char * path_tmp = try_malloc(size, f_name);
char * f_name = "update_worldstate_file()";
uint16_t size = strlen(s[PATH_WORLDSTATE]) + strlen(s[PATH_SUFFIX_TMP]) + 1;
char * path_tmp = try_malloc(size, f_name);
- sprintf(path_tmp, "%s%s", s[PATH_WORLDSTATE], s[PATH_SUFFIX_TMP]);
+ int test = sprintf(path_tmp, "%s%s", s[PATH_WORLDSTATE],s[PATH_SUFFIX_TMP]);
+ exit_trouble(test < 0, f_name, "sprintf()");
FILE * file = try_fopen(path_tmp, "w", f_name);
struct Thing * player = get_player();
write_value_as_line(world.turn, file);
FILE * file = try_fopen(path_tmp, "w", f_name);
struct Thing * player = get_player();
write_value_as_line(world.turn, file);
@@
-210,7
+211,7
@@
static void write_value_as_line(uint32_t value, FILE * file)
{
char * f_name = "write_value_as_line()";
char write_buf[12]; /* Holds 10 digits of uint32_t maximum + \n + \0. */
{
char * f_name = "write_value_as_line()";
char write_buf[12]; /* Holds 10 digits of uint32_t maximum + \n + \0. */
-
sprintf(write_buf, "%u\n", value
);
+
exit_trouble(sprintf(write_buf, "%u\n", value) < 0, f_name, "sprintf()"
);
try_fwrite(write_buf, strlen(write_buf), 1, file, f_name);
}
try_fwrite(write_buf, strlen(write_buf), 1, file, f_name);
}
diff --git
a/src/server/run.c
b/src/server/run.c
index 9ab9f30b08f0c9dd71eb245b7a600f7f61f51fc1..2b56a9d97a721a729156b93bcf3c51b8c40e7d2c 100644
(file)
--- a/
src/server/run.c
+++ b/
src/server/run.c
@@
-4,7
+4,7
@@
#include "run.h"
#include <stddef.h> /* NULL */
#include <stdint.h> /* uint8_t, uint16_t, uint32_t */
#include "run.h"
#include <stddef.h> /* NULL */
#include <stdint.h> /* uint8_t, uint16_t, uint32_t */
-#include <stdio.h> /* FILE, sprintf(), fflush() */
+#include <stdio.h> /* FILE,
printf(),
sprintf(), fflush() */
#include <stdlib.h> /* free(), atoi() */
#include <string.h> /* strlen(), strcmp() strncmp(), strdup() */
#include <unistd.h> /* access() */
#include <stdlib.h> /* free(), atoi() */
#include <string.h> /* strlen(), strcmp() strncmp(), strdup() */
#include <unistd.h> /* access() */
@@
-311,7
+311,8
@@
static void record_msg(char * msg)
char * f_name = "record_msg()";
uint16_t size = strlen(s[PATH_RECORD]) + strlen(s[PATH_SUFFIX_TMP]) + 1;
char * path_tmp = try_malloc(size, f_name);
char * f_name = "record_msg()";
uint16_t size = strlen(s[PATH_RECORD]) + strlen(s[PATH_SUFFIX_TMP]) + 1;
char * path_tmp = try_malloc(size, f_name);
- sprintf(path_tmp, "%s%s", s[PATH_RECORD], s[PATH_SUFFIX_TMP]);
+ int test = sprintf(path_tmp, "%s%s", s[PATH_RECORD], s[PATH_SUFFIX_TMP]);
+ exit_trouble(test < 0, f_name, "sprintf()");
FILE * file_tmp = try_fopen(path_tmp, "w", f_name);
if (!access(s[PATH_RECORD], F_OK))
{
FILE * file_tmp = try_fopen(path_tmp, "w", f_name);
if (!access(s[PATH_RECORD], F_OK))
{
diff --git
a/src/server/thing_actions.c
b/src/server/thing_actions.c
index bb8f585ef0d1cf60649da7c8476486ab0f276d1b..c1e337b6842ab067ee2ef4e2d54d83023708131d 100644
(file)
--- a/
src/server/thing_actions.c
+++ b/
src/server/thing_actions.c
@@
-6,7
+6,7
@@
#include <stdio.h> /* sprintf() */
#include <stdlib.h> /* free() */
#include <string.h> /* strlen(), strcmp(), memcpy(), strncmp() */
#include <stdio.h> /* sprintf() */
#include <stdlib.h> /* free() */
#include <string.h> /* strlen(), strcmp(), memcpy(), strncmp() */
-#include "../common/rexit.h" /* exit_err() */
+#include "../common/rexit.h" /* exit_err()
, exit_trouble()
*/
#include "../common/try_malloc.h" /* try_malloc() */
#include "../common/yx_uint8.h" /* struct yx_uint8 */
#include "field_of_view.h" /* build_fov_map() */
#include "../common/try_malloc.h" /* try_malloc() */
#include "../common/yx_uint8.h" /* struct yx_uint8 */
#include "field_of_view.h" /* build_fov_map() */
@@
-104,7
+104,8
@@
static void update_log(char * text)
uint16_t len_whole = len_old + len_new + 1;
char * new_text = try_malloc(len_whole, f_name);
memcpy(new_text, world.log + offset, len_old);
uint16_t len_whole = len_old + len_new + 1;
char * new_text = try_malloc(len_whole, f_name);
memcpy(new_text, world.log + offset, len_old);
- sprintf(new_text + len_old, "%s", text);
+ int test = sprintf(new_text + len_old, "%s", text);
+ exit_trouble(test < 0, f_name, "sprintf()");
free(world.log);
world.log = new_text;
}
free(world.log);
world.log = new_text;
}
@@
-131,7
+132,8
@@
static void actor_hits_actor(struct Thing * hitter, struct Thing * hitted)
}
uint8_t len = 1 + strlen(msg1) + 1 + strlen(msg2) + 1 + strlen(msg3) + 2;
char * msg = try_malloc(len, f_name);
}
uint8_t len = 1 + strlen(msg1) + 1 + strlen(msg2) + 1 + strlen(msg3) + 2;
char * msg = try_malloc(len, f_name);
- sprintf(msg, "\n%s %s %s.", msg1, msg2, msg3);
+ int test = sprintf(msg, "\n%s %s %s.", msg1, msg2, msg3);
+ exit_trouble(test < 0, f_name, "sprintf()");
update_log(msg);
free(msg);
hitted->lifepoints--;
update_log(msg);
free(msg);
hitted->lifepoints--;
@@
-186,7
+188,8
@@
static void playerbonus_move(char d, uint8_t passable)
dsc_move = "You fail to move ";
}
char * msg = try_malloc(strlen(dsc_move) + strlen (dsc_dir) + 3, f_name);
dsc_move = "You fail to move ";
}
char * msg = try_malloc(strlen(dsc_move) + strlen (dsc_dir) + 3, f_name);
- sprintf(msg, "\n%s%s.", dsc_move, dsc_dir);
+ int test = sprintf(msg, "\n%s%s.", dsc_move, dsc_dir);
+ exit_trouble(test < 0, f_name, "sprintf()");
update_log(msg);
free(msg);
}
update_log(msg);
free(msg);
}
diff --git
a/src/server/things.c
b/src/server/things.c
index 81d59318cf8e36b19a7cebe0d8ebc68571cc5493..eabded27bf98a554330ff84aab1abd34f384fccc 100644
(file)
--- a/
src/server/things.c
+++ b/
src/server/things.c
@@
-5,7
+5,7
@@
#include <stdint.h> /* uint8_t, uint16_t, UINT8_MAX, UINT16_MAX */
#include <stdlib.h> /* free() */
#include <string.h> /* memset(), strlen() */
#include <stdint.h> /* uint8_t, uint16_t, UINT8_MAX, UINT16_MAX */
#include <stdlib.h> /* free() */
#include <string.h> /* memset(), strlen() */
-#include "../common/rexit.h" /* exit_err() */
+#include "../common/rexit.h" /* exit_err()
, exit_trouble()
*/
#include "../common/try_malloc.h" /* try_malloc() */
#include "../common/yx_uint8.h" /* yx_uint8 */
#include "map.h" /* is_passable() */
#include "../common/try_malloc.h" /* try_malloc() */
#include "../common/yx_uint8.h" /* yx_uint8 */
#include "map.h" /* is_passable() */
@@
-192,7
+192,7
@@
extern struct ThingType * get_thing_type(uint8_t id)
char * err_intro = "Requested thing type of unused ID ";
uint16_t size = strlen(err_intro) + 3 + 1 + 1;
char * err = try_malloc(size, f_name);
char * err_intro = "Requested thing type of unused ID ";
uint16_t size = strlen(err_intro) + 3 + 1 + 1;
char * err = try_malloc(size, f_name);
-
sprintf(err, "%s%d.", err_intro, id
);
+
exit_trouble(sprintf(err, "%s%d.", err_intro, id) < 0, f_name, "sprintf()"
);
exit_err(NULL == tt, err);
free(err);
return tt;
exit_err(NULL == tt, err);
free(err);
return tt;