35 lines · cpp
1// Test that the common part implementation of *printf interceptors does not2// cause negative-size-param false positives.3 4// RUN: %clangxx -O2 %s -o %t5// RUN: %env_tool_opts=check_printf=1 %run %t 2>&16 7// FIXME: The maximum supported allocation size is too platform-specific:8// REQUIRES: x86_64-target-arch9 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 18void write(char *buf, int buf_size, const char *fmt, ...) {19 va_list args;20 va_start(args, fmt);21 vsnprintf(buf, buf_size, fmt, args);22 va_end(args);23}24 25int main() {26 char buffer[100];27 const size_t kStrSize = 1UL << 31;28 char *x = (char *)malloc(kStrSize);29 memset(x, '=', kStrSize - 1);30 x[kStrSize - 1] = 0;31 write(buffer, 100, "%s\n", x);32 free(x);33 return 0;34}35