summaryrefslogtreecommitdiff
path: root/test/sanitizer_common/TestCases/Posix/strtonum.cc
diff options
context:
space:
mode:
Diffstat (limited to 'test/sanitizer_common/TestCases/Posix/strtonum.cc')
-rw-r--r--test/sanitizer_common/TestCases/Posix/strtonum.cc54
1 files changed, 54 insertions, 0 deletions
diff --git a/test/sanitizer_common/TestCases/Posix/strtonum.cc b/test/sanitizer_common/TestCases/Posix/strtonum.cc
new file mode 100644
index 000000000..22346b2e1
--- /dev/null
+++ b/test/sanitizer_common/TestCases/Posix/strtonum.cc
@@ -0,0 +1,54 @@
+// RUN: %clangxx -O0 -g %s -o %t && %run %t 2>&1 | FileCheck %s
+//
+// UNSUPPORTED: linux, darwin, solaris
+
+#define _OPENBSD_SOURCE
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(void) {
+ const char *errstr;
+
+ printf("strtonum\n");
+
+ long long l = strtonum("100", 1, 100, &errstr);
+ assert(!errstr);
+ printf("%lld\n", l);
+
+ l = strtonum("200", 1, 100, &errstr);
+ assert(errstr);
+ printf("%s\n", errstr);
+
+ l = strtonum("300", 1000, 1001, &errstr);
+ assert(errstr);
+ printf("%s\n", errstr);
+
+ l = strtonum("abc", 1000, 1001, &errstr);
+ assert(errstr);
+ printf("%s\n", errstr);
+
+ l = strtonum("1000", 1001, 1000, &errstr);
+ assert(errstr);
+ printf("%s\n", errstr);
+
+ l = strtonum("1000abc", 1000, 1001, &errstr);
+ assert(errstr);
+ printf("%s\n", errstr);
+
+ l = strtonum("1000.0", 1000, 1001, &errstr);
+ assert(errstr);
+ printf("%s\n", errstr);
+
+ // CHECK: strtonum
+ // CHECK: 100
+ // CHECK: too large
+ // CHECK: too small
+ // CHECK: invalid
+ // CHECK: invalid
+ // CHECK: invalid
+ // CHECK: invalid
+
+ return 0;
+}