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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/bin/dartutils.h » ('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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "bin/crypto.h" 5 #include "bin/crypto.h"
6 #include "bin/dartutils.h" 6 #include "bin/dartutils.h"
7 7
8 #include "include/dart_api.h" 8 #include "include/dart_api.h"
9 9
10 10
11 namespace dart { 11 namespace dart {
12 namespace bin { 12 namespace bin {
13 13
14 void FUNCTION_NAME(Crypto_GetRandomBytes)(Dart_NativeArguments args) { 14 void FUNCTION_NAME(Crypto_GetRandomBytes)(Dart_NativeArguments args) {
15 Dart_Handle count_obj = Dart_GetNativeArgument(args, 0); 15 Dart_Handle count_obj = Dart_GetNativeArgument(args, 0);
16 int64_t count = 0; 16 const int64_t kMaxRandomBytes = 4096;
17 if (!DartUtils::GetInt64Value(count_obj, &count)) { 17 int64_t count64 = 0;
18 if (!DartUtils::GetInt64Value(count_obj, &count64) ||
19 (count64 < 0) || (count64 > kMaxRandomBytes)) {
18 Dart_Handle error = 20 Dart_Handle error =
19 DartUtils::NewString("Invalid argument, must be an int."); 21 DartUtils::NewString("Invalid argument: count must be a positive int "
22 "less than or equal to 4096.");
20 Dart_ThrowException(error); 23 Dart_ThrowException(error);
21 } 24 }
25 intptr_t count = static_cast<intptr_t>(count64);
22 uint8_t* buffer = new uint8_t[count]; 26 uint8_t* buffer = new uint8_t[count];
23 ASSERT(buffer != NULL); 27 ASSERT(buffer != NULL);
24 if (!Crypto::GetRandomBytes(count, buffer)) { 28 if (!Crypto::GetRandomBytes(count, buffer)) {
25 delete[] buffer; 29 delete[] buffer;
26 Dart_ThrowException(DartUtils::NewDartOSError()); 30 Dart_ThrowException(DartUtils::NewDartOSError());
31 UNREACHABLE();
27 } 32 }
28 Dart_Handle result = Dart_NewTypedData(Dart_TypedData_kUint8, count); 33 Dart_Handle result = Dart_NewTypedData(Dart_TypedData_kUint8, count);
29 if (Dart_IsError(result)) { 34 if (Dart_IsError(result)) {
30 delete[] buffer; 35 delete[] buffer;
31 Dart_Handle error = DartUtils::NewString("Failed to allocate storage."); 36 Dart_Handle error = DartUtils::NewString("Failed to allocate storage.");
32 Dart_ThrowException(error); 37 Dart_ThrowException(error);
38 UNREACHABLE();
33 } 39 }
34 Dart_ListSetAsBytes(result, 0, buffer, count); 40 Dart_ListSetAsBytes(result, 0, buffer, count);
35 Dart_SetReturnValue(args, result); 41 Dart_SetReturnValue(args, result);
36 delete[] buffer; 42 delete[] buffer;
37 } 43 }
38 44
39 } // namespace bin 45 } // namespace bin
40 } // namespace dart 46 } // namespace dart
OLDNEW
« 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