| 1 | // Test that the common part implementation of *printf interceptors does not |
| 2 | // cause negative-size-param false positives. |
| 3 | |
| 4 | // RUN: %clangxx -O2 %s -o %t |
| 5 | // RUN: %env_tool_opts=check_printf=1 %run %t 2>&1 |
| 6 | |
| 7 | // FIXME: The maximum supported allocation size is too platform-specific: |
| 8 | // REQUIRES: x86_64-target-arch |
| 9 | |
| 10 | // FIXME: printf is not intercepted on Windows yet. |
| 11 | // UNSUPPORTED: target={{.*windows-msvc.*}} |
| 12 | |
| 13 | #include <stdarg.h> |
| 14 | #include <stdio.h> |
| 15 | #include <stdlib.h> |
| 16 | #include <string.h> |
| 17 | |
| 18 | void write(char *buf, int buf_size, const char *fmt, ...) { |
| 19 | va_list args; |
| 20 | va_start(args, fmt); |
| 21 | vsnprintf(s: buf, maxlen: buf_size, format: fmt, arg: args); |
| 22 | va_end(args); |
| 23 | } |
| 24 | |
| 25 | int main() { |
| 26 | char buffer[100]; |
| 27 | const size_t kStrSize = 1UL << 31; |
| 28 | char *x = (char *)malloc(size: kStrSize); |
| 29 | memset(s: x, c: '=', n: kStrSize - 1); |
| 30 | x[kStrSize - 1] = 0; |
| 31 | write(buf: buffer, buf_size: 100, fmt: "%s\n" , x); |
| 32 | free(ptr: x); |
| 33 | return 0; |
| 34 | } |
| 35 | |