security audit: first batch of fixes. replaced sprintf, strcpy with more secure versions

This commit is contained in:
Magnus Auvinen 2008-02-11 21:49:26 +00:00
parent 57b2da779f
commit 79dfdb3cd7
21 changed files with 162 additions and 129 deletions

View file

@ -430,7 +430,7 @@ void client_connect(const char *server_address_str)
dbg_msg("client", "connecting to '%s'", server_address_str);
strncpy(buf, server_address_str, 512);
str_copy(buf, server_address_str, sizeof(buf));
for(k = 0; buf[k]; k++)
{
@ -500,7 +500,7 @@ static void client_debug_render()
}
frametime_avg = frametime_avg*0.9f + frametime*0.1f;
sprintf(buffer, "ticks: %8d %8d send: %6d recv: %6d snaploss: %d mem %dk gfxmem: %dk fps: %3d",
str_format(buffer, sizeof(buffer), "ticks: %8d %8d send: %6d recv: %6d snaploss: %d mem %dk gfxmem: %dk fps: %3d",
current_tick, current_predtick,
(current.send_bytes-prev.send_bytes)*10,
(current.recv_bytes-prev.recv_bytes)*10,
@ -517,7 +517,7 @@ static void client_debug_render()
{
if(snapshot_data_rate[i])
{
sprintf(buffer, "%4d : %8d %8d %8d", i, snapshot_data_rate[i]/8, snapshot_data_updates[i],
str_format(buffer, sizeof(buffer), "%4d : %8d %8d %8d", i, snapshot_data_rate[i]/8, snapshot_data_updates[i],
(snapshot_data_rate[i]/snapshot_data_updates[i])/8);
gfx_quads_text(2, 100+i*8, 16, buffer);
}
@ -564,7 +564,7 @@ static const char *client_load_map(const char *filename, int wanted_crc)
df = datafile_load(filename);
if(!df)
{
sprintf(errormsg, "map '%s' not found", filename);
str_format(errormsg, sizeof(errormsg), "map '%s' not found", filename);
return errormsg;
}
@ -573,7 +573,7 @@ static const char *client_load_map(const char *filename, int wanted_crc)
if(crc != wanted_crc)
{
datafile_unload(df);
sprintf(errormsg, "map differs from the server. %08x != %08x", crc, wanted_crc);
str_format(errormsg, sizeof(errormsg), "map differs from the server. %08x != %08x", crc, wanted_crc);
return errormsg;
}
@ -592,13 +592,13 @@ static const char *client_load_map_search(const char *mapname, int wanted_crc)
client_set_state(CLIENTSTATE_LOADING);
/* try the normal maps folder */
sprintf(buf, "data/maps/%s.map", mapname);
str_format(buf, sizeof(buf), "data/maps/%s.map", mapname);
error = client_load_map(buf, wanted_crc);
if(!error)
return error;
/* try the downloaded maps */
sprintf(buf2, "%s_%8x.map", mapname, wanted_crc);
str_format(buf2, sizeof(buf2), "%s_%8x.map", mapname, wanted_crc);
engine_savepath(buf2, buf, sizeof(buf));
error = client_load_map(buf, wanted_crc);
return error;
@ -628,10 +628,10 @@ static void client_process_packet(NETPACKET *packet)
#endif
info.latency = 999;
sprintf(info.address, "%d.%d.%d.%d:%d",
str_format(info.address, sizeof(info.address), "%d.%d.%d.%d:%d",
addr.ip[0], addr.ip[1], addr.ip[2],
addr.ip[3], addr.port);
sprintf(info.name, "\255%d.%d.%d.%d:%d", /* the \255 is to make sure that it's sorted last */
str_format(info.name, sizeof(info.name), "\255%d.%d.%d.%d:%d", /* the \255 is to make sure that it's sorted last */
addr.ip[0], addr.ip[1], addr.ip[2],
addr.ip[3], addr.port);
@ -668,21 +668,21 @@ static void client_process_packet(NETPACKET *packet)
unpacker_reset(&up, (unsigned char*)packet->data+sizeof(SERVERBROWSE_INFO), packet->data_size-sizeof(SERVERBROWSE_INFO));
strncpy(info.version, unpacker_get_string(&up), 32);
strncpy(info.name, unpacker_get_string(&up), 64);
strncpy(info.map, unpacker_get_string(&up), 32);
str_copy(info.version, unpacker_get_string(&up), sizeof(info.version));
str_copy(info.name, unpacker_get_string(&up), sizeof(info.name));
str_copy(info.map, unpacker_get_string(&up), sizeof(info.map));
info.game_type = atol(unpacker_get_string(&up));
info.flags = atol(unpacker_get_string(&up));
info.progression = atol(unpacker_get_string(&up));
info.num_players = atol(unpacker_get_string(&up));
info.max_players = atol(unpacker_get_string(&up));
sprintf(info.address, "%d.%d.%d.%d:%d",
str_format(info.address, sizeof(info.address), "%d.%d.%d.%d:%d",
packet->address.ip[0], packet->address.ip[1], packet->address.ip[2],
packet->address.ip[3], packet->address.port);
for(i = 0; i < info.num_players; i++)
{
strncpy(info.player_names[i], unpacker_get_string(&up), 48);
str_copy(info.player_names[i], unpacker_get_string(&up), sizeof(info.player_names[i]));
info.player_scores[i] = atol(unpacker_get_string(&up));
}
@ -727,7 +727,7 @@ static void client_process_packet(NETPACKET *packet)
else
{
char buf[512];
sprintf(buf, "%s_%8x.map", map, map_crc);
str_format(buf, sizeof(buf), "%s_%8x.map", map, map_crc);
engine_savepath(buf, mapdownload_filename, sizeof(mapdownload_filename));
dbg_msg("client/network", "starting to download map to '%s'", mapdownload_filename);

View file

@ -107,9 +107,9 @@ int font_set_load(FONT_SET *font_set, const char *font_filename, const char *tex
FONT *font = &font_set->fonts[i];
size = va_arg(va, int);
sprintf(composed_font_filename, font_filename, size);
sprintf(composed_text_texture_filename, text_texture_filename, size);
sprintf(composed_outline_texture_filename, outline_texture_filename, size);
str_format(composed_font_filename, sizeof(composed_font_filename), font_filename, size);
str_format(composed_text_texture_filename, sizeof(composed_text_texture_filename), text_texture_filename, size);
str_format(composed_outline_texture_filename, sizeof(composed_outline_texture_filename), outline_texture_filename, size);
if (font_load(font, composed_font_filename))
{

View file

@ -209,7 +209,7 @@ void inp_update()
/* clear and begin count on the other one */
mem_zero(&input_count[input_current], sizeof(input_count[input_current]));
memcpy(input_state[input_current], input_state[input_current^1], sizeof(input_state[input_current]));
mem_copy(input_state[input_current], input_state[input_current^1], sizeof(input_state[input_current]));
input_current^=1;
if(keyboard_first)

View file

@ -214,7 +214,7 @@ static void client_serverbrowse_sort()
for(i = 0; i < num_sorted_servers; i++)
serverlist[sorted_serverlist[i]]->info.sorted_index = i;
strncpy(filterstring, config.b_filter_string, sizeof(filterstring)-1);
str_copy(filterstring, config.b_filter_string, sizeof(filterstring));
sorthash = client_serverbrowse_sorthash();
}
@ -278,7 +278,7 @@ void client_serverbrowse_set(NETADDR4 *addr, int request, SERVER_INFO *info)
SERVERENTRY **newlist;
num_server_capacity += 100;
newlist = mem_alloc(num_server_capacity*sizeof(SERVERENTRY*), 1);
memcpy(newlist, serverlist, num_servers*sizeof(SERVERENTRY*));
mem_copy(newlist, serverlist, num_servers*sizeof(SERVERENTRY*));
mem_free(serverlist);
serverlist = newlist;
}

View file

@ -13,7 +13,7 @@ CONFIGURATION config;
void config_reset()
{
#define MACRO_CONFIG_INT(name,def,min,max) config.name = def;
#define MACRO_CONFIG_STR(name,len,def) strncpy(config.name, def, len);
#define MACRO_CONFIG_STR(name,len,def) str_copy(config.name, def, len);
#include "e_config_variables.h"
@ -44,12 +44,10 @@ void config_set(const char *line)
char *var_str = var;
char *val_str = val;
strcpy(val, c+1);
str_copy(val, c+1, sizeof(val));
mem_copy(var, line, c - line);
var[c - line] = 0;
strip_spaces(&var_str);
strip_spaces(&val_str);
@ -98,7 +96,7 @@ void config_save(const char *filename)
#endif
const int newline_len = sizeof(newline)-1;
#define MACRO_CONFIG_INT(name,def,min,max) { char str[256]; sprintf(str, "%s=%i%s", #name, config.name, newline); io_write(file, str, strlen(str)); }
#define MACRO_CONFIG_INT(name,def,min,max) { char str[256]; str_format(str, sizeof(str), "%s=%i%s", #name, config.name, newline); io_write(file, str, strlen(str)); }
#define MACRO_CONFIG_STR(name,len,def) { io_write(file, #name, strlen(#name)); io_write(file, "=", 1); io_write(file, config.name, strlen(config.name)); io_write(file, newline, newline_len); }
#include "e_config_variables.h"
@ -119,7 +117,7 @@ void config_save(const char *filename)
#undef MACRO_CONFIG_STR
#define MACRO_CONFIG_INT(name,def,min,max) void config_set_ ## name (CONFIGURATION *c, int val) { if(min != max) { if (val < min) val = min; if (max != 0 && val > max) val = max; } c->name = val; }
#define MACRO_CONFIG_STR(name,len,def) void config_set_ ## name (CONFIGURATION *c, const char *str) { strncpy(c->name, str, len-1); c->name[sizeof(c->name)-1] = 0; }
#define MACRO_CONFIG_STR(name,len,def) void config_set_ ## name (CONFIGURATION *c, const char *str) { str_copy(c->name, str, len-1); c->name[sizeof(c->name)-1] = 0; }
#include "e_config_variables.h"
#undef MACRO_CONFIG_INT
#undef MACRO_CONFIG_STR

View file

@ -9,7 +9,7 @@ extern "C"{
typedef struct
{
#define MACRO_CONFIG_INT(name,def,min,max) int name;
#define MACRO_CONFIG_STR(name,len,def) char name[len];
#define MACRO_CONFIG_STR(name,len,def) char name[len]; /* Flawfinder: ignore */
#include "e_config_variables.h"
#undef MACRO_CONFIG_INT
#undef MACRO_CONFIG_STR

View file

@ -359,7 +359,7 @@ void console_execute(const char *str)
if (console_validate(command, &result))
{
char buf[256];
sprintf(buf, "Invalid arguments... Usage: %s %s", command->name, command->params);
str_format(buf, sizeof(buf), "Invalid arguments... Usage: %s %s", command->name, command->params);
console_print(buf);
}
else
@ -368,7 +368,7 @@ void console_execute(const char *str)
else
{
char buf[256];
sprintf(buf, "No such command: %s.", name);
str_format(buf, sizeof(buf), "No such command: %s.", name);
console_print(buf);
}
}
@ -402,7 +402,7 @@ static void int_variable_command(void *result, void *user_data)
if (console_result_int(result, 1, &new_val))
{
char buf[256];
sprintf(buf, "Value: %d", data->getter(&config));
str_format(buf, sizeof(buf), "Value: %d", data->getter(&config));
console_print(buf);
}
else
@ -419,7 +419,7 @@ static void str_variable_command(void *result, void *user_data)
if (console_result_string(result, 1, &new_val))
{
char buf[256];
sprintf(buf, "Value: %s", data->getter(&config));
str_format(buf, sizeof(buf), "Value: %s", data->getter(&config));
console_print(buf);
}
else

View file

@ -20,7 +20,7 @@ static char application_save_path[512] = {0};
const char *engine_savepath(const char *filename, char *buffer, int max)
{
sprintf(buffer, "%s/%s", application_save_path, filename);
str_format(buffer, max, "%s/%s", application_save_path, filename);
return buffer;
}
@ -45,12 +45,10 @@ void engine_init(const char *appname)
fs_storage_path(appname, application_save_path, sizeof(application_save_path));
if(fs_makedir(application_save_path) == 0)
{
strcpy(path, application_save_path);
strcat(path, "/screenshots");
str_format(path, sizeof(path), "%s/screenshots", application_save_path);
fs_makedir(path);
strcpy(path, application_save_path);
strcat(path, "/maps");
str_format(path, sizeof(path), "%s/maps", application_save_path);
fs_makedir(path);
}
}
@ -165,7 +163,7 @@ static void perf_dump_imp(PERFORMACE_INFO *info, int indent)
for(i = 0; i < indent; i++)
buf[i] = ' ';
sprintf(&buf[indent], "%-20s %8.2f %8.2f", info->name, info->total*1000/(float)freq, info->biggest*1000/(float)freq);
str_format(&buf[indent], sizeof(buf)-indent, "%-20s %8.2f %8.2f", info->name, info->total*1000/(float)freq, info->biggest*1000/(float)freq);
dbg_msg("perf", "%s", buf);
info = info->first_child;
@ -374,7 +372,7 @@ int mastersrv_save()
for(i = 0; i < MAX_MASTERSERVERS; i++)
{
char buf[1024];
sprintf(buf, "%s %d.%d.%d.%d\n", master_servers[i].hostname,
str_format(buf, sizeof(buf), "%s %d.%d.%d.%d\n", master_servers[i].hostname,
master_servers[i].addr.ip[0], master_servers[i].addr.ip[1],
master_servers[i].addr.ip[2], master_servers[i].addr.ip[3]);

View file

@ -89,7 +89,7 @@ typedef struct
const MSG_INFO *msg_get_info();
/* message unpacking */
int msg_unpack_start(const void *data, int data_size, int *system);
int msg_unpack_start(const void *data, int data_size, int *is_system);
/*
Function: msg_unpack_int

View file

@ -53,7 +53,7 @@ int map_is_loaded()
int map_load(const char *mapname)
{
char buf[512];
sprintf(buf, "data/maps/%s.map", mapname);
str_format(buf, sizeof(buf), "data/maps/%s.map", mapname);
map = datafile_load(buf);
return map != 0;
}

View file

@ -221,7 +221,7 @@ static const char *conn_error(NETCONNECTION *conn)
static void conn_set_error(NETCONNECTION *conn, const char *str)
{
strcpy(conn->error_string, str);
str_copy(conn->error_string, str, sizeof(conn->error_string));
}
/*
@ -337,7 +337,7 @@ static void conn_disconnect(NETCONNECTION *conn, const char *reason)
conn->error_string[0] = 0;
if(reason)
strcpy(conn->error_string, reason);
str_copy(conn->error_string, reason, sizeof(conn->error_string));
}
conn_reset(conn);

View file

@ -77,7 +77,7 @@ void dbg_msg(const char *sys, const char *fmt, ...)
#if defined(CONF_FAMILY_WINDOWS)
char str[1024];
va_start(args, fmt);
vsprintf(str, fmt, args);
_vnsprintf(str, sizeof(str), fmt, args);
va_end(args);
OutputDebugString(str);
OutputDebugString("\n");
@ -92,11 +92,17 @@ void dbg_msg(const char *sys, const char *fmt, ...)
{
char str[2048];
int len;
sprintf(str, "[%s]: ", sys);
str_format(str, sizeof(str), "[%s]: ", sys);
va_start(args, fmt);
vsprintf(str+strlen(str), fmt, args);
len = strlen(str);
#if defined(CONF_FAMILY_WINDOWS)
_vsnprintf(str+len, sizeof(str)-len, fmt, args);
#else
vsnprintf(str+len, sizeof(str)-len, fmt, args);
#endif
va_end(args);
console_print(str);
@ -180,7 +186,7 @@ void mem_debug_dump()
while(header)
{
sprintf(buf, "%s(%d): %d\n", header->filename, header->line, header->size);
str_format(buf, sizeof(buf), "%s(%d): %d\n", header->filename, header->line, header->size);
io_write(f, buf, strlen(buf));
header = header->next;
}
@ -675,8 +681,7 @@ int fs_listdir(const char *dir, fs_listdir_callback cb, void *user)
WIN32_FIND_DATA finddata;
HANDLE handle;
char buffer[1024*2];
strcpy(buffer, dir);
strcat(buffer, "/*");
str_format(buffer, sizeof(buffer), "%s/*", dir);
handle = FindFirstFileA(buffer, &finddata);
@ -777,10 +782,6 @@ void swap_endian(void *data, unsigned elem_size, unsigned num)
int net_socket_read_wait(NETSOCKET sock, int time)
{
/*
#if defined(CONF_FAMILY_WINDOWS)
#error Not implemented
#else*/
struct timeval tv;
fd_set readfds;
@ -795,8 +796,6 @@ int net_socket_read_wait(NETSOCKET sock, int time)
if(FD_ISSET(sock, &readfds))
return 1;
return 0;
/*
#endif*/
}
unsigned time_timestamp()
@ -804,6 +803,45 @@ unsigned time_timestamp()
return time(0);
}
void str_append(char *dst, const char *src, int dst_size)
{
int s = strlen(dst);
int i = 0;
while(s < dst_size)
{
dst[s] = src[i];
if(!src[i]) /* check for null termination */
break;
s++;
i++;
}
dst[dst_size-1] = 0; /* assure null termination */
}
void str_copy(char *dst, const char *src, int dst_size)
{
strncpy(dst, src, dst_size);
dst[dst_size-1] = 0; /* assure null termination */
}
void str_format(char *buffer, int buffer_size, const char *format, ...)
{
#if defined(CONF_FAMILY_WINDOWS)
va_list ap;
va_start(ap, format);
_vsnprintf(buffer, buffer_size, format, ap);
va_end(ap);
#else
va_list ap;
va_start(ap, format);
vsnprintf(buffer, buffer_size, format, ap);
va_end(ap);
#endif
buffer[buffer_size-1] = 0; /* assure null termination */
}
#if defined(__cplusplus)
}
#endif

View file

@ -520,6 +520,13 @@ void swap_endian(void *data, unsigned elem_size, unsigned num);
/* #define cache_prefetch(addr) __builtin_prefetch(addr) */
/*typedef unsigned char [256] pstr;
void pstr_format(pstr *str, )*/
void str_append(char *dst, const char *src, int dst_size);
void str_copy(char *dst, const char *src, int dst_size);
void str_format(char *buffer, int buffer_size, const char *format, ...);
#ifdef __cplusplus
}
#endif

View file

@ -205,7 +205,7 @@ void server_setclientname(int client_id, const char *name)
{
if(client_id < 0 || client_id > MAX_CLIENTS || clients[client_id].state < SRVCLIENT_STATE_READY)
return;
strncpy(clients[client_id].name, name, MAX_NAME_LENGTH);
str_copy(clients[client_id].name, name, MAX_NAME_LENGTH);
}
void server_setclientscore(int client_id, int score)
@ -548,18 +548,18 @@ static void server_process_client_packet(NETPACKET *packet)
{
char version[64];
const char *password;
strncpy(version, msg_unpack_string(), 64);
str_copy(version, msg_unpack_string(), 64);
if(strcmp(version, mods_net_version()) != 0)
{
/* OH FUCK! wrong version, drop him */
char reason[256];
sprintf(reason, "wrong version. server is running %s.", mods_net_version());
str_format(reason, sizeof(reason), "wrong version. server is running %s.", mods_net_version());
netserver_drop(net, cid, reason);
return;
}
strncpy(clients[cid].name, msg_unpack_string(), MAX_NAME_LENGTH);
strncpy(clients[cid].clan, msg_unpack_string(), MAX_CLANNAME_LENGTH);
str_copy(clients[cid].name, msg_unpack_string(), MAX_NAME_LENGTH);
str_copy(clients[cid].clan, msg_unpack_string(), MAX_CLANNAME_LENGTH);
password = msg_unpack_string();
if(config.password[0] != 0 && strcmp(config.password, password) != 0)
@ -704,29 +704,29 @@ static void server_send_serverinfo(NETADDR4 *addr, int lan)
packer_add_string(&p, config.sv_map, 32);
/* gametype */
sprintf(buf, "%d", browseinfo_gametype);
str_format(buf, sizeof(buf), "%d", browseinfo_gametype);
packer_add_string(&p, buf, 2);
/* flags */
i = 0;
if(strlen(config.password))
if(config.password[0])
i |= 1;
sprintf(buf, "%d", i);
str_format(buf, sizeof(buf), "%d", i);
packer_add_string(&p, buf, 2);
/* progression */
sprintf(buf, "%d", browseinfo_progression);
str_format(buf, sizeof(buf), "%d", browseinfo_progression);
packer_add_string(&p, buf, 4);
sprintf(buf, "%d", c); packer_add_string(&p, buf, 3); /* num players */
sprintf(buf, "%d", netserver_max_clients(net)); packer_add_string(&p, buf, 3); /* max players */
str_format(buf, sizeof(buf), "%d", c); packer_add_string(&p, buf, 3); /* num players */
str_format(buf, sizeof(buf), "%d", netserver_max_clients(net)); packer_add_string(&p, buf, 3); /* max players */
for(i = 0; i < MAX_CLIENTS; i++)
{
if(clients[i].state != SRVCLIENT_STATE_EMPTY)
{
packer_add_string(&p, clients[i].name, 48); /* player name */
sprintf(buf, "%d", clients[i].score); packer_add_string(&p, buf, 6); /* player score */
str_format(buf, sizeof(buf), "%d", clients[i].score); packer_add_string(&p, buf, 6); /* player score */
}
}
@ -798,7 +798,7 @@ static int server_load_map(const char *mapname)
{
DATAFILE *df;
char buf[512];
sprintf(buf, "data/maps/%s.map", mapname);
str_format(buf, sizeof(buf), "data/maps/%s.map", mapname);
df = datafile_load(buf);
if(!df)
return 0;
@ -810,7 +810,7 @@ static int server_load_map(const char *mapname)
current_map_crc = datafile_crc(buf);
dbg_msg("server", "%s crc is %08x", buf, current_map_crc);
strcpy(current_map, mapname);
str_copy(current_map, mapname, sizeof(current_map));
map_set(df);
/* load compelate map into memory for download */
@ -842,7 +842,7 @@ static int server_run()
}
/* start server */
if(strlen(config.sv_bindaddr) && net_host_lookup(config.sv_bindaddr, config.sv_port, &bindaddr) != 0)
if(config.sv_bindaddr[0] && net_host_lookup(config.sv_bindaddr, config.sv_port, &bindaddr) != 0)
{
/* sweet! */
}

View file

@ -224,8 +224,8 @@ void chat_add_line(int client_id, int team, const char *line)
if(client_id == -1) // server message
{
strcpy(chat_lines[chat_current_line].name, "*** ");
sprintf(chat_lines[chat_current_line].text, "%s", line);
str_copy(chat_lines[chat_current_line].name, "*** ", sizeof(chat_lines[chat_current_line].name));
str_format(chat_lines[chat_current_line].text, sizeof(chat_lines[chat_current_line].text), "%s", line);
}
else
{
@ -240,8 +240,8 @@ void chat_add_line(int client_id, int team, const char *line)
chat_lines[chat_current_line].name_color = 1;
}
strcpy(chat_lines[chat_current_line].name, client_datas[client_id].name);
sprintf(chat_lines[chat_current_line].text, ": %s", line);
str_copy(chat_lines[chat_current_line].name, client_datas[client_id].name, sizeof(chat_lines[chat_current_line].name));
str_format(chat_lines[chat_current_line].text, sizeof(chat_lines[chat_current_line].text), ": %s", line);
}
}
@ -529,13 +529,13 @@ void render_goals(float x, float y, float w)
if(gameobj && gameobj->time_limit)
{
char buf[64];
sprintf(buf, "Time Limit: %d min", gameobj->time_limit);
str_format(buf, sizeof(buf), "Time Limit: %d min", gameobj->time_limit);
gfx_text(0, x+w/2, y, 24.0f, buf, -1);
}
if(gameobj && gameobj->score_limit)
{
char buf[64];
sprintf(buf, "Score Limit: %d", gameobj->score_limit);
str_format(buf, sizeof(buf), "Score Limit: %d", gameobj->score_limit);
gfx_text(0, x+40, y, 24.0f, buf, -1);
}
}
@ -546,7 +546,7 @@ void render_spectators(float x, float y, float w)
int count = 0;
float h = 120.0f;
strcpy(buffer, "Spectators: ");
str_copy(buffer, sizeof(buffer), "Spectators: ");
gfx_blend_normal();
gfx_texture_set(-1);
@ -614,7 +614,7 @@ void render_scoreboard(float x, float y, float w, int team, const char *title)
if(gameobj)
{
char buf[128];
sprintf(buf, "%d", gameobj->teamscore[team&1]);
str_format(buf, buf, "%d", gameobj->teamscore[team&1]);
tw = gfx_text_width(0, 48, buf, -1);
gfx_text(0, x+w-tw-30, y, 48, buf, -1);
}
@ -622,15 +622,6 @@ void render_scoreboard(float x, float y, float w, int team, const char *title)
y += 54.0f;
/*
if(team)
{
char buf[128];
sprintf(buf, "%4d", gameobj->teamscore[team&1]);
gfx_text(0, x+w/2-tw/2, y, 32, buf, -1);
}*/
// find players
const obj_player_info *players[MAX_CLIENTS] = {0};
int num_players = 0;
@ -687,18 +678,18 @@ void render_scoreboard(float x, float y, float w, int team, const char *title)
gfx_quads_end();
}
sprintf(buf, "%4d", info->score);
str_format(buf, sizeof(buf), "%4d", info->score);
gfx_text(0, x+60-gfx_text_width(0, font_size,buf,-1), y, font_size, buf, -1);
if(config.cl_show_player_ids)
{
sprintf(buf, "%d | %s", info->clientid, client_datas[info->clientid].name);
str_format(buf, sizeof(buf), "%d | %s", info->clientid, client_datas[info->clientid].name);
gfx_text(0, x+128, y, font_size, buf, -1);
}
else
gfx_text(0, x+128, y, font_size, client_datas[info->clientid].name, -1);
sprintf(buf, "%4d", info->latency);
str_format(buf, sizeof(buf), "%4d", info->latency);
float tw = gfx_text_width(0, font_size, buf, -1);
gfx_text(0, x+w-tw-35, y, font_size, buf, -1);
@ -1257,15 +1248,15 @@ void render_game()
// render chat input
char buf[sizeof(chat_input)+16];
if(chat_mode == CHATMODE_ALL)
sprintf(buf, "All: %s_", chat_input);
str_format(buf, sizeof(buf), "All: %s_", chat_input);
else if(chat_mode == CHATMODE_TEAM)
sprintf(buf, "Team: %s_", chat_input);
str_format(buf, sizeof(buf), "Team: %s_", chat_input);
else if(chat_mode == CHATMODE_CONSOLE)
sprintf(buf, "Console: %s_", chat_input);
str_format(buf, sizeof(buf), "Console: %s_", chat_input);
else if(chat_mode == CHATMODE_REMOTECONSOLE)
sprintf(buf, "Rcon: %s_", chat_input);
str_format(buf, sizeof(buf), "Rcon: %s_", chat_input);
else
sprintf(buf, "Chat: %s_", chat_input);
str_format(buf, sizeof(buf), "Chat: %s_", chat_input);
gfx_text(0, x, y, 8.0f, buf, 380);
starty = y;
}
@ -1336,7 +1327,7 @@ void render_game()
else
time = (client_tick()-gameobj->round_start_tick)/client_tickspeed();
sprintf(buf, "%d:%02d", time /60, time %60);
str_format(buf, sizeof(buf), "%d:%02d", time /60, time %60);
float w = gfx_text_width(0, 16, buf, -1);
gfx_text(0, half-w/2, 2, 16, buf, -1);
}
@ -1364,7 +1355,7 @@ void render_game()
gfx_quads_end();
char buf[32];
sprintf(buf, "%d", gameobj->teamscore[t]);
str_format(buf, sizeof(buf), "%d", gameobj->teamscore[t]);
float w = gfx_text_width(0, 14, buf, -1);
if(gametype == GAMETYPE_CTF)
@ -1413,9 +1404,9 @@ void render_game()
int seconds = gameobj->warmup/SERVER_TICK_SPEED;
if(seconds < 5)
sprintf(buf, "%d.%d", seconds, (gameobj->warmup*10/SERVER_TICK_SPEED)%10);
str_format(buf, sizeof(buf), "%d.%d", seconds, (gameobj->warmup*10/SERVER_TICK_SPEED)%10);
else
sprintf(buf, "%d", seconds);
str_format(buf, sizeof(buf), "%d", seconds);
w = gfx_text_width(0, 24, buf, -1);
gfx_text(0, 150*gfx_screenaspect()+-w/2, 75, 24, buf, -1);
}
@ -1456,7 +1447,7 @@ void render_game()
vec2(local_character->x, local_character->y));
char buf[512];
sprintf(buf, "%.2f", speed/2);
str_format(buf, sizeof(buf), "%.2f", speed/2);
gfx_text(0, 150, 50, 12, buf, -1);
}
@ -1545,12 +1536,12 @@ void render_game()
float w;
float x = 5.0f;
sprintf(buf, "%.2f", standard);
str_format(buf, sizeof(buf), "%.2f", standard);
x += 20.0f;
w = gfx_text_width(0, 5, buf, -1);
gfx_text(0x0, x-w, y+count*6, 5, buf, -1);
sprintf(buf, "%.2f", current);
str_format(buf, sizeof(buf), "%.2f", current);
x += 20.0f;
w = gfx_text_width(0, 5, buf, -1);
gfx_text(0x0, x-w, y+count*6, 5, buf, -1);

