From 5e94179a29dffe9c29479e998c75b24087f5ab60 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Sat, 30 Jun 2012 13:14:57 -0300 Subject: [PATCH] tools/libtxt/edit.c (text2edit): disentangle confused logic of "e" variable We used it for the whole list and the current element, which didn't work very well. --- tools/libtxt/edit.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tools/libtxt/edit.c b/tools/libtxt/edit.c index 543b457..65e5f9f 100644 --- a/tools/libtxt/edit.c +++ b/tools/libtxt/edit.c @@ -168,8 +168,8 @@ static int parse_coord(struct edit *e, const char *s, struct edit *text2edit(const char *s) { - struct edit *e = NULL; - struct edit **last = &e; + struct edit *edits = NULL, *e; + struct edit **last = &edits; const char *start; int have_text = 0; char *end; @@ -187,12 +187,13 @@ struct edit *text2edit(const char *s) if (*s == '\n' && !have_text) continue; - *last = malloc(sizeof(struct edit)); - if (!*last) + e = malloc(sizeof(struct edit)); + if (!e) abort(); - (*last)->type = edit_nl; /* pick something without data */ - (*last)->next = NULL; - last = &(*last)->next; + e->type = edit_nl; /* pick something without data */ + e->next = NULL; + *last = e; + last = &e->next; if (*s == '\n') continue; @@ -238,7 +239,7 @@ struct edit *text2edit(const char *s) } if (s != start) add_string(&last, start, s-start); - return e; + return edits; fail: free_edit(e);