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

Side by Side Diff: base/rand_util.cc

Issue 8418034: Make string_util::WriteInto() DCHECK() that the supplied |length_with_null| > 1, meaning that the... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/rand_util.h ('k') | base/rand_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/rand_util.h" 5 #include "base/rand_util.h"
6 6
7 #include <math.h> 7 #include <math.h>
8 8
9 #include <limits> 9 #include <limits>
10 10
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 uint64 random_int; 64 uint64 random_int;
65 size_t random_int_size = sizeof(random_int); 65 size_t random_int_size = sizeof(random_int);
66 for (size_t i = 0; i < output_length; i += random_int_size) { 66 for (size_t i = 0; i < output_length; i += random_int_size) {
67 random_int = base::RandUint64(); 67 random_int = base::RandUint64();
68 size_t copy_count = std::min(output_length - i, random_int_size); 68 size_t copy_count = std::min(output_length - i, random_int_size);
69 memcpy(((uint8*)output) + i, &random_int, copy_count); 69 memcpy(((uint8*)output) + i, &random_int, copy_count);
70 } 70 }
71 } 71 }
72 72
73 std::string RandBytesAsString(size_t length) { 73 std::string RandBytesAsString(size_t length) {
74 DCHECK_GT(length, 0u);
74 std::string result; 75 std::string result;
75 RandBytes(WriteInto(&result, length + 1), length); 76 RandBytes(WriteInto(&result, length + 1), length);
76 return result; 77 return result;
77 } 78 }
78 79
79 } // namespace base 80 } // namespace base
OLDNEW
« no previous file with comments | « base/rand_util.h ('k') | base/rand_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698