From: Leo C Date: Fri, 27 Jul 2018 06:43:02 +0000 (+0200) Subject: ENV_SIZE X-Git-Url: http://cloudbase.mooo.com/gitweb/z180-stamp.git/commitdiff_plain/b0a9d14ceee5b6d4e6e27bb6982497c70cd12aeb ENV_SIZE --- diff --git a/avr/env.c b/avr/env.c index 6bbd99c..44c5742 100644 --- a/avr/env.c +++ b/avr/env.c @@ -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; }