aboutsummaryrefslogtreecommitdiffstats
path: root/extension/select.c
diff options
context:
space:
mode:
authorAndrew J. Schorr <aschorr@telemetry-investments.com>2013-07-02 16:13:43 -0400
committerAndrew J. Schorr <aschorr@telemetry-investments.com>2013-07-02 16:13:43 -0400
commitf0391b8a4db649853ecc47a10b09d7c4b04330cf (patch)
tree6c999c4fc62c4e83830c1bdfe03690dc2f331850 /extension/select.c
parent6ace1b5a655517a41be7d1633ec7592ad940c0e6 (diff)
downloadegawk-f0391b8a4db649853ecc47a10b09d7c4b04330cf.tar.gz
egawk-f0391b8a4db649853ecc47a10b09d7c4b04330cf.tar.bz2
egawk-f0391b8a4db649853ecc47a10b09d7c4b04330cf.zip
Patch select to remove support for buggy case where the index had a numeric value.
Diffstat (limited to 'extension/select.c')
-rw-r--r--extension/select.c44
1 files changed, 12 insertions, 32 deletions
diff --git a/extension/select.c b/extension/select.c
index be17dcf5..89dbf6c3 100644
--- a/extension/select.c
+++ b/extension/select.c
@@ -238,41 +238,21 @@ do_select(int nargs, awk_value_t *result)
if (flatten_array(fds[i].array.array_cookie, &fds[i].flat)) {
emalloc(fds[i].array2fd, int *, fds[i].flat->count*sizeof(int), "select");
for (j = 0; j < fds[i].flat->count; j++) {
+ long x;
fds[i].array2fd[j] = -1;
- switch (EL.index.val_type) {
- case AWK_NUMBER:
- 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]);
- }
- }
+ /* note: the index is always delivered as a string */
+
+ if (((EL.value.val_type == AWK_UNDEFINED) || ((EL.value.val_type == AWK_STRING) && ! EL.value.str_value.len)) && (integer_string(EL.index.str_value.str, &x) == 0) && (x >= 0))
+ fds[i].array2fd[j] = x;
+ else if (EL.value.val_type == AWK_STRING) {
+ const awk_input_buf_t *buf;
+ if ((buf = get_file(EL.index.str_value.str, EL.index.str_value.len, EL.value.str_value.str, EL.value.str_value.len)) != NULL)
+ fds[i].array2fd[j] = buf->fd;
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) && ((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;
- if ((buf = get_file(EL.index.str_value.str, EL.index.str_value.len, EL.value.str_value.str, EL.value.str_value.len)) != NULL)
- fds[i].array2fd[j] = buf->fd;
- else
- warning(ext_id, _("select: get_file(`%s', `%s') failed in `%s' array"), EL.index.str_value.str, EL.value.str_value.str, argname[i]);
- }
- else
- warning(ext_id, _("select: command type should be a string for `%s' in `%s' array"), EL.index.str_value.str, argname[i]);
- }
- break;
- default:
- warning(ext_id, _("select: invalid index type in `%s' array (must be a string or a non-negative integer"), argname[i]);
- break;
+ warning(ext_id, _("select: get_file(`%s', `%s') failed in `%s' array"), EL.index.str_value.str, EL.value.str_value.str, argname[i]);
}
+ else
+ warning(ext_id, _("select: command type should be a string for `%s' in `%s' array"), EL.index.str_value.str, argname[i]);
if (fds[i].array2fd[j] < 0) {
update_ERRNO_string(_("select: get_file failed"));
if (! release_flattened_array(fds[i].array.array_cookie, fds[i].flat))