]> cloudbase.mooo.com Git - z180-stamp.git/commitdiff
ENV_SIZE
authorLeo C <erbl259-lmu@yahoo.de>
Fri, 27 Jul 2018 06:43:02 +0000 (08:43 +0200)
committerLeo C <erbl259-lmu@yahoo.de>
Fri, 27 Jul 2018 06:43:02 +0000 (08:43 +0200)
avr/env.c

index 6bbd99c4f91fb1725004111a8f2cb6f0f468e3a7..44c5742afe3043a6054218eede24a7660436e62b 100644 (file)
--- a/avr/env.c
+++ b/avr/env.c
        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;
        }