summaryrefslogtreecommitdiff
path: root/avr/env.c
diff options
context:
space:
mode:
Diffstat (limited to 'avr/env.c')
-rw-r--r--avr/env.c31
1 files changed, 24 insertions, 7 deletions
diff --git a/avr/env.c b/avr/env.c
index 8487c6f..28437a4 100644
--- a/avr/env.c
+++ b/avr/env.c
@@ -103,6 +103,19 @@ uint16_t varname_get(char *buf, env_item_t *ep)
static
+uint16_t varval_getlen(uint16_t index)
+{
+ int i = 0;
+ char c;
+
+ while ((c = env_get_char (index + i)) != '\0') {
+ i++;
+ };
+
+ return i;
+}
+
+static
uint16_t varval_get(char *buf, uint16_t index, int len)
{
int i = 0;
@@ -403,13 +416,17 @@ env_item_t *envlist_get(const char *name, uint_fast8_t flag)
if (ep != NULL && (flag & ENV_GET_VAL)) {
if (ep->flags & EF_V_EEP) {
char *vp;
- uint_fast8_t len;
- /* TODO: function that gets len of val,
- to get rid of xrealloc */
- vp = xmalloc(CONFIG_SYS_CBSIZE);
- len = varval_get(vp, ep->val.eep, CONFIG_SYS_CBSIZE);
- ep->val.ram = xrealloc(vp, len + 1);
- ep->flags &= ~EF_V_EEP;
+ int len;
+ len = varval_getlen(ep->val.eep);
+ if (len > CONFIG_SYS_CBSIZE)
+ len = CONFIG_SYS_CBSIZE;
+ vp = xmalloc(len + 1);
+ if (vp) {
+ varval_get(vp, ep->val.eep, len + 1);
+ ep->val.ram = vp;
+ ep->flags &= ~EF_V_EEP;
+ } else
+ printf_P(PSTR("Out of memory!\n"));
}
}