aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryuta.256 <yuta.256@b7c3aa3b-274f-0410-ae0b-edc9d07c929d>2008-07-18 19:30:31 +0000
committeryuta.256 <yuta.256@b7c3aa3b-274f-0410-ae0b-edc9d07c929d>2008-07-18 19:30:31 +0000
commitf6a102a6c865e0c593e3d296d11ad340a581711b (patch)
tree57c774e29276f2bb27486f6af8d99850e13ee409
parent101c19ff41d3cebfb3702ce980d02a09f81e2e0b (diff)
downloadplatform_external_libdivsufsort-f6a102a6c865e0c593e3d296d11ad340a581711b.tar.gz
platform_external_libdivsufsort-f6a102a6c865e0c593e3d296d11ad340a581711b.tar.bz2
platform_external_libdivsufsort-f6a102a6c865e0c593e3d296d11ad340a581711b.zip
Fixed integer overflow in ss_isqrt().
-rw-r--r--include/divsufsort_private.h8
-rw-r--r--lib/sssort.c4
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] :