diff options
| author | binji@chromium.org <binji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-19 04:11:44 +0000 |
|---|---|---|
| committer | binji@chromium.org <binji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-19 04:11:44 +0000 |
| commit | 8505831392922851d8b42869bc0ee82b66f982ad (patch) | |
| tree | e2dfa5f4b509b9e00d145d48cdf4f334d74f0050 /native_client_sdk/src/examples/pong/pong.cc | |
| parent | d0d9c3eed9085779098868f5ab8a3d90e6899dcc (diff) | |
| download | chromium_src-8505831392922851d8b42869bc0ee82b66f982ad.zip chromium_src-8505831392922851d8b42869bc0ee82b66f982ad.tar.gz chromium_src-8505831392922851d8b42869bc0ee82b66f982ad.tar.bz2 | |
[NaCl SDK] Fix some examples
BUG=none
TEST=none
Review URL: https://chromiumcodereview.appspot.com/10583008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@142908 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'native_client_sdk/src/examples/pong/pong.cc')
| -rw-r--r-- | native_client_sdk/src/examples/pong/pong.cc | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/native_client_sdk/src/examples/pong/pong.cc b/native_client_sdk/src/examples/pong/pong.cc index 8adf3fe..54ba17f3 100644 --- a/native_client_sdk/src/examples/pong/pong.cc +++ b/native_client_sdk/src/examples/pong/pong.cc @@ -93,7 +93,7 @@ void QueryCallback(void* data, int32_t result) { pong->bytes_buffer_.resize(pong->bytes_to_read_); // Check if there is anything to read. - if (pong->bytes_to_read_ == 0) { + if (pong->bytes_to_read_ != 0) { pong->file_io_->Read(pong->offset_, &pong->bytes_buffer_[0], pong->bytes_to_read_, @@ -340,11 +340,9 @@ void Pong::WriteScoreToFile() { if (file_io_ == NULL) return; // Write the score in <player score>:<computer score> format. - size_t score_string_length = 1 + (player_score_ ? log(player_score_) : 1) + 1 - + (computer_score_ ? log(computer_score_) : 1) + 1; - bytes_buffer_.resize(score_string_length); - snprintf(&bytes_buffer_[0], bytes_buffer_.length(), "%i:%i", player_score_, - computer_score_); + char buffer[100]; + snprintf(&buffer[0], sizeof(buffer), "%d:%d", player_score_, computer_score_); + bytes_buffer_ = std::string(&buffer[0]); offset_ = 0; // overwrite score in file. file_io_->Write(offset_, bytes_buffer_.c_str(), @@ -404,15 +402,10 @@ Pong::BallDirection Pong::RightPaddleNextMove() const { } void Pong::UpdateScoreDisplay() { - if (file_io_ == NULL) - PostMessage(pp::Var("Could not save score (incognito?).")); - return; // Since we cant't save the score to file, do nothing and return. - size_t message_length = 18 + (player_score_ ? log(player_score_) : 1) + 1 - + (computer_score_ ? log(computer_score_) : 1) + 1; - std::string score_message(message_length, '\0'); - snprintf(&score_message[0], score_message.length(), - "You: %i Computer: %i", player_score_, computer_score_); - PostMessage(pp::Var(score_message)); + char buffer[100]; + snprintf(&buffer[0], sizeof(buffer), "You %d: Computer %d", player_score_, + computer_score_); + PostMessage(pp::Var(buffer)); } } // namespace pong |
