fixed the potential overflow issue that would never happen in various binary serach functions

This commit is contained in:
hyung-hwan 2017-05-02 01:14:32 +00:00
parent 8093f20372
commit b96113159b
15 changed files with 76 additions and 55 deletions

View File

@ -118,11 +118,11 @@ subdir = lib/awk
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_sign.m4 \
$(top_srcdir)/m4/ax_cxx_namespace.m4 \
$(top_srcdir)/m4/ax_numval.m4 $(top_srcdir)/m4/ax_pthread.m4 \
$(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltargz.m4 \
$(top_srcdir)/m4/ltdl.m4 $(top_srcdir)/m4/ltoptions.m4 \
$(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \
$(top_srcdir)/m4/lt~obsolete.m4 \
$(top_srcdir)/m4/ax_lib_mysql.m4 $(top_srcdir)/m4/ax_numval.m4 \
$(top_srcdir)/m4/ax_pthread.m4 $(top_srcdir)/m4/libtool.m4 \
$(top_srcdir)/m4/ltargz.m4 $(top_srcdir)/m4/ltdl.m4 \
$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
$(top_srcdir)/m4/lx_find_mpi.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
@ -445,6 +445,10 @@ MKDIR_P = @MKDIR_P@
MPICC = @MPICC@
MPI_CFLAGS = @MPI_CFLAGS@
MPI_CLDFLAGS = @MPI_CLDFLAGS@
MYSQL_CFLAGS = @MYSQL_CFLAGS@
MYSQL_CONFIG = @MYSQL_CONFIG@
MYSQL_LDFLAGS = @MYSQL_LDFLAGS@
MYSQL_VERSION = @MYSQL_VERSION@
NM = @NM@
NMEDIT = @NMEDIT@
OBJDUMP = @OBJDUMP@

View File

@ -570,7 +570,7 @@ static int query (qse_awk_mod_t* mod, qse_awk_t* awk, const qse_char_t* name, qs
while (left <= right)
{
mid = (left + right) / 2;
mid = left + (right - left) / 2;
n = qse_strcmp (fnctab[mid].name, name);
if (n > 0) right = mid - 1;
@ -586,7 +586,7 @@ static int query (qse_awk_mod_t* mod, qse_awk_t* awk, const qse_char_t* name, qs
left = 0; right = QSE_COUNTOF(inttab) - 1;
while (left <= right)
{
mid = (left + right) / 2;
mid = left + (right - left) / 2;
n = qse_strcmp (inttab[mid].name, name);
if (n > 0) right = mid - 1;

View File

@ -619,7 +619,7 @@ static int query (qse_awk_mod_t* mod, qse_awk_t* awk, const qse_char_t* name, qs
while (left <= right)
{
mid = (left + right) / 2;
mid = left + (right - left) / 2;
n = qse_strcmp (fnctab[mid].name, name);
if (n > 0) right = mid - 1;
@ -636,7 +636,7 @@ static int query (qse_awk_mod_t* mod, qse_awk_t* awk, const qse_char_t* name, qs
left = 0; right = QSE_COUNTOF(inttab) - 1;
while (left <= right)
{
mid = (left + right) / 2;
mid = left + (right - left) / 2;
n = qse_strcmp (inttab[mid].name, name);
if (n > 0) right = mid - 1;

View File

@ -206,7 +206,7 @@ static int query (qse_awk_mod_t* mod, qse_awk_t* awk, const qse_char_t* name, qs
while (left <= right)
{
mid = (left + right) / 2;
mid = left + (right - left) / 2;
n = qse_strcmp (fnctab[mid].name, name);
if (n > 0) right = mid - 1;
@ -222,7 +222,7 @@ static int query (qse_awk_mod_t* mod, qse_awk_t* awk, const qse_char_t* name, qs
left = 0; right = QSE_COUNTOF(inttab) - 1;
while (left <= right)
{
mid = (left + right) / 2;
mid = left + (right - left) / 2;
n = qse_strcmp (inttab[mid].name, name);
if (n > 0) right = mid - 1;

View File

@ -238,7 +238,7 @@ static int query (qse_awk_mod_t* mod, qse_awk_t* awk, const qse_char_t* name, qs
while (left <= right)
{
mid = (left + right) / 2;
mid = left + (right - left) / 2;
n = qse_strcmp (fnctab[mid].name, name);
if (n > 0) right = mid - 1;

View File

@ -43,14 +43,13 @@ static int fnc_normspace (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
a0 = qse_awk_rtx_getarg(rtx, 0);
path.ptr = qse_awk_rtx_getvalstr (rtx, a0, &path.len);
if (path.ptr)
{
if (!path.ptr) return -1;
path.len = qse_strxpac (path.ptr, path.len);
retv = qse_awk_rtx_makestrval (rtx, path.ptr, path.len);
qse_awk_rtx_freevalstr (rtx, a0, path.ptr);
if (!retv) return -1;
qse_awk_rtx_setretval (rtx, retv);
}
return 0;
}
@ -65,14 +64,13 @@ static int trim (qse_awk_rtx_t* rtx, int flags)
a0 = qse_awk_rtx_getarg(rtx, 0);
path.ptr = qse_awk_rtx_getvalstr (rtx, a0, &path.len);
if (path.ptr)
{
if (!path.ptr) return -1;
npath = qse_strxtrmx (path.ptr, &path.len, flags);
retv = qse_awk_rtx_makestrval (rtx, npath, path.len);
qse_awk_rtx_freevalstr (rtx, a0, path.ptr);
if (!retv) return -1;
qse_awk_rtx_setretval (rtx, retv);
}
return 0;
}
@ -100,7 +98,7 @@ static int is_class (qse_awk_rtx_t* rtx, qse_ctype_t ctype)
a0 = qse_awk_rtx_getarg (rtx, 0);
str0 = qse_awk_rtx_getvalstr (rtx, a0, &len0);
if (str0 == QSE_NULL) return -1;
if (!str0) return -1;
if (len0 <= 0) tmp = 0;
else
@ -216,6 +214,8 @@ static int fnc_value (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
static int fnc_tonum (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
{
/* str::tonum (value) */
qse_awk_val_t* retv;
qse_awk_val_t* a0;
qse_awk_int_t lv;
@ -251,7 +251,6 @@ struct fnctab_t
qse_awk_mod_sym_fnc_t info;
};
#define A_MAX QSE_TYPE_MAX(int)
static fnctab_t fnctab[] =
@ -297,7 +296,7 @@ static int query (qse_awk_mod_t* mod, qse_awk_t* awk, const qse_char_t* name, qs
while (left <= right)
{
mid = (left + right) / 2;
mid = left + (right - left) / 2;
n = qse_strcmp (fnctab[mid].name, name);
if (n > 0) right = mid - 1;
@ -314,7 +313,7 @@ static int query (qse_awk_mod_t* mod, qse_awk_t* awk, const qse_char_t* name, qs
left = 0; right = QSE_COUNTOF(inttab) - 1;
while (left <= right)
{
mid = (left + right) / 2;
mid = left + (right - left) / 2;
n = qse_strcmp (inttab[mid].name, name);
if (n > 0) right = mid - 1;

View File

@ -966,7 +966,7 @@ static int query (qse_awk_mod_t* mod, qse_awk_t* awk, const qse_char_t* name, qs
while (left <= right)
{
mid = (left + right) / 2;
mid = left + (right - left) / 2;
n = qse_strcmp (fnctab[mid].name, name);
if (n > 0) right = mid - 1;
@ -982,7 +982,7 @@ static int query (qse_awk_mod_t* mod, qse_awk_t* awk, const qse_char_t* name, qs
left = 0; right = QSE_COUNTOF(inttab) - 1;
while (left <= right)
{
mid = (left + right) / 2;
mid = left + (right - left) / 2;
n = qse_strcmp (inttab[mid].name, name);
if (n > 0) right = mid - 1;

View File

@ -1342,7 +1342,7 @@ static int query (qse_awk_mod_t* mod, qse_awk_t* awk, const qse_char_t* name, qs
while (left <= right)
{
mid = (left + right) / 2;
mid = left + (right - left) / 2;
n = qse_strcmp (fnctab[mid].name, name);
if (n > 0) right = mid - 1;

View File

@ -6322,7 +6322,8 @@ static int classify_ident (qse_awk_t* awk, const qse_cstr_t* name)
int n;
kwent_t* kwp;
mid = (left + right) / 2;
/*mid = (left + right) / 2;*/
mid = left + (right - left) / 2;
kwp = &kwtab[mid];
n = qse_strxncmp (kwp->name.ptr, kwp->name.len, name->ptr, name->len);

View File

@ -96,11 +96,11 @@ subdir = lib/cmn
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_sign.m4 \
$(top_srcdir)/m4/ax_cxx_namespace.m4 \
$(top_srcdir)/m4/ax_numval.m4 $(top_srcdir)/m4/ax_pthread.m4 \
$(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltargz.m4 \
$(top_srcdir)/m4/ltdl.m4 $(top_srcdir)/m4/ltoptions.m4 \
$(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \
$(top_srcdir)/m4/lt~obsolete.m4 \
$(top_srcdir)/m4/ax_lib_mysql.m4 $(top_srcdir)/m4/ax_numval.m4 \
$(top_srcdir)/m4/ax_pthread.m4 $(top_srcdir)/m4/libtool.m4 \
$(top_srcdir)/m4/ltargz.m4 $(top_srcdir)/m4/ltdl.m4 \
$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
$(top_srcdir)/m4/lx_find_mpi.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
@ -341,6 +341,10 @@ MKDIR_P = @MKDIR_P@
MPICC = @MPICC@
MPI_CFLAGS = @MPI_CFLAGS@
MPI_CLDFLAGS = @MPI_CLDFLAGS@
MYSQL_CFLAGS = @MYSQL_CFLAGS@
MYSQL_CONFIG = @MYSQL_CONFIG@
MYSQL_LDFLAGS = @MYSQL_LDFLAGS@
MYSQL_VERSION = @MYSQL_VERSION@
NM = @NM@
NMEDIT = @NMEDIT@
OBJDUMP = @OBJDUMP@

View File

@ -371,7 +371,8 @@ int qse_wcstoctype (const qse_wchar_t* name, qse_wctype_t* id)
int n;
struct wtab_t* kwp;
mid = (left + right) / 2;
/*mid = (left + right) / 2;*/
mid = left + (right - left) / 2;
kwp = &wtab[mid];
n = qse_wcscmp (name, wtab->name);
@ -402,7 +403,8 @@ int qse_wcsntoctype (const qse_wchar_t* name, qse_size_t len, qse_wctype_t* id)
int n;
struct wtab_t* kwp;
mid = (left + right) / 2;
/*mid = (left + right) / 2;*/
mid = left + (right - left) / 2;
kwp = &wtab[mid];
n = qse_wcsxcmp (name, len, kwp->name);
@ -453,7 +455,8 @@ int qse_mbstoctype (const qse_mchar_t* name, qse_mctype_t* id)
int n;
struct mtab_t* kwp;
mid = (left + right) / 2;
/*mid = (left + right) / 2;*/
mid = left + (right - left) / 2;
kwp = &mtab[mid];
n = qse_mbscmp (name, mtab->name);
@ -484,7 +487,8 @@ int qse_mbsntoctype (const qse_mchar_t* name, qse_size_t len, qse_mctype_t* id)
int n;
struct mtab_t* kwp;
mid = (left + right) / 2;
/*mid = (left + right) / 2;*/
mid = left + (right - left) / 2;
kwp = &mtab[mid];
n = qse_mbsxcmp (name, len, kwp->name);

View File

@ -22705,7 +22705,8 @@ static qse_uint16_t mbtowc (qse_uint16_t c)
int left = 0, right = QSE_COUNTOF(mbtowc_range) - 1, mid;
while (left <= right)
{
mid = (left + right) / 2;
/*mid = (left + right) / 2;*/
mid = left + (right - left) / 2;
if (c >= mbtowc_range[mid].first && c <= mbtowc_range[mid].last)
return mbtowc_range[mid].seg[c - mbtowc_range[mid].first];
else if (c > mbtowc_range[mid].last)
@ -56976,7 +56977,8 @@ static qse_uint16_t wctomb (qse_uint16_t c)
int left = 0, right = QSE_COUNTOF(wctomb_range) - 1, mid;
while (left <= right)
{
mid = (left + right) / 2;
/*mid = (left + right) / 2;*/
mid = left + (right - left) / 2;
if (c >= wctomb_range[mid].first && c <= wctomb_range[mid].last)
return wctomb_range[mid].seg[c - wctomb_range[mid].first];
else if (c > wctomb_range[mid].last)

View File

@ -16831,7 +16831,8 @@ static qse_uint16_t mbtowc (qse_uint16_t c)
int left = 0, right = QSE_COUNTOF(mbtowc_range) - 1, mid;
while (left <= right)
{
mid = (left + right) / 2;
/*mid = (left + right) / 2;*/
mid = left + (right - left) / 2;
if (c >= mbtowc_range[mid].first && c <= mbtowc_range[mid].last)
return mbtowc_range[mid].seg[c - mbtowc_range[mid].first];
else if (c > mbtowc_range[mid].last)
@ -38118,7 +38119,8 @@ static qse_uint16_t wctomb (qse_uint16_t c)
int left = 0, right = QSE_COUNTOF(wctomb_range) - 1, mid;
while (left <= right)
{
mid = (left + right) / 2;
/*mid = (left + right) / 2;*/
mid = left + (right - left) / 2;
if (c >= wctomb_range[mid].first && c <= wctomb_range[mid].last)
return wctomb_range[mid].seg[c - wctomb_range[mid].first];
else if (c > wctomb_range[mid].last)

View File

@ -92,11 +92,11 @@ subdir = lib/xli
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_sign.m4 \
$(top_srcdir)/m4/ax_cxx_namespace.m4 \
$(top_srcdir)/m4/ax_numval.m4 $(top_srcdir)/m4/ax_pthread.m4 \
$(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltargz.m4 \
$(top_srcdir)/m4/ltdl.m4 $(top_srcdir)/m4/ltoptions.m4 \
$(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \
$(top_srcdir)/m4/lt~obsolete.m4 \
$(top_srcdir)/m4/ax_lib_mysql.m4 $(top_srcdir)/m4/ax_numval.m4 \
$(top_srcdir)/m4/ax_pthread.m4 $(top_srcdir)/m4/libtool.m4 \
$(top_srcdir)/m4/ltargz.m4 $(top_srcdir)/m4/ltdl.m4 \
$(top_srcdir)/m4/ltoptions.m4 $(top_srcdir)/m4/ltsugar.m4 \
$(top_srcdir)/m4/ltversion.m4 $(top_srcdir)/m4/lt~obsolete.m4 \
$(top_srcdir)/m4/lx_find_mpi.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
@ -276,6 +276,10 @@ MKDIR_P = @MKDIR_P@
MPICC = @MPICC@
MPI_CFLAGS = @MPI_CFLAGS@
MPI_CLDFLAGS = @MPI_CLDFLAGS@
MYSQL_CFLAGS = @MYSQL_CFLAGS@
MYSQL_CONFIG = @MYSQL_CONFIG@
MYSQL_LDFLAGS = @MYSQL_LDFLAGS@
MYSQL_VERSION = @MYSQL_VERSION@
NM = @NM@
NMEDIT = @NMEDIT@
OBJDUMP = @OBJDUMP@

View File

@ -267,7 +267,8 @@ static int classify_ident (qse_xli_t* xli, const qse_cstr_t* name)
int n;
kwent_t* kwp;
mid = (left + right) / 2;
/*mid = (left + right) / 2;*/
mid = left + (right - left) / 2;
kwp = &kwtab[mid];
n = qse_strxncmp (kwp->name.ptr, kwp->name.len, name->ptr, name->len);