summaryrefslogtreecommitdiffstats
path: root/contrib/gdtoa
diff options
context:
space:
mode:
authorattilio <attilio@FreeBSD.org>2009-09-10 11:27:07 +0000
committerattilio <attilio@FreeBSD.org>2009-09-10 11:27:07 +0000
commit0eca1d868a3519f728504706d9a7fe9128205446 (patch)
tree9fb9c3574f503521073a8e0ca0ddbbe248b41c19 /contrib/gdtoa
parent0e3b39faeb53d570b13fe926c1fe3e7aaac10d07 (diff)
downloadFreeBSD-src-0eca1d868a3519f728504706d9a7fe9128205446.zip
FreeBSD-src-0eca1d868a3519f728504706d9a7fe9128205446.tar.gz
MFC r196916:
Fix a list overrun. Sponsored by: Sandvine Incorporated Approved by: re (kib)
Diffstat (limited to 'contrib/gdtoa')
-rw-r--r--contrib/gdtoa/gdtoaimp.h2
-rw-r--r--contrib/gdtoa/misc.c18
2 files changed, 13 insertions, 7 deletions
diff --git a/contrib/gdtoa/gdtoaimp.h b/contrib/gdtoa/gdtoaimp.h
index c550ada..9991ffa 100644
--- a/contrib/gdtoa/gdtoaimp.h
+++ b/contrib/gdtoa/gdtoaimp.h
@@ -485,7 +485,7 @@ extern pthread_mutex_t __gdtoa_locks[2];
_pthread_mutex_unlock(&__gdtoa_locks[n]); \
} while(0)
-#define Kmax 15
+#define Kmax 9
struct
Bigint {
diff --git a/contrib/gdtoa/misc.c b/contrib/gdtoa/misc.c
index b3ce7c9..8d2888e 100644
--- a/contrib/gdtoa/misc.c
+++ b/contrib/gdtoa/misc.c
@@ -55,7 +55,9 @@ Balloc
#endif
ACQUIRE_DTOA_LOCK(0);
- if ( (rv = freelist[k]) !=0) {
+ /* The k > Kmax case does not need ACQUIRE_DTOA_LOCK(0), */
+ /* but this case seems very unlikely. */
+ if (k <= Kmax && (rv = freelist[k]) !=0) {
freelist[k] = rv->next;
}
else {
@@ -65,7 +67,7 @@ Balloc
#else
len = (sizeof(Bigint) + (x-1)*sizeof(ULong) + sizeof(double) - 1)
/sizeof(double);
- if (pmem_next - private_mem + len <= PRIVATE_mem) {
+ if (k <= Kmax && pmem_next - private_mem + len <= PRIVATE_mem) {
rv = (Bigint*)pmem_next;
pmem_next += len;
}
@@ -89,10 +91,14 @@ Bfree
#endif
{
if (v) {
- ACQUIRE_DTOA_LOCK(0);
- v->next = freelist[v->k];
- freelist[v->k] = v;
- FREE_DTOA_LOCK(0);
+ if (v->k > Kmax)
+ free((void*)v);
+ else {
+ ACQUIRE_DTOA_LOCK(0);
+ v->next = freelist[v->k];
+ freelist[v->k] = v;
+ FREE_DTOA_LOCK(0);
+ }
}
}
OpenPOWER on IntegriCloud