Changeset - r20984:a4da9302878d
[Not reviewed]
master
0 10 0
rubidium - 11 years ago 2013-11-23 13:15:07
rubidium@openttd.org
(svn r26058) -Fix: handle the return value of a number of functions better
10 files changed with 51 insertions and 13 deletions:
0 comments (0 inline, 0 general)
src/bmp.cpp
Show inline comments
 
@@ -25,18 +25,24 @@ void BmpInitializeBuffer(BmpBuffer *buff
 

	
 
static inline void AdvanceBuffer(BmpBuffer *buffer)
 
{
 
	if (buffer->read < 0) return;
 

	
 
	buffer->read = (int)fread(buffer->data, 1, BMP_BUFFER_SIZE, buffer->file);
 
	buffer->pos  = 0;
 
}
 

	
 
static inline bool EndOfBuffer(BmpBuffer *buffer)
 
{
 
	if (buffer->read < 0) return false;
 

	
 
	if (buffer->pos == buffer->read || buffer->pos < 0) AdvanceBuffer(buffer);
 
	return buffer->pos == buffer->read;
 
}
 

	
 
static inline byte ReadByte(BmpBuffer *buffer)
 
{
 
	if (buffer->read < 0) return 0;
 

	
 
	if (buffer->pos == buffer->read || buffer->pos < 0) AdvanceBuffer(buffer);
 
	buffer->real_pos++;
 
	return buffer->data[buffer->pos++];
 
@@ -62,7 +68,9 @@ static inline void SkipBytes(BmpBuffer *
 

	
 
static inline void SetStreamOffset(BmpBuffer *buffer, int offset)
 
{
 
	fseek(buffer->file, offset, SEEK_SET);
 
	if (fseek(buffer->file, offset, SEEK_SET) < 0) {
 
		buffer->read = -1;
 
	}
 
	buffer->pos = -1;
 
	buffer->real_pos = offset;
 
	AdvanceBuffer(buffer);
src/debug.cpp
Show inline comments
 
@@ -112,6 +112,8 @@ static void debug_print(const char *dbg,
 
		char buf2[1024 + 32];
 

	
 
		snprintf(buf2, lengthof(buf2), "%sdbg: [%s] %s\n", GetLogPrefix(), dbg, buf);
 
		/* Sending out an error when this fails would be nice, however... the error
 
		 * would have to be send over this failing socket which won't work. */
 
		send(_debug_socket, buf2, (int)strlen(buf2), 0);
 
		return;
 
	}
src/fileio.cpp
Show inline comments
 
@@ -88,7 +88,9 @@ void FioSeekTo(size_t pos, int mode)
 
	if (mode == SEEK_CUR) pos += FioGetPos();
 
	_fio.buffer = _fio.buffer_end = _fio.buffer_start + FIO_BUFFER_SIZE;
 
	_fio.pos = pos;
 
	fseek(_fio.cur_fh, _fio.pos, SEEK_SET);
 
	if (fseek(_fio.cur_fh, _fio.pos, SEEK_SET) < 0) {
 
		DEBUG(misc, 0, "Seeking in %s failed", _fio.filename);
 
	}
 
}
 

	
 
#if defined(LIMITED_FDS)
 
@@ -450,7 +452,11 @@ FILE *FioFOpenFileTar(TarFileListEntry *
 
	FILE *f = fopen(entry->tar_filename, "rb");
 
	if (f == NULL) return f;
 

	
 
	fseek(f, entry->position, SEEK_SET);
 
	if (fseek(f, entry->position, SEEK_SET) < 0) {
 
		fclose(f);
 
		return NULL;
 
	}
 

	
 
	if (filesize != NULL) *filesize = entry->size;
 
	return f;
 
}
 
@@ -533,6 +539,8 @@ FILE *FioFOpenFile(const char *filename,
 
 */
 
static void FioCreateDirectory(const char *name)
 
{
 
	/* Ignore directory creation errors; they'll surface later on, and most
 
	 * of the time they are 'directory already exists' errors anyhow. */
 
#if defined(WIN32) || defined(WINCE)
 
	CreateDirectory(OTTD2FS(name), NULL);
 
#elif defined(OS2) && !defined(__INNOTEK_LIBC__)
 
@@ -897,7 +905,11 @@ bool TarScanner::AddFile(const char *fil
 

	
 
		/* Skip to the next block.. */
 
		skip = Align(skip, 512);
 
		fseek(f, skip, SEEK_CUR);
 
		if (fseek(f, skip, SEEK_CUR) < 0) {
 
			DEBUG(misc, 0, "The file '%s' can't be read as a valid tar-file", filename);
 
			fclose(f);
 
			return false;
 
		}
 
		pos += skip;
 
	}
 

	
src/ini.cpp
Show inline comments
 
@@ -106,7 +106,9 @@ bool IniFile::SaveToDisk(const char *fil
 
	shfopt.pTo    = tfilename;
 
	SHFileOperation(&shfopt);
 
#else
 
	rename(file_new, filename);
 
	if (rename(file_new, filename) < 0) {
 
		DEBUG(misc, 0, "Renaming %s to %s failed; configuration not saved", file_new, filename);
 
	}
 
#endif
 

	
 
	return true;
src/newgrf_config.cpp
Show inline comments
 
@@ -362,7 +362,11 @@ static bool CalcGRFMD5Sum(GRFConfig *con
 

	
 
	size_t start = ftell(f);
 
	size = min(size, GRFGetSizeOfDataSection(f));
 
	fseek(f, start, SEEK_SET);
 

	
 
	if (fseek(f, start, SEEK_SET) < 0) {
 
		FioFCloseFile(f);
 
		return false;
 
	}
 

	
 
	/* calculate md5sum */
 
	while ((len = fread(buffer, 1, (size > sizeof(buffer)) ? sizeof(buffer) : size, f)) != 0 && size != 0) {
src/pathfinder/yapf/yapf_node_rail.hpp
Show inline comments
 
@@ -196,7 +196,7 @@ struct CYapfRailNodeT
 
		while (cur != GetLastTile() || cur_td != GetLastTrackdir()) {
 
			if (!((obj.*func)(cur, cur_td))) return false;
 

	
 
			ft.Follow(cur, cur_td);
 
			if (!ft.Follow(cur, cur_td)) break;
 
			cur = ft.m_new_tile;
 
			assert(KillFirstBit(ft.m_new_td_bits) == TRACKDIR_BIT_NONE);
 
			cur_td = FindFirstTrackdir(ft.m_new_td_bits);
src/saveload/oldloader.cpp
Show inline comments
 
@@ -250,10 +250,9 @@ static SavegameType DetermineOldSavegame
 

	
 
	/* Can't fseek to 0 as in tar files that is not correct */
 
	long pos = ftell(f);
 
	if (!CheckOldSavegameType(f, temp, lastof(temp), TTO_HEADER_SIZE)) {
 
	if (pos >= 0 && !CheckOldSavegameType(f, temp, lastof(temp), TTO_HEADER_SIZE)) {
 
		type = SGT_TTD;
 
		fseek(f, pos, SEEK_SET);
 
		if (!CheckOldSavegameType(f, temp, lastof(temp), TTD_HEADER_SIZE)) {
 
		if (fseek(f, pos, SEEK_SET) < 0 || !CheckOldSavegameType(f, temp, lastof(temp), TTD_HEADER_SIZE)) {
 
			type = SGT_INVALID;
 
		}
 
	}
src/saveload/saveload.cpp
Show inline comments
 
@@ -1848,7 +1848,9 @@ struct FileReader : LoadFilter {
 
	/* virtual */ void Reset()
 
	{
 
		clearerr(this->file);
 
		fseek(this->file, this->begin, SEEK_SET);
 
		if (fseek(this->file, this->begin, SEEK_SET)) {
 
			DEBUG(sl, 1, "Could not reset the file reading");
 
		}
 
	}
 
};
 

	
src/script/squirrel.cpp
Show inline comments
 
@@ -493,7 +493,12 @@ SQRESULT Squirrel::LoadFile(HSQUIRRELVM 
 
				}
 
				func = _io_file_lexfeed_UTF8;
 
				break;
 
			default: func = _io_file_lexfeed_ASCII; fseek(file, -2, SEEK_CUR); break; // ASCII
 
			default: // ASCII
 
				func = _io_file_lexfeed_ASCII;
 
				if (fseek(file, -2, SEEK_CUR) < 0) {
 
					return sq_throwerror(vm, _SC("cannot read the file"));
 
				}
 
				break;
 
		}
 

	
 
		if (SQ_SUCCEEDED(sq_compile(vm, func, &f, OTTD2SQ(filename), printerror))) {
src/strgen/strgen.cpp
Show inline comments
 
@@ -353,7 +353,9 @@ struct LanguageFileWriter : LanguageWrit
 

	
 
	void Finalise()
 
	{
 
		fputc(0, this->fh);
 
		if (fputc(0, this->fh) == EOF) {
 
			error("Could not write to %s", this->filename);
 
		}
 
		this->FileWriter::Finalise();
 
	}
 

	
 
@@ -368,6 +370,8 @@ struct LanguageFileWriter : LanguageWrit
 
/** Multi-OS mkdirectory function */
 
static inline void ottd_mkdir(const char *directory)
 
{
 
	/* Ignore directory creation errors; they'll surface later on, and most
 
	 * of the time they are 'directory already exists' errors anyhow. */
 
#if defined(WIN32) || defined(__WATCOMC__)
 
		mkdir(directory);
 
#else
0 comments (0 inline, 0 general)