From 017d63cd7a4bf68aa38f560a3064335932a3c412 Mon Sep 17 00:00:00 2001 From: "Emden R. Gansner" Date: Thu, 19 Dec 2013 17:14:58 -0500 Subject: [PATCH] Fix bug in split function --- lib/expr/exeval.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/expr/exeval.c b/lib/expr/exeval.c index 4ed1eeeae..d2d2f886f 100644 --- a/lib/expr/exeval.c +++ b/lib/expr/exeval.c @@ -713,16 +713,20 @@ exsplit(Expr_t * ex, register Exnode_t * expr, void *env) v.integer = 0; while (*str) { sz = strspn (str, seps); - for (i = 0; i < sz; i++) { - addItem (arr, v, ""); - v.integer++; + if (sz) { + if (v.integer == 0) { /* initial separator => empty field */ + addItem (arr, v, ""); + v.integer++; + } + for (i = 1; i < sz; i++) { + addItem (arr, v, ""); + v.integer++; + } } str += sz; - if (*str == '\0') { - if (v.integer == sz) { /* only separators */ - addItem (arr, v, ""); - v.integer++; - } + if (*str == '\0') { /* terminal separator => empty field */ + addItem (arr, v, ""); + v.integer++; break; } sz = strcspn (str, seps); -- 2.40.0