Change sprintf use in talk samples to snprintf

BUG=2301
R=juberti@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/41579004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@8128 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/talk/examples/peerconnection/server/peer_channel.cc b/talk/examples/peerconnection/server/peer_channel.cc
index 355dbbe..243995b 100644
--- a/talk/examples/peerconnection/server/peer_channel.cc
+++ b/talk/examples/peerconnection/server/peer_channel.cc
@@ -35,6 +35,9 @@
 
 #include "talk/examples/peerconnection/server/data_socket.h"
 #include "talk/examples/peerconnection/server/utils.h"
+#include "webrtc/base/stringutils.h"
+
+using rtc::sprintfn;
 
 // Set to the peer id of the originator when messages are being
 // exchanged between peers, but set to the id of the receiving peer
@@ -108,8 +111,11 @@
 // Returns a string in the form "name,id,connected\n".
 std::string ChannelMember::GetEntry() const {
   assert(name_.length() <= kMaxNameLength);
-  char entry[1024] = {0};
-  sprintf(entry, "%s,%i,%i\n", name_.c_str(), id_, connected_);  // NOLINT
+
+  // name, 11-digit int, 1-digit bool, newline, null
+  char entry[kMaxNameLength + 15];
+  sprintfn(entry, sizeof(entry), "%s%d%d\n",
+           name_.substr(0, kMaxNameLength).c_str(), id_, connected_);
   return entry;
 }
 
diff --git a/talk/examples/peerconnection/server/utils.cc b/talk/examples/peerconnection/server/utils.cc
index da2c096..a9938c8 100644
--- a/talk/examples/peerconnection/server/utils.cc
+++ b/talk/examples/peerconnection/server/utils.cc
@@ -29,19 +29,14 @@
 
 #include <stdio.h>
 
+#include "webrtc/base/stringencode.h"
+
+using rtc::ToString;
+
 std::string int2str(int i) {
-  char buffer[11] = {0};
-  sprintf(buffer, "%d", i);  // NOLINT
-  return buffer;
+  return ToString<int>(i);
 }
 
 std::string size_t2str(size_t i) {
-  char buffer[32] = {0};
-#ifdef WIN32
-  // %zu isn't supported on Windows.
-  sprintf(buffer, "%Iu", i);  // NOLINT
-#else
-  sprintf(buffer, "%zu", i);  // NOLINT
-#endif
-  return buffer;
+  return ToString<size_t>(i);
 }