home · contact · privacy
Server: Remove memory leak in save_world().
[plomrogue] / src / server / thing_actions.c
index bb8f585ef0d1cf60649da7c8476486ab0f276d1b..b153ff868ef749fc92497e955a75cc849c725674 100644 (file)
@@ -6,10 +6,11 @@
 #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 "hardcoded_strings.h" /* s */
 #include "things.h" /* structs Thing, ThingType, get_player(), own_thing(),
                      * set_thing_position(), get_thing_type()
                      */
@@ -104,7 +105,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);
-    sprintf(new_text + len_old, "%s", text);
+    int test = sprintf(new_text + len_old, "%s", text);
+    exit_trouble(test < 0, f_name, s[S_FCN_SPRINTF]);
     free(world.log);
     world.log = new_text;
 }
@@ -131,7 +133,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);
-    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, s[S_FCN_SPRINTF]);
     update_log(msg);
     free(msg);
     hitted->lifepoints--;
@@ -186,7 +189,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);
-    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, s[S_FCN_SPRINTF]);
     update_log(msg);
     free(msg);
 }