IN GENERAL:
-- check for return values of *printf()
-
- expand use of hardcoded_strings module(s)
BOTH SERVER/CLIENT:
#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() */
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;
#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() */
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;
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;
}
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);
}
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];
- 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;
+ 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);
}
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;
}
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;
}
#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 */
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)
{
- sprintf(keyname, "%s", keyname_match);
+ int test = sprintf(keyname, "%s", keyname_match);
+ exit_trouble(test < 0, f_name, "sprintf()");
return 1;
}
return 0;
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;
- 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
{
- sprintf(keyname, "(unknown)");
+ exit_trouble(sprintf(keyname, "(unknown)") < 0, f_name, "sprintf()");
}
return keyname;
}
/* Leave properly. */
cleanup();
- printf("%s\n", quit_msg);
+ exit_trouble(printf("%s\n", quit_msg) < 0, f_name, "printf()");
exit(EXIT_SUCCESS);
}
#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 */
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];
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;
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;
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++)
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)
{
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++);
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);
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);
}
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);
}
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);
}
#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() */
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);
{
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);
}
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);
{
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);
}
#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() */
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))
{
#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() */
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;
}
}
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--;
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);
}
#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() */
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;