diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2019-06-05 16:34:43 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2019-06-05 16:34:43 +0300 |
commit | b9e95e79712c1e0021e63204e0d910da2ec2692a (patch) | |
tree | d4d70a225257807223d944972cd3a25b9bb055a4 /src/wordsplit.c | |
parent | 1fa2dd2c6587822ff682581643499c3c3b78c9ea (diff) | |
download | grecs-b9e95e79712c1e0021e63204e0d910da2ec2692a.tar.gz grecs-b9e95e79712c1e0021e63204e0d910da2ec2692a.tar.bz2 |
wordsplit: special handling for WRDSE_USAGE.
* src/wordsplit.c (wordsplit_run): Initialize ws_errctx early. This
ensures that wordsplit_strerror gets correct data after WRDSE_USAGE.
(wordsplit_free): Return immediately if errno was WRDSE_USAGE.
Diffstat (limited to 'src/wordsplit.c')
-rw-r--r-- | src/wordsplit.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/wordsplit.c b/src/wordsplit.c index 48312bb..b38dde4 100644 --- a/src/wordsplit.c +++ b/src/wordsplit.c @@ -2677,24 +2677,26 @@ wordsplit_process_list (struct wordsplit *wsp, size_t start) } return wsp->ws_errno; } static int wordsplit_run (const char *command, size_t length, struct wordsplit *wsp, int flags, int lvl) { int rc; size_t start; + /* Initialize error context early */ + wsp->ws_errctx = NULL; if (!command) { if (!(flags & WRDSF_INCREMENTAL)) return _wsplt_seterr (wsp, WRDSE_USAGE); if (wsp->ws_head) return wordsplit_finish (wsp); start = skip_delim_real (wsp); if (wsp->ws_endp == wsp->ws_len) return _wsplt_seterr (wsp, WRDSE_NOINPUT); @@ -2787,24 +2789,28 @@ wordsplit_clearerr (struct wordsplit *ws) free (ws->ws_usererr); ws->ws_usererr = NULL; free (ws->ws_errctx); ws->ws_errctx = NULL; ws->ws_errno = WRDSE_OK; } void wordsplit_free (struct wordsplit *ws) { + if (ws->ws_errno == WRDSE_USAGE) + /* Usage error: the structure is not properly initialized and there's + nothing to free. */ + return; wordsplit_clearerr (ws); wordsplit_free_nodes (ws); wordsplit_free_words (ws); free (ws->ws_wordv); ws->ws_wordv = NULL; wordsplit_free_envbuf (ws); wordsplit_free_parambuf (ws); } int wordsplit_get_words (struct wordsplit *ws, size_t *wordc, char ***wordv) { |