[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[augeas-devel] augeas: master - * src/pathx.c: call make_value before pop_value



Gitweb:        http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=afee63affe8b6263644300003a91af5facb758a4
Commit:        afee63affe8b6263644300003a91af5facb758a4
Parent:        ff4286b6c5d15a41d17a1ee309c9e59993035728
Author:        David Lutterkort <lutter redhat com>
AuthorDate:    Thu Mar 19 21:11:45 2009 -0700
Committer:     David Lutterkort <lutter redhat com>
CommitterDate: Thu Mar 19 21:11:45 2009 -0700

* src/pathx.c: call make_value before pop_value

Since make_value might realloc, pointers retrieved with pop_value may
become invalid across make_value calls.
---
 src/pathx.c |   24 ++++++++++--------------
 1 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/src/pathx.c b/src/pathx.c
index 83a8613..332aee1 100644
--- a/src/pathx.c
+++ b/src/pathx.c
@@ -446,39 +446,36 @@ static struct value *expr_value(struct expr *expr, struct state *state) {
 static void eval_expr(struct expr *expr, struct state *state);
 
 static void func_last(struct state *state) {
-    value_ind_t vind;
-
-    vind = make_value(T_NUMBER, state);
+    value_ind_t vind = make_value(T_NUMBER, state);
     CHECK_ERROR;
+
     state->value_pool[vind].number = state->ctx_len;
     push_value(vind, state);
 }
 
 static void func_position(struct state *state) {
-    value_ind_t vind;
-
-    vind = make_value(T_NUMBER, state);
+    value_ind_t vind = make_value(T_NUMBER, state);
     CHECK_ERROR;
+
     state->value_pool[vind].number = state->ctx_pos;
     push_value(vind, state);
 }
 
 static void func_count(struct state *state) {
-    value_ind_t vind;
-    struct value *ns = pop_value(state);
-
-    vind = make_value(T_NUMBER, state);
+    value_ind_t vind = make_value(T_NUMBER, state);
     CHECK_ERROR;
+
+    struct value *ns = pop_value(state);
     state->value_pool[vind].number = ns->nodeset->used;
     push_value(vind, state);
 }
 
 static void func_label(struct state *state) {
-    value_ind_t vind;
+    value_ind_t vind = make_value(T_STRING, state);
     char *s;
 
-    vind = make_value(T_STRING, state);
     CHECK_ERROR;
+
     if (state->ctx->label)
         s = strdup(state->ctx->label);
     else
@@ -553,15 +550,14 @@ static void eval_eq(struct state *state, int neq) {
 }
 
 static void eval_arith(struct state *state, enum binary_op op) {
+    value_ind_t vind = make_value(T_NUMBER, state);
     struct value *r = pop_value(state);
     struct value *l = pop_value(state);
-    value_ind_t vind;
     int res;
 
     assert(l->tag == T_NUMBER);
     assert(r->tag == T_NUMBER);
 
-    vind = make_value(T_NUMBER, state);
     CHECK_ERROR;
 
     if (op == OP_PLUS)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]