diff options
author | Andrew J. Schorr <aschorr@telemetry-investments.com> | 2013-07-02 14:24:13 -0400 |
---|---|---|
committer | Andrew J. Schorr <aschorr@telemetry-investments.com> | 2013-07-02 14:24:13 -0400 |
commit | a0d911d5920362982fb6a5c1fa6047c69dc26668 (patch) | |
tree | 51420ace7a32912f37cd4dc2ed9001bd1c8dc47f /extension/select.c | |
parent | c5d29ade6407adcec3eeef9e61a1474501acc0d3 (diff) | |
download | egawk-a0d911d5920362982fb6a5c1fa6047c69dc26668.tar.gz egawk-a0d911d5920362982fb6a5c1fa6047c69dc26668.tar.bz2 egawk-a0d911d5920362982fb6a5c1fa6047c69dc26668.zip |
Tighten up some argument checks in the select extension.
Diffstat (limited to 'extension/select.c')
-rw-r--r-- | extension/select.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/extension/select.c b/extension/select.c index c1b706fc..be17dcf5 100644 --- a/extension/select.c +++ b/extension/select.c @@ -241,18 +241,22 @@ do_select(int nargs, awk_value_t *result) fds[i].array2fd[j] = -1; switch (EL.index.val_type) { case AWK_NUMBER: - if (EL.index.num_value >= 0) - fds[i].array2fd[j] = EL.index.num_value; - if (fds[i].array2fd[j] != EL.index.num_value) { - fds[i].array2fd[j] = -1; - warning(ext_id, _("select: invalid numeric index `%g' in `%s' array (should be a non-negative integer)"), EL.index.num_value, argname[i]); + if ((EL.value.val_type == AWK_UNDEFINED) || ((EL.value.val_type == AWK_STRING) && ! EL.value.str_value.len)) { + if (EL.index.num_value >= 0) + fds[i].array2fd[j] = EL.index.num_value; + if (fds[i].array2fd[j] != EL.index.num_value) { + fds[i].array2fd[j] = -1; + warning(ext_id, _("select: invalid numeric index `%g' in `%s' array (should be a non-negative integer)"), EL.index.num_value, argname[i]); + } } + else + warning(ext_id, _("select: numeric index `%g' in `%s' array should have an empty command type to be treated as a file descriptor"), EL.index.num_value, argname[i]); break; case AWK_STRING: { long x; - if ((integer_string(EL.index.str_value.str, &x) == 0) && (x >= 0)) + if ((integer_string(EL.index.str_value.str, &x) == 0) && (x >= 0) && ((EL.value.val_type == AWK_UNDEFINED) || ((EL.value.val_type == AWK_STRING) && ! EL.value.str_value.len))) fds[i].array2fd[j] = x; else if (EL.value.val_type == AWK_STRING) { const awk_input_buf_t *buf; |