[openjk] 68/130: SG: Add checks for file handle
Simon McVittie
smcv at debian.org
Fri Oct 28 11:09:20 UTC 2016
This is an automated email from the git hooks/post-receive script.
smcv pushed a commit to branch debian/master
in repository openjk.
commit 2cdbf4192e601c0d9b72b62502f8133cdc136e4d
Author: bibendovsky <bibendovsky at hotmail.com>
Date: Sun Aug 7 21:46:10 2016 +0300
SG: Add checks for file handle
---
shared/qcommon/ojk_i_saved_game.h | 7 +++-
shared/qcommon/ojk_saved_game.cpp | 51 +++++++++++++++++++++++++++---
shared/qcommon/ojk_saved_game_helper_fwd.h | 13 ++++++++
3 files changed, 65 insertions(+), 6 deletions(-)
diff --git a/shared/qcommon/ojk_i_saved_game.h b/shared/qcommon/ojk_i_saved_game.h
index f4d0140..50bad4f 100644
--- a/shared/qcommon/ojk_i_saved_game.h
+++ b/shared/qcommon/ojk_i_saved_game.h
@@ -32,7 +32,8 @@ public:
}
- // Tries to reads a chunk from the file into the internal buffer.
+ // Reads a chunk from the file into the internal buffer.
+ // Returns true on success or false otherwise.
virtual bool read_chunk(
const uint32_t chunk_id) = 0;
@@ -44,21 +45,25 @@ public:
// Writes a chunk into the file from the internal buffer.
+ // Returns true on success or false otherwise.
virtual bool write_chunk(
const uint32_t chunk_id) = 0;
// Reads data from the internal buffer.
+ // Returns true on success or false otherwise.
virtual bool read(
void* dst_data,
int dst_size) = 0;
// Writes data into the internal buffer.
+ // Returns true on success or false otherwise.
virtual bool write(
const void* src_data,
int src_size) = 0;
// Increments buffer's offset by the specified non-negative count.
+ // Returns true on success or false otherwise.
virtual bool skip(
int count) = 0;
diff --git a/shared/qcommon/ojk_saved_game.cpp b/shared/qcommon/ojk_saved_game.cpp
index 708fc28..ede9b5a 100644
--- a/shared/qcommon/ojk_saved_game.cpp
+++ b/shared/qcommon/ojk_saved_game.cpp
@@ -163,10 +163,8 @@ void SavedGame::close()
file_handle_ = 0;
}
- error_message_.clear();
-
- io_buffer_.clear();
- io_buffer_offset_ = 0;
+ clear_error();
+ reset_buffer();
saved_io_buffer_.clear();
saved_io_buffer_offset_ = 0;
@@ -175,7 +173,6 @@ void SavedGame::close()
is_readable_ = false;
is_writable_ = false;
- is_failed_ = false;
}
bool SavedGame::read_chunk(
@@ -186,6 +183,12 @@ bool SavedGame::read_chunk(
return false;
}
+ if (file_handle_ == 0)
+ {
+ is_failed_ = true;
+ error_message_ = "Not open or created.";
+ return false;
+ }
io_buffer_offset_ = 0;
@@ -352,6 +355,16 @@ bool SavedGame::read_chunk(
bool SavedGame::is_all_data_read() const
{
+ if (is_failed_)
+ {
+ return false;
+ }
+
+ if (file_handle_ == 0)
+ {
+ return false;
+ }
+
return io_buffer_.size() == io_buffer_offset_;
}
@@ -373,6 +386,13 @@ bool SavedGame::write_chunk(
return false;
}
+ if (file_handle_ == 0)
+ {
+ is_failed_ = true;
+ error_message_ = "Not open or created.";
+ return false;
+ }
+
const auto chunk_id_string = get_chunk_id_string(
chunk_id);
@@ -548,6 +568,13 @@ bool SavedGame::read(
return false;
}
+ if (file_handle_ == 0)
+ {
+ is_failed_ = true;
+ error_message_ = "Not open or created.";
+ return false;
+ }
+
if (!dst_data)
{
is_failed_ = true;
@@ -600,6 +627,13 @@ bool SavedGame::write(
return false;
}
+ if (file_handle_ == 0)
+ {
+ is_failed_ = true;
+ error_message_ = "Not open or created.";
+ return false;
+ }
+
if (!src_data)
{
is_failed_ = true;
@@ -654,6 +688,13 @@ bool SavedGame::skip(
return false;
}
+ if (file_handle_ == 0)
+ {
+ is_failed_ = true;
+ error_message_ = "Not open or created.";
+ return false;
+ }
+
if (!is_readable_ && !is_writable_)
{
is_failed_ = true;
diff --git a/shared/qcommon/ojk_saved_game_helper_fwd.h b/shared/qcommon/ojk_saved_game_helper_fwd.h
index 7dee5b6..a2f866c 100644
--- a/shared/qcommon/ojk_saved_game_helper_fwd.h
+++ b/shared/qcommon/ojk_saved_game_helper_fwd.h
@@ -22,25 +22,38 @@ public:
ISavedGame* saved_game);
+ // Reads a chunk from the file into the internal buffer.
+ // Calls error method on failure.
void read_chunk(
const uint32_t chunk_id);
+ // Writes a chunk into the file from the internal buffer.
+ // Calls error method on failure.
void write_chunk(
const uint32_t chunk_id);
+ // Increments buffer's offset by the specified non-negative count.
+ // Calls error method on failure.
void skip(
int count);
+ // Clears buffer and resets it's offset to the beginning.
const void* get_buffer_data();
+ // Returns a current size of the I/O buffer.
int get_buffer_size() const;
+ // Clears buffer and resets it's offset to the beginning.
void reset_buffer();
+ // Resets buffer offset to the beginning.
void reset_buffer_offset();
+ // Calls error method if not all data read.
void ensure_all_data_read();
+ // Error flag.
+ // Returns true if read/write operation failed otherwise false.
bool is_failed() const;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/openjk.git
More information about the Pkg-games-commits
mailing list