================
@@ -29,6 +29,20 @@ void f(int x, int y) {
   return;
 }
 
+// Test nested conditional expressions:
+void testNested(char * message) {
+  fprintf(stderr, "AssertMacros: %s", (0!=0) ? message : ((0!=0) ? message : 
""));
+}
+
+// If the conditional cannot be constant-folded, try analyze both branches:
+void testConditionalAnalysis(char * message, int x) {
+  fprintf(stderr, "AssertMacros: %s", (x!=0) ? "hello" : "world");
+  fprintf(stderr, "AssertMacros: %s", (0!=0) ? message : ((x!=0) ? "hello" : 
"world"));
+  fprintf(stderr, "AssertMacros: %s", (x!=0) ? (((x!=0) ? "hello" : "world")) 
: ((x!=0) ? "hello" : "world"));
+  fprintf(stderr, "AssertMacros: %s", (x!=0) ? (((x!=0) ? "hello" : "world")) 
: ((x!=0) ? "hello" : message)); //\
+               cxx-warning{{function 'fprintf' is unsafe}} cxx-note{{string 
argument is not guaranteed to be null-terminated}}                              
                                                          
----------------
ziqingluo-90 wrote:

> Why is this raised only for C++ mode? I couldn't see any hints for that 
> restriction.

This is a part of warning about unsafe libc functions under the C++ Safe 
Buffers project.  It does not make much sense to emit these warnings on C 
programs as they don't have safe alternatives.

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

Reply via email to