fixed the processed length calculation bug in feed_json_data() in xli/json.c

This commit is contained in:
hyung-hwan 2019-06-13 05:45:47 +00:00
parent df7a5eda5f
commit 4d556c475a
3 changed files with 12 additions and 12 deletions

View File

@ -520,18 +520,18 @@ static int fnc_sleep (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
rx = 0; rx = 0;
#elif defined(__DOS__) #elif defined(__DOS__)
#if (defined(__WATCOMC__) && (__WATCOMC__ < 1200)) #if (defined(__WATCOMC__) && (__WATCOMC__ < 1200))
sleep (lv); sleep (lv);
rx = 0; rx = 0;
#else #else
rx = sleep (lv); rx = sleep (lv);
#endif #endif
#elif defined(HAVE_NANOSLEEP) #elif defined(HAVE_NANOSLEEP)
struct timespec req; struct timespec req;
req.tv_sec = lv; req.tv_sec = lv;
req.tv_nsec = 0; req.tv_nsec = 0;
rx = nanosleep (&req, QSE_NULL); rx = nanosleep(&req, QSE_NULL);
#else #else
rx = sleep (lv); rx = sleep(lv);
#endif #endif
} }
else if (rx >= 1) else if (rx >= 1)
@ -545,28 +545,28 @@ static int fnc_sleep (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
#elif defined(__DOS__) #elif defined(__DOS__)
/* no high-resolution sleep() is available */ /* no high-resolution sleep() is available */
#if (defined(__WATCOMC__) && (__WATCOMC__ < 1200)) #if (defined(__WATCOMC__) && (__WATCOMC__ < 1200))
sleep ((qse_awk_int_t)fv); sleep ((qse_awk_int_t)fv);
rx = 0; rx = 0;
#else #else
rx = sleep ((qse_awk_int_t)fv); rx = sleep((qse_awk_int_t)fv);
#endif; #endif;
#elif defined(HAVE_NANOSLEEP) #elif defined(HAVE_NANOSLEEP)
struct timespec req; struct timespec req;
req.tv_sec = (qse_awk_int_t)fv; req.tv_sec = (qse_awk_int_t)fv;
req.tv_nsec = QSE_SEC_TO_NSEC(fv - req.tv_sec); req.tv_nsec = QSE_SEC_TO_NSEC(fv - req.tv_sec);
rx = nanosleep (&req, QSE_NULL); rx = nanosleep(&req, QSE_NULL);
#elif defined(HAVE_SELECT) #elif defined(HAVE_SELECT)
struct timeval req; struct timeval req;
req.tv_sec = (qse_awk_int_t)fv; req.tv_sec = (qse_awk_int_t)fv;
req.tv_usec = QSE_SEC_TO_USEC(fv - req.tv_sec); req.tv_usec = QSE_SEC_TO_USEC(fv - req.tv_sec);
rx = select (0, QSE_NULL, QSE_NULL, QSE_NULL, &req); rx = select(0, QSE_NULL, QSE_NULL, QSE_NULL, &req);
#else #else
/* no high-resolution sleep() is available */ /* no high-resolution sleep() is available */
rx = sleep ((qse_awk_int_t)fv); rx = sleep((qse_awk_int_t)fv);
#endif #endif
} }
retv = qse_awk_rtx_makeintval (rtx, rx); retv = qse_awk_rtx_makeintval(rtx, rx);
if (retv == QSE_NULL) return -1; if (retv == QSE_NULL) return -1;
qse_awk_rtx_setretval (rtx, retv); qse_awk_rtx_setretval (rtx, retv);

View File

@ -3071,7 +3071,7 @@ static int run_printf (qse_awk_rtx_t* rtx, qse_awk_nde_print_t* nde)
case QSE_AWK_VAL_MBS: case QSE_AWK_VAL_MBS:
/* perform the formatted output */ /* perform the formatted output */
n = output_formatted_bytes (rtx, nde->out_type, dst, ((qse_awk_val_mbs_t*)v)->val.ptr, ((qse_awk_val_mbs_t*)v)->val.len, head->next); n = output_formatted_bytes(rtx, nde->out_type, dst, ((qse_awk_val_mbs_t*)v)->val.ptr, ((qse_awk_val_mbs_t*)v)->val.len, head->next);
qse_awk_rtx_refdownval (rtx, v); qse_awk_rtx_refdownval (rtx, v);
if (n <= -1) if (n <= -1)
{ {

View File

@ -796,7 +796,7 @@ static int feed_json_data (qse_json_t* json, const qse_mchar_t* data, qse_size_t
else if (n > bcslen) else if (n > bcslen)
{ {
/* incomplete sequence */ /* incomplete sequence */
*xlen = bcslen; /* need at lease this much */ *xlen = ptr - data; /* didn't manage to process in full */
return 0; /* feed more for incomplete sequence */ return 0; /* feed more for incomplete sequence */
} }