From f6a102a6c865e0c593e3d296d11ad340a581711b Mon Sep 17 00:00:00 2001 From: "yuta.256" Date: Fri, 18 Jul 2008 19:30:31 +0000 Subject: Fixed integer overflow in ss_isqrt(). --- include/divsufsort_private.h | 8 ++++---- lib/sssort.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/divsufsort_private.h b/include/divsufsort_private.h index 0d7bd28..c0ab5a6 100644 --- a/include/divsufsort_private.h +++ b/include/divsufsort_private.h @@ -78,7 +78,7 @@ extern "C" { #if defined(SS_INSERTIONSORT_THRESHOLD) # if SS_INSERTIONSORT_THRESHOLD < 1 # undef SS_INSERTIONSORT_THRESHOLD -# define SS_INSERTIONSORT_THRESHOLD 1 +# define SS_INSERTIONSORT_THRESHOLD (1) # endif #else # define SS_INSERTIONSORT_THRESHOLD (8) @@ -86,10 +86,10 @@ extern "C" { #if defined(SS_BLOCKSIZE) # if SS_BLOCKSIZE < 0 # undef SS_BLOCKSIZE -# define SS_BLOCKSIZE 0 -# elif 65536 <= SS_BLOCKSIZE +# define SS_BLOCKSIZE (0) +# elif 32768 <= SS_BLOCKSIZE # undef SS_BLOCKSIZE -# define SS_BLOCKSIZE 65535 +# define SS_BLOCKSIZE (32767) # endif #else # define SS_BLOCKSIZE (1024) diff --git a/lib/sssort.c b/lib/sssort.c index 037ac97..79ab181 100644 --- a/lib/sssort.c +++ b/lib/sssort.c @@ -84,7 +84,7 @@ ss_ilg(saidx_t n) { #if SS_BLOCKSIZE != 0 -static const int sqq_table[256] = { +static const saint_t sqq_table[256] = { 0, 16, 22, 27, 32, 35, 39, 42, 45, 48, 50, 53, 55, 57, 59, 61, 64, 65, 67, 69, 71, 73, 75, 76, 78, 80, 81, 83, 84, 86, 87, 89, 90, 91, 93, 94, 96, 97, 98, 99, 101, 102, 103, 104, 106, 107, 108, 109, @@ -108,7 +108,7 @@ saidx_t ss_isqrt(saidx_t x) { saidx_t y, e; - if(x >= (65535UL * 65535UL)) { return 65535; } + if(x >= (SS_BLOCKSIZE * SS_BLOCKSIZE)) { return SS_BLOCKSIZE; } e = (x & 0xffff0000) ? ((x & 0xff000000) ? 24 + lg_table[(x >> 24) & 0xff] : -- cgit v1.2.3