View file

@ -52,7 +52,7 @@ static void client_console_print(const char *str)
len = 255;
char *entry = (char *)ringbuf_allocate(console_backlog, len+1);
memcpy(entry, str, len+1);
mem_copy(entry, str, len+1);
}
@ -137,7 +137,7 @@ void console_handle_input()
if (console_input_len)
{
char *entry = (char *)ringbuf_allocate(console_history, console_input_len+1);
memcpy(entry, console_input, console_input_len+1);
mem_copy(entry, console_input, console_input_len+1);
console_execute(console_input);
console_input[0] = 0;
@ -163,7 +163,7 @@ void console_handle_input()
unsigned int len = strlen(console_history_entry);
if (len < sizeof(console_input) - 1)
{
memcpy(console_input, console_history_entry, len+1);
mem_copy(console_input, console_history_entry, len+1);
console_input_len = len;
}
@ -180,7 +180,7 @@ void console_handle_input()
unsigned int len = strlen(console_history_entry);
if (len < sizeof(console_input) - 1)
{
memcpy(console_input, console_history_entry, len+1);
mem_copy(console_input, console_history_entry, len+1);
console_input_len = len;
}
@ -304,7 +304,7 @@ void console_render()
gfx_text(0, x+prompt_width+width+1, y, font_size, "_", -1);
char buf[64];
sprintf(buf, "Teewars v%s", TEEWARS_VERSION);
str_format(buf, sizeof(buf), "Teewars v%s", TEEWARS_VERSION);
float version_width = gfx_text_width(0, font_size, buf, -1);
gfx_text(0, screen.w-version_width-5, y, font_size, buf, -1);

View file

@ -110,7 +110,7 @@ int img_init()
{
char buf[256];
char *name = (char *)map_get_data(img->image_name);
sprintf(buf, "data/mapres/%s.png", name);
str_format(buf, sizeof(buf), "data/mapres/%s.png", name);
map_textures[i] = gfx_load_texture(buf, IMG_AUTO);
}
else

View file

@ -171,7 +171,7 @@ static void ui_draw_checkbox(const void *id, const char *text, int checked, cons
static void ui_draw_checkbox_number(const void *id, const char *text, int checked, const RECT *r, const void *extra)
{
char buf[16];
sprintf(buf, "%d", checked);
str_format(buf, sizeof(buf), "%d", checked);
ui_draw_checkbox_common(id, text, buf, r);
}
@ -882,12 +882,12 @@ static void menu2_render_serverbrowser(RECT main_view)
ui_do_label(&button, item->map, 12.0f, -1);
else if(id == COL_PLAYERS)
{
sprintf(temp, "%i/%i", item->num_players, item->max_players);
str_format(temp, sizeof(temp), "%i/%i", item->num_players, item->max_players);
ui_do_label(&button, temp, 12.0f, 1);
}
else if(id == COL_PING)
{
sprintf(temp, "%i", item->latency);
str_format(temp, sizeof(temp), "%i", item->latency);
ui_do_label(&button, temp, 12.0f, 1);
}
else if(id == COL_PROGRESS)
@ -981,13 +981,13 @@ static void menu2_render_serverbrowser(RECT main_view)
char temp[16];
if(selected_server->progression < 0)
sprintf(temp, "N/A");
str_format(temp, sizeof(temp), "N/A");
else
sprintf(temp, "%d%%", selected_server->progression);
str_format(temp, sizeof(temp), "%d%%", selected_server->progression);
ui_hsplit_t(&right_column, 15.0f, &row, &right_column);
ui_do_label(&row, temp, 13.0f, -1);
sprintf(temp, "%d", selected_server->latency);
str_format(temp, sizeof(temp), "%d", selected_server->latency);
ui_hsplit_t(&right_column, 15.0f, &row, &right_column);
ui_do_label(&row, temp, 13.0f, -1);
}
@ -1012,7 +1012,7 @@ static void menu2_render_serverbrowser(RECT main_view)
char temp[16];
ui_hsplit_t(&server_scoreboard, 16.0f, &row, &server_scoreboard);
sprintf(temp, "%d", selected_server->player_scores[i]);
str_format(temp, sizeof(temp), "%d", selected_server->player_scores[i]);
ui_do_label(&row, temp, 14.0f, -1);
ui_vsplit_l(&row, 25.0f, 0x0, &row);
@ -1050,7 +1050,7 @@ static void menu2_render_serverbrowser(RECT main_view)
ui_vsplit_l(&button, 5.0f, &button, &button);
char buf[8];
sprintf(buf, "%d", config.b_filter_ping);
str_format(buf, sizeof(buf), "%d", config.b_filter_ping);
ui_do_edit_box(&config.b_filter_ping, &editbox, buf, sizeof(buf), 14.0f);
config.b_filter_ping = atoi(buf);
@ -1073,7 +1073,7 @@ static void menu2_render_serverbrowser(RECT main_view)
ui_draw_rect(&status, vec4(1,1,1,0.25f), CORNER_B, 5.0f);
ui_vmargin(&status, 50.0f, &status);
char buf[128];
sprintf(buf, "%d of %d servers", client_serverbrowse_sorted_num(), client_serverbrowse_num());
str_format(buf, sizeof(buf), "%d of %d servers", client_serverbrowse_sorted_num(), client_serverbrowse_num());
ui_do_label(&status, buf, 14.0f, -1);
// render toolbox
@ -1231,7 +1231,7 @@ static void menu2_render_settings_player(RECT main_view)
{
const skin *s = skin_get(i);
char buf[128];
sprintf(buf, "%s", s->name);
str_format(buf, sizeof(buf), "%s", s->name);
int selected = 0;
if(strcmp(s->name, config.player_skin) == 0)
selected = 1;
@ -1357,7 +1357,7 @@ static void menu2_render_settings_graphics(RECT main_view)
// draw footers
ui_hsplit_b(&modelist, 20, &modelist, &footer);
sprintf(buf, "Current: %dx%d %d bit", config.gfx_screen_width, config.gfx_screen_height, config.gfx_color_depth);
str_format(buf, sizeof(buf), "Current: %dx%d %d bit", config.gfx_screen_width, config.gfx_screen_height, config.gfx_color_depth);
ui_draw_rect(&footer, vec4(1,1,1,0.25f), CORNER_B, 5.0f);
ui_vsplit_l(&footer, 10.0f, 0, &footer);
ui_do_label(&footer, buf, 14.0f, -1);
@ -1397,7 +1397,7 @@ static void menu2_render_settings_graphics(RECT main_view)
selected = 1;
}
sprintf(buf, " %dx%d %d bit", modes[i].width, modes[i].height, depth);
str_format(buf, sizeof(buf), " %dx%d %d bit", modes[i].width, modes[i].height, depth);
if(ui_do_button(&modes[i], buf, selected, &button, ui_draw_list_row, 0))
{
config.gfx_color_depth = depth;
@ -1502,7 +1502,7 @@ static void menu2_render_settings_sound(RECT main_view)
// sample rate box
{
char buf[64];
sprintf(buf, "%d", config.snd_rate);
str_format(buf, sizeof(buf), "%d", config.snd_rate);
ui_hsplit_t(&main_view, 20.0f, &button, &main_view);
ui_do_label(&button, "Sample Rate", 14.0f, -1);
ui_vsplit_l(&button, 110.0f, 0, &button);
@ -1810,7 +1810,7 @@ int menu2_render()
if(client_mapdownload_totalsize() > 0)
{
title = "Downloading map";
sprintf(buf, "%d/%d KiB", client_mapdownload_amount()/1024, client_mapdownload_totalsize()/1024);
str_format(buf, sizeof(buf), "%d/%d KiB", client_mapdownload_amount()/1024, client_mapdownload_totalsize()/1024);
extra_text = buf;
}
}

View file

@ -23,7 +23,7 @@ static void skinscan(const char *name, int is_dir, void *user)
return;
char buf[512];
sprintf(buf, "data/skins/%s", name);
str_format(buf, sizeof(buf), "data/skins/%s", name);
IMAGE_INFO info;
if(!gfx_load_png(&info, buf))
{

View file

@ -115,6 +115,7 @@ void gameobject::cyclemap()
{
if(!strlen(config.sv_maprotation))
return;
// handle maprotation
char buf[512];
const char *s = strstr(config.sv_maprotation, config.sv_map);
@ -145,7 +146,7 @@ void gameobject::cyclemap()
i++;
dbg_msg("game", "rotating map to %s", &buf[i]);
strcpy(config.sv_map, &buf[i]);
str_copy(config.sv_map, &buf[i], sizeof(config.sv_map));
}
void gameobject::post_reset()

View file

@ -663,7 +663,7 @@ void player::set_team(int new_team)
return;
char buf[512];
sprintf(buf, "%s joined the %s", server_clientname(client_id), get_team_name(new_team));
str_format(buf, sizeof(buf), "%s joined the %s", server_clientname(client_id), get_team_name(new_team));
send_chat(-1, -1, buf);
team = new_team;
@ -2108,7 +2108,7 @@ void mods_client_enter(int client_id)
char buf[512];
sprintf(buf, "%s entered and joined the %s", server_clientname(client_id), get_team_name(players[client_id].team));
str_format(buf, sizeof(buf), "%s entered and joined the %s", server_clientname(client_id), get_team_name(players[client_id].team));
send_chat(-1, -1, buf);
dbg_msg("game", "team_join player='%d:%s' team=%d", client_id, server_clientname(client_id), players[client_id].team);
@ -2138,7 +2138,7 @@ void mods_connected(int client_id)
void mods_client_drop(int client_id)
{
char buf[512];
sprintf(buf, "%s has left the game", server_clientname(client_id));
str_format(buf, sizeof(buf), "%s has left the game", server_clientname(client_id));
send_chat(-1, -1, buf);
dbg_msg("game", "leave player='%d:%s'", client_id, server_clientname(client_id));
@ -2196,12 +2196,12 @@ void mods_message(int msg, int client_id)
if(msg == MSG_CHANGEINFO && strcmp(name, server_clientname(client_id)) != 0)
{
char msg[256];
sprintf(msg, "*** %s changed name to %s", server_clientname(client_id), name);
str_format(msg, sizeof(msg), "*** %s changed name to %s", server_clientname(client_id), name);
send_chat(-1, -1, msg);
}
//send_set_name(client_id, players[client_id].name, name);
strncpy(players[client_id].skin_name, skin_name, 64);
str_copy(players[client_id].skin_name, skin_name, sizeof(players[client_id].skin_name));
server_setclientname(client_id, name);
gameobj->on_player_info_change(&players[client_id]);