From c741910c6e8cde9282ce173fba8a202c5cabddf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xabier=20Crespo=20=C3=81lvarez?= Date: Wed, 16 May 2018 13:38:33 +0200 Subject: [PATCH 1/2] Avoid comparing integer to pointer --- easyflash/src/ef_env.c | 10 +++++----- easyflash/src/ef_env_wl.c | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/easyflash/src/ef_env.c b/easyflash/src/ef_env.c index 0b0fd76..a554c08 100644 --- a/easyflash/src/ef_env.c +++ b/easyflash/src/ef_env.c @@ -337,7 +337,7 @@ static char *find_env(const char *key) { char *env_start, *env_end, *env, *found_env = NULL; size_t key_len = strlen(key), env_len; - if (*key == NULL) { + if ((key == NULL) || *key == '\0') { EF_INFO("Flash ENV name must be not empty!\n"); return NULL; } @@ -386,7 +386,7 @@ static EfErrCode create_env(const char *key, const char *value) { EF_ASSERT(key); EF_ASSERT(value); - if (*key == NULL) { + if ((key == NULL) || *key == '\0') { EF_INFO("Flash ENV name must be not empty!\n"); return EF_ENV_NAME_ERR; } @@ -421,7 +421,7 @@ static EfErrCode del_env(const char *key){ EF_ASSERT(key); - if (*key == NULL) { + if ((key == NULL) || *key == '\0') { EF_INFO("Flash ENV name must be not NULL!\n"); return EF_ENV_NAME_ERR; } @@ -480,7 +480,7 @@ EfErrCode ef_set_env(const char *key, const char *value) { ef_port_env_lock(); /* if ENV value is empty, delete it */ - if (*value == NULL) { + if ((value == NULL) || *value == '\0') { result = del_env(key); } else { old_env = find_env(key); @@ -554,7 +554,7 @@ void ef_print_env(void) { for (j = 0; j < 4; j++) { c = (*env_cache_data_addr) >> (8 * j); ef_print("%c", c); - if (c == NULL) { + if (c == '\0') { ef_print("\n"); break; } diff --git a/easyflash/src/ef_env_wl.c b/easyflash/src/ef_env_wl.c index 219e1be..4640a3d 100644 --- a/easyflash/src/ef_env_wl.c +++ b/easyflash/src/ef_env_wl.c @@ -354,7 +354,7 @@ static char *find_env(const char *key) { char *env_start, *env_end, *env, *found_env = NULL; size_t key_len = strlen(key), env_len; - if (*key == NULL) { + if ((key == NULL) || (*key == '\0')) { EF_INFO("Flash ENV name must be not empty!\n"); return NULL; } @@ -404,7 +404,7 @@ static EfErrCode create_env(const char *key, const char *value) { EF_ASSERT(key); EF_ASSERT(value); - if (*key == NULL) { + if ((key == NULL) || (*key == '\0')) { EF_INFO("Flash ENV name must be not empty!\n"); return EF_ENV_NAME_ERR; } @@ -439,7 +439,7 @@ static EfErrCode del_env(const char *key) { EF_ASSERT(key); - if (*key == NULL) { + if ((key == NULL) || (*key == '\0')) { EF_INFO("Flash ENV name must be not NULL!\n"); return EF_ENV_NAME_ERR; } @@ -498,7 +498,7 @@ EfErrCode ef_set_env(const char *key, const char *value) { ef_port_env_lock(); /* if ENV value is empty, delete it */ - if (*value == NULL) { + if ((value == NULL) || (*value == '\0')) { result = del_env(key); } else { old_env = find_env(key); From f2883a8e778834a20dccf27e27923efa98787c89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xabier=20Crespo=20=C3=81lvarez?= Date: Wed, 16 May 2018 13:39:02 +0200 Subject: [PATCH 2/2] Add missing error code --- easyflash/inc/easyflash.h | 1 + 1 file changed, 1 insertion(+) diff --git a/easyflash/inc/easyflash.h b/easyflash/inc/easyflash.h index 5a80585..1f3fcdc 100644 --- a/easyflash/inc/easyflash.h +++ b/easyflash/inc/easyflash.h @@ -78,6 +78,7 @@ typedef struct _ef_env{ typedef enum { EF_NO_ERR, EF_ERASE_ERR, + EF_READ_ERR, EF_WRITE_ERR, EF_ENV_NAME_ERR, EF_ENV_NAME_EXIST,