Minor improvement

* src/wordsplit.c (expvar): Gracefully handle NULL values in
ENV_KV environment.
* src/wordsplit.h: Fix typo in a comment.
* doc/wordsplit.3: Update.
This commit is contained in:
Sergey Poznyakoff 2018-02-20 16:42:25 +02:00
parent d97c672079
commit 35b47a80c6
3 changed files with 13 additions and 7 deletions

View file

@ -14,7 +14,7 @@
.\" You should have received a copy of the GNU General Public License .\" You should have received a copy of the GNU General Public License
.\" along with Grecs. If not, see <http://www.gnu.org/licenses/>. .\" along with Grecs. If not, see <http://www.gnu.org/licenses/>.
.\" .\"
.TH WORDSPLIT 3 "December 3, 2014" "GRECS" "Grecs User Reference" .TH WORDSPLIT 3 "February 20, 2018" "GRECS" "Grecs User Reference"
.SH NAME .SH NAME
wordsplit \- split string into words wordsplit \- split string into words
.SH SYNOPSIS .SH SYNOPSIS
@ -181,7 +181,8 @@ elements in the array:
.IR ws_env [ n ] .IR ws_env [ n ]
containing the variable name, and containing the variable name, and
.IR ws_env [ "n+1" ] .IR ws_env [ "n+1" ]
containing its value. containing its value. If the latter is \fBNULL\fR, the corresponding
variable is undefined.
.PP .PP
More sophisticated variable tables can be implemented using More sophisticated variable tables can be implemented using
callback function. The \fIws_getvar\fR member should be set to point callback function. The \fIws_getvar\fR member should be set to point

View file

@ -81,8 +81,8 @@ struct wordsplit
void *clos); void *clos);
/* [Input] (!WRDSF_NOCMD) Returns in the memory /* [Input] (!WRDSF_NOCMD) Returns in the memory
location pointed to by RET the expansion of location pointed to by RET the expansion of
the command CMD (LEN bytes nong). If WRDSF_ARGV the command CMD (LEN bytes long). If WRDSO_ARGV
flag is set, ARGV contains CMD split out to option is set, ARGV contains CMD split out to
words. Otherwise ARGV is NULL. words. Otherwise ARGV is NULL.
See ws_getvar for a discussion of possible See ws_getvar for a discussion of possible

View file

@ -1034,9 +1034,14 @@ expvar (struct wordsplit *wsp, const char *str, size_t len,
rc = wordsplit_find_env (wsp, str, i, &vptr); rc = wordsplit_find_env (wsp, str, i, &vptr);
if (rc == WRDSE_OK) if (rc == WRDSE_OK)
{ {
value = strdup (vptr); if (vptr)
if (!value) {
rc = WRDSE_NOSPACE; value = strdup (vptr);
if (!value)
rc = WRDSE_NOSPACE;
}
else
rc = WRDSE_UNDEF;
} }
else if (wsp->ws_flags & WRDSF_GETVAR) else if (wsp->ws_flags & WRDSF_GETVAR)
rc = wsp->ws_getvar (&value, str, i, wsp->ws_closure); rc = wsp->ws_getvar (&value, str, i, wsp->ws_closure);