| OLD | NEW |
| 1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 /* Copyright (c) 2010 The Chromium OS 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 * Utility functions that need to be built as part of the firmware. | 5 * Utility functions that need to be built as part of the firmware. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "sysincludes.h" |
| 8 #include "utility.h" | 9 #include "utility.h" |
| 9 | 10 |
| 10 void* Memset(void* d, const uint8_t c, uint64_t n) { | 11 void* Memset(void* d, const uint8_t c, uint64_t n) { |
| 11 uint8_t* dest = d; /* the only way to keep both cl and gcc happy */ | 12 uint8_t* dest = d; /* the only way to keep both cl and gcc happy */ |
| 12 while (n--) { | 13 while (n--) { |
| 13 *dest++ = c; | 14 *dest++ = c; |
| 14 } | 15 } |
| 15 return dest; | 16 return dest; |
| 16 } | 17 } |
| 17 | 18 |
| 18 int SafeMemcmp(const void* s1, const void* s2, size_t n) { | 19 int SafeMemcmp(const void* s1, const void* s2, size_t n) { |
| 20 const unsigned char* us1 = s1; |
| 21 const unsigned char* us2 = s2; |
| 19 int result = 0; | 22 int result = 0; |
| 23 |
| 20 if (0 == n) | 24 if (0 == n) |
| 21 return 1; | 25 return 1; |
| 22 | 26 |
| 23 const unsigned char* us1 = s1; | |
| 24 const unsigned char* us2 = s2; | |
| 25 /* Code snippet without data-dependent branch due to | 27 /* Code snippet without data-dependent branch due to |
| 26 * Nate Lawson (nate@root.org) of Root Labs. */ | 28 * Nate Lawson (nate@root.org) of Root Labs. */ |
| 27 while (n--) | 29 while (n--) |
| 28 result |= *us1++ ^ *us2++; | 30 result |= *us1++ ^ *us2++; |
| 29 | 31 |
| 30 return result != 0; | 32 return result != 0; |
| 31 } | 33 } |
| OLD | NEW |