From 8505831392922851d8b42869bc0ee82b66f982ad Mon Sep 17 00:00:00 2001 From: "binji@chromium.org" Date: Tue, 19 Jun 2012 04:11:44 +0000 Subject: [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 --- native_client_sdk/src/examples/pong/pong.cc | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) (limited to 'native_client_sdk/src/examples/pong/pong.cc') 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 : 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 -- cgit v1.1