home
·
contact
·
privacy
projects
/
plomrogue
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Server: Merge duplicate string literals of "sprintf()".
[plomrogue]
/
src
/
server
/
thing_actions.c
diff --git
a/src/server/thing_actions.c
b/src/server/thing_actions.c
index 2531ae9532152a8e13a27d283088dfee19181ccf..b153ff868ef749fc92497e955a75cc849c725674 100644
(file)
--- a/
src/server/thing_actions.c
+++ b/
src/server/thing_actions.c
@@
-6,10
+6,11
@@
#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() */
+#include "hardcoded_strings.h" /* s */
#include "things.h" /* structs Thing, ThingType, get_player(), own_thing(),
* set_thing_position(), get_thing_type()
*/
#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);
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;
}
free(world.log);
world.log = new_text;
}
@@
-113,6
+115,7
@@
static void update_log(char * text)
static void actor_hits_actor(struct Thing * hitter, struct Thing * hitted)
{
static void actor_hits_actor(struct Thing * hitter, struct Thing * hitted)
{
+ char * f_name = "actor_hits_actor()";
struct ThingType * tt_hitter = get_thing_type(hitter->type);
struct ThingType * tt_hitted = get_thing_type(hitted->type);
struct Thing * player = get_player();
struct ThingType * tt_hitter = get_thing_type(hitter->type);
struct ThingType * tt_hitted = get_thing_type(hitted->type);
struct Thing * player = get_player();
@@
-129,9
+132,11
@@
static void actor_hits_actor(struct Thing * hitter, struct Thing * hitted)
msg3 = tt_hitted->name;
}
uint8_t len = 1 + strlen(msg1) + 1 + strlen(msg2) + 1 + strlen(msg3) + 2;
msg3 = tt_hitted->name;
}
uint8_t len = 1 + strlen(msg1) + 1 + strlen(msg2) + 1 + strlen(msg3) + 2;
- char msg[len];
- sprintf(msg, "\n%s %s %s.", msg1, msg2, msg3);
+ char * msg = try_malloc(len, f_name);
+ int test = sprintf(msg, "\n%s %s %s.", msg1, msg2, msg3);
+ exit_trouble(test < 0, f_name, s[S_FCN_SPRINTF]);
update_log(msg);
update_log(msg);
+ free(msg);
hitted->lifepoints--;
if (0 == hitted->lifepoints)
{
hitted->lifepoints--;
if (0 == hitted->lifepoints)
{
@@
-168,6
+173,7
@@
static uint8_t match_dir(char d, char ** dsc_d, char match, char * dsc_match)
static void playerbonus_move(char d, uint8_t passable)
{
static void playerbonus_move(char d, uint8_t passable)
{
+ char * f_name = "playerbonus_move()";
char * dsc_dir = "north-east";
if ( match_dir(d, &dsc_dir, 'd', "east")
|| match_dir(d, &dsc_dir, 'c', "south-east")
char * dsc_dir = "north-east";
if ( match_dir(d, &dsc_dir, 'd', "east")
|| match_dir(d, &dsc_dir, 'c', "south-east")
@@
-182,9
+188,11
@@
static void playerbonus_move(char d, uint8_t passable)
{
dsc_move = "You fail to move ";
}
{
dsc_move = "You fail to move ";
}
- char msg[strlen(dsc_move) + strlen (dsc_dir) + 3];
- sprintf(msg, "\n%s%s.", dsc_move, dsc_dir);
+ char * msg = try_malloc(strlen(dsc_move) + strlen (dsc_dir) + 3, f_name);
+ int test = sprintf(msg, "\n%s%s.", dsc_move, dsc_dir);
+ exit_trouble(test < 0, f_name, s[S_FCN_SPRINTF]);
update_log(msg);
update_log(msg);
+ free(msg);
}
}