summaryrefslogtreecommitdiff
path: root/tests/stdio_test.cpp
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2016-02-05 11:18:41 -0800
committerElliott Hughes <enh@google.com>2016-02-05 11:18:41 -0800
commit43f7c875654cb94e589ff9d0c4ac58ca9616093e (patch)
treeb59e65b86870ef89c3965f32b18c52910f6038b4 /tests/stdio_test.cpp
parentb90837c3d316c6ea8d6f0b0b6a3643d0d3245a0e (diff)
Add a test for snprintf on a PTHREAD_STACK_MIN-sized stack.
This is a common thing for people to want to do, snprintf requires a lot of stack for itself, and PTHREAD_STACK_MIN should be usable for realistic code. Change-Id: Ib09cfb4e0beec1c69ee0944c3ea4c5d03a94c491
Diffstat (limited to 'tests/stdio_test.cpp')
-rw-r--r--tests/stdio_test.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp
index 2912be4aa..79a86ad2f 100644
--- a/tests/stdio_test.cpp
+++ b/tests/stdio_test.cpp
@@ -534,6 +534,25 @@ TEST(STDIO_TEST, snprintf_utf8_15439554) {
freelocale(cloc);
}
+static void* snprintf_small_stack_fn(void*) {
+ // Make life (realistically) hard for ourselves by allocating our own buffer for the result.
+ char buf[PATH_MAX];
+ snprintf(buf, sizeof(buf), "/proc/%d", getpid());
+ return nullptr;
+}
+
+TEST(STDIO_TEST, snprintf_small_stack) {
+ // Is it safe to call snprintf on a thread with a small stack?
+ // (The snprintf implementation puts some pretty large buffers on the stack.)
+ pthread_attr_t a;
+ ASSERT_EQ(0, pthread_attr_init(&a));
+ ASSERT_EQ(0, pthread_attr_setstacksize(&a, PTHREAD_STACK_MIN));
+
+ pthread_t t;
+ ASSERT_EQ(0, pthread_create(&t, &a, snprintf_small_stack_fn, nullptr));
+ ASSERT_EQ(0, pthread_join(t, nullptr));
+}
+
TEST(STDIO_TEST, fprintf_failures_7229520) {
// http://b/7229520
FILE* fp;