home · contact · privacy
Server: Start hardcoded_strings s's enum names with prefix "S_".
[plomrogue] / src / server / things.c
index e0aa674851fcb2527fe74e70df448c9eca52167c..eabded27bf98a554330ff84aab1abd34f384fccc 100644 (file)
@@ -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 "../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() */
@@ -186,12 +186,15 @@ extern struct Thing * get_player()
 
 extern struct ThingType * get_thing_type(uint8_t id)
 {
+    char * f_name = "get_thing_type()";
     struct ThingType * tt = world.thing_types;
     for (; NULL != tt && id != tt->id; tt = tt->next);
     char * err_intro = "Requested thing type of unused ID ";
-    char err[strlen(err_intro) + 3 + 1 + 1];
-    sprintf(err, "%s%d.", err_intro, id);
+    uint16_t size = strlen(err_intro) + 3 + 1 + 1;
+    char * err = try_malloc(size, f_name);
+    exit_trouble(sprintf(err, "%s%d.", err_intro, id) < 0, f_name, "sprintf()");
     exit_err(NULL == tt, err);
+    free(err);
     return tt;
 }