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

Unified Diff: runtime/bin/crypto.cc

Issue 139043003: - Address warnings about 64-bit to 32-bit conversions. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 11 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 | « no previous file | runtime/bin/dartutils.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/crypto.cc
===================================================================
--- runtime/bin/crypto.cc (revision 31864)
+++ runtime/bin/crypto.cc (working copy)
@@ -13,23 +13,29 @@
void FUNCTION_NAME(Crypto_GetRandomBytes)(Dart_NativeArguments args) {
Dart_Handle count_obj = Dart_GetNativeArgument(args, 0);
- int64_t count = 0;
- if (!DartUtils::GetInt64Value(count_obj, &count)) {
+ const int64_t kMaxRandomBytes = 4096;
+ int64_t count64 = 0;
+ if (!DartUtils::GetInt64Value(count_obj, &count64) ||
+ (count64 < 0) || (count64 > kMaxRandomBytes)) {
Dart_Handle error =
- DartUtils::NewString("Invalid argument, must be an int.");
+ DartUtils::NewString("Invalid argument: count must be a positive int "
+ "less than or equal to 4096.");
Dart_ThrowException(error);
}
+ intptr_t count = static_cast<intptr_t>(count64);
uint8_t* buffer = new uint8_t[count];
ASSERT(buffer != NULL);
if (!Crypto::GetRandomBytes(count, buffer)) {
delete[] buffer;
Dart_ThrowException(DartUtils::NewDartOSError());
+ UNREACHABLE();
}
Dart_Handle result = Dart_NewTypedData(Dart_TypedData_kUint8, count);
if (Dart_IsError(result)) {
delete[] buffer;
Dart_Handle error = DartUtils::NewString("Failed to allocate storage.");
Dart_ThrowException(error);
+ UNREACHABLE();
}
Dart_ListSetAsBytes(result, 0, buffer, count);
Dart_SetReturnValue(args, result);
« no previous file with comments | « no previous file | runtime/bin/dartutils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698