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
This commit is contained in:
jlmiller@webrtc.org 2015-01-22 18:49:06 +00:00
parent ea1c84285c
commit b40c7bb53c
2 changed files with 14 additions and 13 deletions

View File

@ -35,6 +35,9 @@
#include "talk/examples/peerconnection/server/data_socket.h" #include "talk/examples/peerconnection/server/data_socket.h"
#include "talk/examples/peerconnection/server/utils.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 // Set to the peer id of the originator when messages are being
// exchanged between peers, but set to the id of the receiving peer // 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". // Returns a string in the form "name,id,connected\n".
std::string ChannelMember::GetEntry() const { std::string ChannelMember::GetEntry() const {
assert(name_.length() <= kMaxNameLength); 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; return entry;
} }

View File

@ -29,19 +29,14 @@
#include <stdio.h> #include <stdio.h>
#include "webrtc/base/stringencode.h"
using rtc::ToString;
std::string int2str(int i) { std::string int2str(int i) {
char buffer[11] = {0}; return ToString<int>(i);
sprintf(buffer, "%d", i); // NOLINT
return buffer;
} }
std::string size_t2str(size_t i) { std::string size_t2str(size_t i) {
char buffer[32] = {0}; return ToString<size_t>(i);
#ifdef WIN32
// %zu isn't supported on Windows.
sprintf(buffer, "%Iu", i); // NOLINT
#else
sprintf(buffer, "%zu", i); // NOLINT
#endif
return buffer;
} }