================
@@ -0,0 +1,57 @@
+// RUN: %check_clang_tidy %s bugprone-setvbuf-stack-buffer %t
+
+typedef unsigned long size_t;
+typedef struct FILE FILE;
+extern FILE *stdin;
+
+int setvbuf(FILE *stream, char *buf, int mode, size_t size);
+void *malloc(size_t size);
+void *calloc(size_t count, size_t size);
+
+#define _IOFBF 0
+#define _IOLBF 1
+#define _IONBF 2
+#define BUFSIZ 1024
+
+// Test 1: Stack buffer — should warn.
+void stack_buffer(void) {
+  char buf[BUFSIZ];
+  setvbuf(stdin, buf, _IOFBF, BUFSIZ);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: passing stack-allocated buffer 
to 'setvbuf'
+}
+
+// Test 2: NULL buffer (unbuffered) — no warning.
+void null_buffer(void) {
+  setvbuf(stdin, (void *)0, _IONBF, 0);
----------------
zeyi2 wrote:

Could we add a testcase for `NULL` itself?

https://github.com/llvm/llvm-project/pull/187637
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to