summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chip/host/flash.c6
-rw-r--r--chip/host/persistence.c7
-rw-r--r--chip/host/system.c10
-rw-r--r--test/rma_auth.c2
4 files changed, 12 insertions, 13 deletions
diff --git a/chip/host/flash.c b/chip/host/flash.c
index 9f79298d60..6eef197e78 100644
--- a/chip/host/flash.c
+++ b/chip/host/flash.c
@@ -39,12 +39,10 @@ static int flash_check_protect(int offset, int size)
static void flash_set_persistent(void)
{
FILE *f = get_persistent_storage("flash", "wb");
- int sz;
ASSERT(f != NULL);
- sz = fwrite(__host_flash, sizeof(__host_flash), 1, f);
- ASSERT(sz == 1);
+ ASSERT(fwrite(__host_flash, sizeof(__host_flash), 1, f) == 1);
release_persistent_storage(f);
}
@@ -60,7 +58,7 @@ static void flash_get_persistent(void)
return;
}
- fread(__host_flash, sizeof(__host_flash), 1, f);
+ ASSERT(fread(__host_flash, sizeof(__host_flash), 1, f) == 1);
release_persistent_storage(f);
}
diff --git a/chip/host/persistence.c b/chip/host/persistence.c
index 90856b3bdf..c712d01414 100644
--- a/chip/host/persistence.c
+++ b/chip/host/persistence.c
@@ -5,6 +5,7 @@
/* Persistence module for emulator */
+#include <assert.h>
#include <linux/limits.h>
#include <unistd.h>
#include <stdio.h>
@@ -26,7 +27,7 @@ static void get_storage_path(char *out)
current = strchr(current, '/');
}
- snprintf(out, PATH_MAX - 1, "/dev/shm/EC_persist_%s", buf);
+ assert(snprintf(out, PATH_MAX - 1, "/dev/shm/EC_persist_%s", buf) > 0);
out[PATH_MAX - 1] = '\0';
}
@@ -40,7 +41,7 @@ FILE *get_persistent_storage(const char *tag, const char *mode)
* be named 'bar_persist_foo'
*/
get_storage_path(buf);
- snprintf(path, PATH_MAX - 1, "%s_%s", buf, tag);
+ assert(snprintf(path, PATH_MAX - 1, "%s_%s", buf, tag) > 0);
path[PATH_MAX - 1] = '\0';
return fopen(path, mode);
@@ -57,7 +58,7 @@ void remove_persistent_storage(const char *tag)
char path[PATH_MAX];
get_storage_path(buf);
- snprintf(path, PATH_MAX - 1, "%s_%s", buf, tag);
+ assert(snprintf(path, PATH_MAX - 1, "%s_%s", buf, tag) > 0);
path[PATH_MAX - 1] = '\0';
unlink(path);
diff --git a/chip/host/system.c b/chip/host/system.c
index b1654911ab..3c4225dda0 100644
--- a/chip/host/system.c
+++ b/chip/host/system.c
@@ -50,7 +50,7 @@ static void ramdata_get_persistent(void)
return;
}
- fread(__ram_data, RAM_DATA_SIZE, 1, f);
+ ASSERT(fread(__ram_data, RAM_DATA_SIZE, 1, f) == 1);
release_persistent_storage(f);
@@ -78,7 +78,7 @@ static uint32_t get_image_copy(void)
if (f == NULL)
return SYSTEM_IMAGE_UNKNOWN;
- fread(&ret, sizeof(ret), 1, f);
+ ASSERT(fread(&ret, sizeof(ret), 1, f) == 1);
release_persistent_storage(f);
remove_persistent_storage("image_copy");
@@ -102,7 +102,7 @@ static uint32_t load_reset_flags(void)
if (f == NULL)
return EC_RESET_FLAG_POWER_ON;
- fread(&ret, sizeof(ret), 1, f);
+ ASSERT(fread(&ret, sizeof(ret), 1, f) == 1);
release_persistent_storage(f);
remove_persistent_storage("reset_flags");
@@ -125,7 +125,7 @@ static int load_time(timestamp_t *t)
if (f == NULL)
return 0;
- fread(t, sizeof(*t), 1, f);
+ ASSERT(fread(t, sizeof(*t), 1, f) == 1);
release_persistent_storage(f);
remove_persistent_storage("time");
@@ -218,7 +218,7 @@ int system_set_scratchpad(uint32_t value)
{
FILE *f = get_persistent_storage("scratchpad", "w");
- fprintf(f, "%lu", value);
+ fprintf(f, "%u", value);
release_persistent_storage(f);
return EC_SUCCESS;
diff --git a/test/rma_auth.c b/test/rma_auth.c
index c03ba70acd..21f2f2d561 100644
--- a/test/rma_auth.c
+++ b/test/rma_auth.c
@@ -29,7 +29,7 @@ void rand_bytes(void *buffer, size_t len)
FILE *f = fopen("/dev/urandom", "rb");
assert(f);
- fread(buffer, 1, len, f);
+ assert(fread(buffer, len, 1, f) == 1);
fclose(f);
}