diff --git a/talk/examples/peerconnection/server/peer_channel.cc b/talk/examples/peerconnection/server/peer_channel.cc index 355dbbe37..243995b79 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 @@ bool ChannelMember::NotifyOfOtherMember(const ChannelMember& other) { // 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 da2c096a0..a9938c83f 100644 --- a/talk/examples/peerconnection/server/utils.cc +++ b/talk/examples/peerconnection/server/utils.cc @@ -29,19 +29,14 @@ #include +#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(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(i); }