diff options
-rw-r--r-- | avr/env.c | 18 |
1 files changed, 9 insertions, 9 deletions
@@ -18,13 +18,6 @@ debug_cond(DEBUG_ENV, fmt, ##args) -#define ENV_SIZE (CONFIG_ENV_SIZE - sizeof(uint16_t) -1) -#define ACTIVE_FLAG 1 -#define OBSOLETE_FLAG 0 - -#define ENVLIST_DELETE (1<<0) - - /* * Default Environment */ @@ -44,10 +37,17 @@ const FLASH char default_env[] = { }; +#define ENV_SIZE (CONFIG_ENV_SIZE - sizeof(uint16_t) - sizeof(uint8_t)) + +#define ENVLIST_DELETE (1<<0) + + /* EEPROM storage */ typedef struct environment_s { uint16_t crc; /* CRC16 over data bytes */ uint8_t flags; /* active/obsolete flags */ +#define ACTIVE_FLAG 1 +#define OBSOLETE_FLAG 0 char data[ENV_SIZE]; /* Environment data */ } env_t; @@ -139,7 +139,7 @@ static char *env_item_insert_name(char *pos, const char *name, int len) while (*end++ != 0) while (*end++ != 0); - if (end > env_list + ENV_SIZE) + if (end + len >= env_list + ENV_SIZE) return NULL; memmove(dstp, pos, end - pos); @@ -714,7 +714,7 @@ command_ret_t do_env_print(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, return CMD_RET_FAILURE; if (mode == 0) printf_P(PSTR("\nEnvironment size: %d/%d bytes\n"), - size, ENV_SIZE); + size, ENV_SIZE - 1); return CMD_RET_SUCCESS; } |