fixed a simple but critical bug in __MAKE_IMAP_NODE

This commit is contained in:
hyung-hwan 2019-08-26 10:29:26 +00:00
parent 4e6015ed36
commit d0d2a7af8c
4 changed files with 60 additions and 9 deletions

View File

@ -1491,6 +1491,55 @@ BEGIN {
} }
~~~~~ ~~~~~
~~~~~{.awk}
BEGIN {
if (sys::pipe(p0, p1, sys::O_NONBLOCK | sys::O_CLOEXEC) <= -1)
{
print "pipe error";
return -1;
}
a = sys::fork();
if (a <= -1)
{
print "fork error";
sys::close (p0);
sys::close (p1);
}
else if (a == 0)
{
## child
sys::close (p0);
stdout = sys::openfd(1);
sys::dup(p1, stdout);
print B"hello world";
print B"testing sys::dup()";
print B"writing to standard output..";
sys::close (p1);
sys::close (stdout);
}
else
{
sys::close (p1);
while (1)
{
n = sys::read(p0, k, 10);
if (n <= 0)
{
if (n == sys::RC_EAGAIN) continue; ## nonblock but data not available
if (n != 0) print "ERROR: " sys::errmsg();
break;
}
print "[" k "]";
}
sys::close (p0);
sys::wait(a);
}
}
~~~~~
~~~~~{.awk} ~~~~~{.awk}
BEGIN { BEGIN {
d = sys::opendir("/etc", sys::DIR_SORT); d = sys::opendir("/etc", sys::DIR_SORT);

View File

@ -61,16 +61,16 @@ static __IMAP_NODE_T* __MAKE_IMAP_NODE (qse_awk_rtx_t* rtx, __IMAP_LIST_T* list)
node = QSE_NULL; node = QSE_NULL;
if (list->free) node = list->free; if (list->free)
{
node = list->free;
list->free = node->next;
}
else else
{ {
node = qse_awk_rtx_callocmem(rtx, QSE_SIZEOF(*node)); node = qse_awk_rtx_callocmem(rtx, QSE_SIZEOF(*node));
if (!node) goto oops; if (!node) goto oops;
}
if (node == list->free) list->free = node->next;
else
{
if (list->map.high <= list->map.capa) if (list->map.high <= list->map.capa)
{ {
qse_size_t newcapa, inc; qse_size_t newcapa, inc;
@ -92,11 +92,12 @@ static __IMAP_NODE_T* __MAKE_IMAP_NODE (qse_awk_rtx_t* rtx, __IMAP_LIST_T* list)
} }
node->id = list->map.high; node->id = list->map.high;
QSE_ASSERT (list->map.tab[node->id] == QSE_NULL);
list->map.tab[node->id] = node;
list->map.high++; list->map.high++;
} }
QSE_ASSERT (list->map.tab[node->id] == QSE_NULL);
list->map.tab[node->id] = node;
/* append it to the tail */ /* append it to the tail */
node->next = QSE_NULL; node->next = QSE_NULL;
node->prev = list->tail; node->prev = list->tail;

View File

@ -30,6 +30,7 @@
#include <qse/cmn/mbwc.h> #include <qse/cmn/mbwc.h>
#include "../cmn/mem-prv.h" #include "../cmn/mem-prv.h"
#include "fnc.h" #include "fnc.h"
#include "val.h"
static int fnc_normspace (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi) static int fnc_normspace (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{ {

View File

@ -484,7 +484,7 @@ static int fnc_openfd (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
rx = awkerr_to_rc(qse_awk_rtx_geterrnum(rtx)); rx = awkerr_to_rc(qse_awk_rtx_geterrnum(rtx));
set_errmsg_on_sys_list (rtx, sys_list, QSE_NULL); set_errmsg_on_sys_list (rtx, sys_list, QSE_NULL);
} }
else if (fd >= 0) else if (fd >= 0 && fd <= QSE_TYPE_MAX(int))
{ {
sys_node_t* sys_node; sys_node_t* sys_node;