Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Unified Diff: webrtc/base/helpers.cc

Issue 2119003002: Don't silently ignore RNG failures when creating strings / numbers. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Feedback from Matt. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/base/helpers.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/base/helpers.cc
diff --git a/webrtc/base/helpers.cc b/webrtc/base/helpers.cc
index 0a39ee923e1d61b3db9fa6399aee34049595fff6..5e347dff60829e8c2be5d5e2d4f3630cbe962af1 100644
--- a/webrtc/base/helpers.cc
+++ b/webrtc/base/helpers.cc
@@ -28,6 +28,7 @@
#include "webrtc/base/base64.h"
#include "webrtc/base/basictypes.h"
+#include "webrtc/base/checks.h"
#include "webrtc/base/logging.h"
#include "webrtc/base/timeutils.h"
@@ -215,7 +216,7 @@ bool InitRandom(const char* seed, size_t len) {
std::string CreateRandomString(size_t len) {
std::string str;
- CreateRandomString(len, &str);
+ RTC_CHECK(CreateRandomString(len, &str));
return str;
}
@@ -251,10 +252,7 @@ bool CreateRandomString(size_t len, const std::string& table,
std::string CreateRandomUuid() {
std::string str;
std::unique_ptr<uint8_t[]> bytes(new uint8_t[31]);
- if (!Rng().Generate(bytes.get(), 31)) {
- LOG(LS_ERROR) << "Failed to generate random string!";
- return str;
- }
+ RTC_CHECK(Rng().Generate(bytes.get(), 31));
str.reserve(36);
for (size_t i = 0; i < 8; ++i) {
str.push_back(kHex[bytes[i] % 16]);
@@ -282,9 +280,7 @@ std::string CreateRandomUuid() {
uint32_t CreateRandomId() {
uint32_t id;
- if (!Rng().Generate(&id, sizeof(id))) {
- LOG(LS_ERROR) << "Failed to generate random id!";
- }
+ RTC_CHECK(Rng().Generate(&id, sizeof(id)));
return id;
}
« no previous file with comments | « webrtc/base/helpers.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698