Changeset - r5170:49b50acf2141
[Not reviewed]
master
0 8 0
Darkvater - 18 years ago 2006-11-28 20:55:16
darkvater@openttd.org
(svn r7280) -Codechange: Replace some sprintf() functions with the safer snprintf() functions
8 files changed with 21 insertions and 20 deletions:
0 comments (0 inline, 0 general)
driver.c
Show inline comments
 
@@ -203,22 +203,22 @@ int GetDriverParamInt(const char* const*
 
{
 
	const char* p = GetDriverParam(parm, name);
 
	return p != NULL ? atoi(p) : def;
 
}
 

	
 

	
 
char *GetDriverList(char* p)
 
char *GetDriverList(char* p, const char *last)
 
{
 
	const DriverClass* dc;
 

	
 
	for (dc = _driver_classes; dc != endof(_driver_classes); dc++) {
 
		const DriverDesc* dd;
 

	
 
		p += sprintf(p, "List of %s drivers:\n", dc->name);
 
		p += snprintf(p, last - p, "List of %s drivers:\n", dc->name);
 
		for (dd = dc->descs; dd->name != NULL; dd++) {
 
			p += sprintf(p, "%10s: %s\n", dd->name, dd->longname);
 
			p += snprintf(p, last - p, "%10s: %s\n", dd->name, dd->longname);
 
		}
 
		p += sprintf(p, "\n");
 
		p = strecpy(p, "\n", last);
 
	}
 

	
 
	return p;
 
}
driver.h
Show inline comments
 
@@ -5,9 +5,9 @@
 

	
 
void LoadDriver(int driver, const char *name);
 

	
 
bool GetDriverParamBool(const char* const* parm, const char* name);
 
int GetDriverParamInt(const char* const* parm, const char* name, int def);
 

	
 
char *GetDriverList(char* p);
 
char *GetDriverList(char *p, const char *last);
 

	
 
#endif /* DRIVER_H */
fileio.c
Show inline comments
 
@@ -114,24 +114,24 @@ bool FioCheckFileExists(const char *file
 

	
 
FILE *FioFOpenFile(const char *filename)
 
{
 
	FILE *f;
 
	char buf[MAX_PATH];
 

	
 
	sprintf(buf, "%s%s", _path.data_dir, filename);
 
	snprintf(buf, lengthof(buf), "%s%s", _path.data_dir, filename);
 

	
 
	f = fopen(buf, "rb");
 
#if !defined(WIN32)
 
	if (f == NULL) {
 
		strtolower(buf + strlen(_path.data_dir) - 1);
 
		f = fopen(buf, "rb");
 

	
 
#if defined SECOND_DATA_DIR
 
		// tries in the 2nd data directory
 
		if (f == NULL) {
 
			sprintf(buf, "%s%s", _path.second_data_dir, filename);
 
			snprintf(buf, lengthof(buf), "%s%s", _path.second_data_dir, filename);
 
			strtolower(buf + strlen(_path.second_data_dir) - 1);
 
			f = fopen(buf, "rb");
 
		}
 
#endif
 
	}
 
#endif
gfxinit.c
Show inline comments
 
@@ -108,13 +108,13 @@ static bool CheckMD5Digest(const MD5File
 
static bool FileMD5(const MD5File file, bool warn)
 
{
 
	FILE *f;
 
	char buf[MAX_PATH];
 

	
 
	// open file
 
	sprintf(buf, "%s%s", _path.data_dir, file.filename);
 
	snprintf(buf, lengthof(buf), "%s%s", _path.data_dir, file.filename);
 
	f = fopen(buf, "rb");
 

	
 
#if !defined(WIN32)
 
	if (f == NULL) {
 
		strtolower(buf + strlen(_path.data_dir) - 1);
 
		f = fopen(buf, "rb");
map.c
Show inline comments
 
@@ -64,13 +64,13 @@ TileIndex TileAdd(TileIndex tile, TileIn
 
	x = TileX(tile) + dx;
 
	y = TileY(tile) + dy;
 

	
 
	if (x >= MapSizeX() || y >= MapSizeY()) {
 
		char buf[512];
 

	
 
		sprintf(buf, "TILE_ADD(%s) when adding 0x%.4X and 0x%.4X failed",
 
		snprintf(buf, lengthof(buf), "TILE_ADD(%s) when adding 0x%.4X and 0x%.4X failed",
 
			exp, tile, add);
 
#if !defined(_MSC_VER)
 
		fprintf(stderr, "%s:%d %s\n", file, line, buf);
 
#else
 
		_assert(buf, (char*)file, line);
 
#endif
network_client.c
Show inline comments
 
@@ -454,13 +454,13 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER
 

	
 
	if (MY_CLIENT->has_quit) return NETWORK_RECV_STATUS_CONN_LOST;
 

	
 
	// First packet, init some stuff
 
	if (maptype == MAP_PACKET_START) {
 
		// The name for the temp-map
 
		sprintf(filename, "%s%snetwork_client.tmp",  _path.autosave_dir, PATHSEP);
 
		snprintf(filename, lengthof(filename), "%s%snetwork_client.tmp",  _path.autosave_dir, PATHSEP);
 

	
 
		file_pointer = fopen(filename, "wb");
 
		if (file_pointer == NULL) {
 
			_switch_mode_errorstr = STR_NETWORK_ERR_SAVEGAMEERROR;
 
			return NETWORK_RECV_STATUS_SAVEGAME;
 
		}
network_server.c
Show inline comments
 
@@ -278,13 +278,13 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_MA
 

	
 
	if (cs->status == STATUS_AUTH) {
 
		char filename[256];
 
		Packet *p;
 

	
 
		// Make a dump of the current game
 
		sprintf(filename, "%s%snetwork_server.tmp",  _path.autosave_dir, PATHSEP);
 
		snprintf(filename, lengthof(filename), "%s%snetwork_server.tmp",  _path.autosave_dir, PATHSEP);
 
		if (SaveOrLoad(filename, SL_SAVE) != SL_OK) error("network savedump failed");
 

	
 
		file_pointer = fopen(filename, "rb");
 
		fseek(file_pointer, 0, SEEK_END);
 

	
 
		// Now send the _frame_counter and how many packets are coming
openttd.c
Show inline comments
 
@@ -75,13 +75,13 @@ extern void ShowOSErrorBox(const char *b
 
void CDECL error(const char *s, ...)
 
{
 
	va_list va;
 
	char buf[512];
 

	
 
	va_start(va, s);
 
	vsprintf(buf, s, va);
 
	vsnprintf(buf, lengthof(buf), s, va);
 
	va_end(va);
 

	
 
	ShowOSErrorBox(buf);
 
	if (_video_driver != NULL) _video_driver->stop();
 

	
 
	assert(0);
 
@@ -90,13 +90,13 @@ void CDECL error(const char *s, ...)
 

	
 
void CDECL ShowInfoF(const char *str, ...)
 
{
 
	va_list va;
 
	char buf[1024];
 
	va_start(va, str);
 
	vsprintf(buf, str, va);
 
	vsnprintf(buf, lengthof(buf), str, va);
 
	va_end(va);
 
	ShowInfo(buf);
 
}
 

	
 

	
 
void *ReadFileToMem(const char *filename, size_t *lenp, size_t maxsize)
 
@@ -129,16 +129,16 @@ void *ReadFileToMem(const char *filename
 

	
 
static void showhelp(void)
 
{
 
	extern const char _openttd_revision[];
 
	char buf[4096], *p;
 

	
 
	p    = buf;
 
	p = buf;
 

	
 
	p += sprintf(p, "OpenTTD %s\n", _openttd_revision);
 
	p += sprintf(p,
 
	p += snprintf(p, lengthof(buf), "OpenTTD %s\n", _openttd_revision);
 
	p = strecpy(p,
 
		"\n"
 
		"\n"
 
		"Command line options:\n"
 
		"  -v drv              = Set video driver (see below)\n"
 
		"  -s drv              = Set sound driver (see below)\n"
 
		"  -m drv              = Set music driver (see below)\n"
 
@@ -154,16 +154,17 @@ static void showhelp(void)
 
#if !defined(__MORPHOS__) && !defined(__AMIGA__) && !defined(WIN32)
 
		"  -f                  = Fork into the background (dedicated only)\n"
 
#endif
 
		"  -i                  = Force to use the DOS palette\n"
 
		"                          (use this if you see a lot of pink)\n"
 
		"  -c config_file      = Use 'config_file' instead of 'openttd.cfg'\n"
 
		"\n"
 
		"\n",
 
		lastof(buf)
 
	);
 

	
 
	p = GetDriverList(p);
 
	p = GetDriverList(p, lastof(buf));
 

	
 
	ShowInfo(buf);
 
}
 

	
 

	
 
typedef struct {
 
@@ -283,16 +284,16 @@ static void LoadIntroGame(void)
 

	
 
	// Setup main window
 
	ResetWindowSystem();
 
	SetupColorsAndInitialWindow();
 

	
 
	// Generate a world.
 
	sprintf(filename, "%sopntitle.dat",  _path.data_dir);
 
	snprintf(filename, lengthof(filename), "%sopntitle.dat",  _path.data_dir);
 
#if defined SECOND_DATA_DIR
 
	if (SaveOrLoad(filename, SL_LOAD) != SL_OK) {
 
		sprintf(filename, "%sopntitle.dat",  _path.second_data_dir);
 
		snprintf(filename, lengthof(filename), "%sopntitle.dat",  _path.second_data_dir);
 
	}
 
#endif
 
	if (SaveOrLoad(filename, SL_LOAD) != SL_OK) {
 
		GenerateWorld(GW_EMPTY, 64, 64); // if failed loading, make empty world.
 
		WaitTillGeneratedWorld();
 
	}
0 comments (0 inline, 0 general)