summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQi Wang <interwq@gwu.edu>2022-03-23 16:31:40 -0700
committerQi Wang <interwq@gmail.com>2022-04-04 12:16:46 -0700
commited5fc14b28ca62a6ba57b65adf557e1ef09037f0 (patch)
treea589e27d7818bd2f16f0fa1424c8a721657fdfcb
parent25517b852e76b429d4a97f4c96606263b2a9c209 (diff)
downloadjemalloc-ed5fc14b28ca62a6ba57b65adf557e1ef09037f0.tar.gz
Use volatile to workaround buffer overflow false positives.
In test/integration/rallocx, full usable size is checked which may confuse overflow detection.
-rw-r--r--test/integration/rallocx.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/test/integration/rallocx.c b/test/integration/rallocx.c
index d4a48fce..68b8f381 100644
--- a/test/integration/rallocx.c
+++ b/test/integration/rallocx.c
@@ -41,7 +41,11 @@ get_large_size(size_t ind) {
}
TEST_BEGIN(test_grow_and_shrink) {
- void *p, *q;
+ /*
+ * Use volatile to workaround buffer overflow false positives
+ * (-D_FORTIFY_SOURCE=3).
+ */
+ void *volatile p, *volatile q;
size_t tsz;
#define NCYCLES 3
unsigned i, j;
@@ -85,9 +89,13 @@ TEST_BEGIN(test_grow_and_shrink) {
TEST_END
static bool
-validate_fill(const void *p, uint8_t c, size_t offset, size_t len) {
+validate_fill(void *p, uint8_t c, size_t offset, size_t len) {
bool ret = false;
- const uint8_t *buf = (const uint8_t *)p;
+ /*
+ * Use volatile to workaround buffer overflow false positives
+ * (-D_FORTIFY_SOURCE=3).
+ */
+ uint8_t *volatile buf = (uint8_t *)p;
size_t i;
for (i = 0; i < len; i++) {
@@ -104,7 +112,11 @@ validate_fill(const void *p, uint8_t c, size_t offset, size_t len) {
}
TEST_BEGIN(test_zero) {
- void *p, *q;
+ /*
+ * Use volatile to workaround buffer overflow false positives
+ * (-D_FORTIFY_SOURCE=3).
+ */
+ void *volatile p, *volatile q;
size_t psz, qsz, i, j;
size_t start_sizes[] = {1, 3*1024, 63*1024, 4095*1024};
#define FILL_BYTE 0xaaU
@@ -205,7 +217,11 @@ TEST_BEGIN(test_align_enum) {
TEST_END
TEST_BEGIN(test_lg_align_and_zero) {
- void *p, *q;
+ /*
+ * Use volatile to workaround buffer overflow false positives
+ * (-D_FORTIFY_SOURCE=3).
+ */
+ void *volatile p, *volatile q;
unsigned lg_align;
size_t sz;
#define MAX_LG_ALIGN 25