From 4fd96a54d3c4c523ee9df1d6999f95142c68c5f4 Mon Sep 17 00:00:00 2001 From: An-Cheng Huang Date: Mon, 30 Jun 2008 19:38:21 -0700 Subject: fix for bug 3403: allocate correct amount of memory for multi-valued nodes. --- src/cli_new.c | 33 ++++++++++++++++++++++++++++++--- src/cli_val.h | 1 + 2 files changed, 31 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/cli_new.c b/src/cli_new.c index 26cc719..b66d83c 100644 --- a/src/cli_new.c +++ b/src/cli_new.c @@ -1926,24 +1926,51 @@ void subtract_values(char **lhs, const char *rhs) if (lhs == NULL || *lhs == NULL || **lhs == '\0' || rhs == NULL || *rhs == '\0') return; + /* calculate number of rhs entries */ rhs_copy = strdup(rhs); - length = strlen(rhs) / 2; + line = strtok(rhs_copy, "\n\r"); + while (line != NULL && *line != '\0') { + rhs_cnt++; + line = strtok(NULL, "\n\r"); + } + + /* strtok destroys the string. dup again. */ + free(rhs_copy); + rhs_copy = strdup(rhs); + + /* allocate enough space for all old entries (to be subtracted) */ + length = rhs_cnt * sizeof(char *); head = ptr = my_malloc(length, "subtract_values list1"); memset(head, 0, length); + /* parse the entries and put them in head[] */ line = strtok(rhs_copy, "\n\r"); while (line != NULL && *line != '\0') { *ptr = line; ptr++; - rhs_cnt++; line = strtok(NULL, "\n\r"); } - length = strlen(*lhs) / 2; + /* calculate number of lhs entries */ + { + char *lhs_copy = strdup(*lhs); + line = strtok(lhs_copy, "\n\r"); + while (line != NULL && *line != '\0') { + lhs_cnt++; + line = strtok(NULL, "\n\r"); + } + free(lhs_copy); + } + + /* allocate enough space for all new entries */ + length = lhs_cnt * sizeof(char *); new_head = new_ptr = my_malloc(length, "subtract_values list2"); memset(new_head, 0, length); + /* reset length and lhs_cnt. they are now used for the "new" array (i.e., + * after subtraction). */ length = 0; + lhs_cnt = 0; line = strtok(*lhs, "\n\r"); while (line != NULL && *line != '\0') { for (i = 0; i < rhs_cnt; i++) { diff --git a/src/cli_val.h b/src/cli_val.h index 520fa8e..56f6cee 100644 --- a/src/cli_val.h +++ b/src/cli_val.h @@ -214,6 +214,7 @@ extern int get_config_lock(); extern int out_fd; extern FILE *out_stream; +extern FILE *err_stream; extern int initialize_output(); -- cgit v1.2.3 From 89690fab7e1b49ab8a97a5c9907982bec45e85d5 Mon Sep 17 00:00:00 2001 From: Michael Larson Date: Tue, 1 Jul 2008 13:56:24 -0700 Subject: fix for bug 3377. --- src/delete.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/delete.c b/src/delete.c index 9bdb3ed..bb2c987 100644 --- a/src/delete.c +++ b/src/delete.c @@ -291,8 +291,10 @@ int main(int argc, char **argv) if (status != VTWERR_OK) bye("Corrupted old value ---- \n%s\n-----\n", cp); res = val_cmp(&new_value, &old_value, IN_COND); - if (!res) + if (!res) { + fprintf(out_stream, "%s is not a configured value\n", new_value.val); bye("Not in multivalue"); + } touch(); if (old_value.cnt) { push_path(&m_path, VAL_NAME); -- cgit v1.2.3 From 93a148a78b577ced2cfaebdbe1659e3ecc58c4aa Mon Sep 17 00:00:00 2001 From: Michael Larson Date: Mon, 7 Jul 2008 12:05:27 -0700 Subject: fix for bug 3216. added no escape option to push path for environmental path variable. note this is appied to all c code access to the edit env variable. --- src/cli_new.c | 28 ++++++++++++++++++++++++++++ src/cli_objects.c | 2 +- src/cli_val.h | 1 + 3 files changed, 30 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/cli_new.c b/src/cli_new.c index b66d83c..0b50ccb 100644 --- a/src/cli_new.c +++ b/src/cli_new.c @@ -1774,7 +1774,35 @@ void push_path(vtw_path *path, char *segm) }else *pp = *cp; *pp = 0; + path->path_len += len; + if (path->path_lev == path->path_ends_alloc){ + path->path_ends_alloc += ENDS_ALLOC; + path->path_ends = (int *)my_realloc(path->path_ends, + sizeof(int *)*path->path_ends_alloc, "puhs_path 2"); + } + path->path_ends[path->path_lev++] = path->path_len; + // push_path_no_escape(); +} +/** + * Version of above that doesn't escape value before stuffing. + * + **/ +void push_path_no_escape(vtw_path *path, char *segm) +{ + int len; + char *cp; + char *pp; + + for(cp=segm, len=0;*cp;++cp, ++len); + warrant_path(path, len + 1); + path->path_buf[path->path_len] = '/'; + path->path_buf[++path->path_len] = 0; + for(pp=path->path_buf + path->path_len,cp=segm; + *cp;++cp, ++pp) { + *pp = *cp; + } + *pp = 0; path->path_len += len; if (path->path_lev == path->path_ends_alloc){ path->path_ends_alloc += ENDS_ALLOC; diff --git a/src/cli_objects.c b/src/cli_objects.c index 8f0f6fe..8685c6a 100644 --- a/src/cli_objects.c +++ b/src/cli_objects.c @@ -243,7 +243,7 @@ void init_edit() slashp = strchr(scanp, '/'); if (slashp) *slashp = 0; - push_path(&m_path, scanp); + push_path_no_escape(&m_path, scanp); if (slashp) { *slashp = '/'; scanp = slashp+1; diff --git a/src/cli_val.h b/src/cli_val.h index 56f6cee..c9d59a6 100644 --- a/src/cli_val.h +++ b/src/cli_val.h @@ -153,6 +153,7 @@ extern void cli_val_done(void); extern void init_path(vtw_path *path, const char *root); extern void pop_path(vtw_path *path); extern void push_path(vtw_path *path, char *segm); +extern void push_path_no_escape(vtw_path *path, char *segm); extern void free_def(vtw_def *defp); extern void free_sorted(vtw_sorted *sortp); extern void *my_malloc(size_t size, const char *name); -- cgit v1.2.3