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

Unified Diff: src/platform/vboot_reference/common/utility_stub.c

Issue 572024: Add a StatefulMemcpy which can be used to safely and iteratively copy blocks of memory. (Closed)
Patch Set: Must be consistent.. Created 10 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 | src/platform/vboot_reference/include/utility.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/platform/vboot_reference/common/utility_stub.c
diff --git a/src/platform/vboot_reference/common/utility_stub.c b/src/platform/vboot_reference/common/utility_stub.c
index 14a5910fbad8911e2a375e07fd6925a049983159..ca12fa610ccf9473018f59c3b87aa0f1f0995d3b 100644
--- a/src/platform/vboot_reference/common/utility_stub.c
+++ b/src/platform/vboot_reference/common/utility_stub.c
@@ -10,7 +10,6 @@
#include <stdio.h>
#include <stdlib.h>
-#include <string.h>
void* Malloc(size_t size) {
void* p = malloc(size);
@@ -29,6 +28,13 @@ void* Memcpy(void* dest, const void* src, size_t n) {
return memcpy(dest, src, n);
}
+void* Memset(void* dest, const uint8_t c, size_t n) {
+ while (n--) {
+ *((uint8_t*)dest) = c;
+ }
+ return dest;
+}
+
int SafeMemcmp(const void* s1, const void* s2, size_t n) {
int match = 1;
const unsigned char* us1 = s1;
@@ -42,3 +48,16 @@ int SafeMemcmp(const void* s1, const void* s2, size_t n) {
return match;
}
+
+void* StatefulMemcpy(MemcpyState* state, void* dst, int len) {
+ void* saved_ptr;
+ if (len > state->remaining_len) {
+ state->remaining_len = -1;
+ return NULL;
+ }
+ saved_ptr = state->remaining_buf;
+ Memcpy(dst, saved_ptr, len);
+ state->remaining_buf += len;
+ state->remaining_len -= len;
+ return dst;
+}
« no previous file with comments | « no previous file | src/platform/vboot_reference/include/utility.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698