summaryrefslogtreecommitdiffstats
path: root/test/unit
diff options
context:
space:
mode:
authorJason Evans <je@fb.com>2016-02-25 23:29:49 (GMT)
committerJason Evans <je@fb.com>2016-02-25 23:29:49 (GMT)
commit0c516a00c4cb28cff55ce0995f756b5aae074c9e (patch)
tree9752d36c7303bae8567cc01ec0347d658c6d7207 /test/unit
parent767d85061a6fb88ec977bbcd9b429a43aff391e6 (diff)
downloadjemalloc-0c516a00c4cb28cff55ce0995f756b5aae074c9e.zip
jemalloc-0c516a00c4cb28cff55ce0995f756b5aae074c9e.tar.gz
jemalloc-0c516a00c4cb28cff55ce0995f756b5aae074c9e.tar.bz2
Make *allocx() size class overflow behavior defined.
Limit supported size and alignment to HUGE_MAXCLASS, which in turn is now limited to be less than PTRDIFF_MAX. This resolves #278 and #295.
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/size_classes.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/test/unit/size_classes.c b/test/unit/size_classes.c
index d3aaebd..3a2126f 100644
--- a/test/unit/size_classes.c
+++ b/test/unit/size_classes.c
@@ -80,10 +80,33 @@ TEST_BEGIN(test_size_classes)
}
TEST_END
+TEST_BEGIN(test_overflow)
+{
+ size_t max_size_class;
+
+ max_size_class = get_max_size_class();
+
+ assert_u_ge(size2index(max_size_class+1), NSIZES,
+ "size2index() should return >= NSIZES on overflow");
+ assert_u_ge(size2index(PTRDIFF_MAX+1), NSIZES,
+ "size2index() should return >= NSIZES on overflow");
+ assert_u_ge(size2index(SIZE_T_MAX), NSIZES,
+ "size2index() should return >= NSIZES on overflow");
+
+ assert_zu_gt(s2u(max_size_class+1), HUGE_MAXCLASS,
+ "s2u() should return > HUGE_MAXCLASS for unsupported size");
+ assert_zu_gt(s2u(PTRDIFF_MAX+1), HUGE_MAXCLASS,
+ "s2u() should return > HUGE_MAXCLASS for unsupported size");
+ assert_zu_eq(s2u(SIZE_T_MAX), 0,
+ "s2u() should return 0 on overflow");
+}
+TEST_END
+
int
main(void)
{
return (test(
- test_size_classes));
+ test_size_classes,
+ test_overflow));
}