Bug 1814798 - pt 1. Add bool to enable/disable PHC at runtime r=glandium
[gecko.git] / build / clang-plugin / tests / TestSprintfLiteral.cpp
blob3c54ce004f2711ed83656d10fe1bb59271ba916a
1 #include <cstdio>
3 void bad() {
4 char x[100];
5 snprintf(x, sizeof(x), "bar"); // expected-error {{Use SprintfLiteral instead of snprintf when writing into a character array.}} expected-note {{This will prevent passing in the wrong size to snprintf accidentally.}}
6 snprintf(x, 100, "bar"); // expected-error {{Use SprintfLiteral instead of snprintf when writing into a character array.}} expected-note {{This will prevent passing in the wrong size to snprintf accidentally.}}
7 const int hundred = 100;
8 snprintf(x, hundred, "bar"); // expected-error {{Use SprintfLiteral instead of snprintf when writing into a character array.}} expected-note {{This will prevent passing in the wrong size to snprintf accidentally.}}
11 void ok() {
12 char x[100];
13 int y;
14 snprintf(x, sizeof(y), "foo");
16 snprintf(x, 50, "foo");
18 int nothundred = 100;
19 nothundred = 99;
20 snprintf(x, nothundred, "foo");
23 void vargs_bad(va_list args) {
24 char x[100];
25 vsnprintf(x, sizeof(x), "bar", args); // expected-error {{Use VsprintfLiteral instead of vsnprintf when writing into a character array.}} expected-note {{This will prevent passing in the wrong size to vsnprintf accidentally.}}
26 vsnprintf(x, 100, "bar", args); // expected-error {{Use VsprintfLiteral instead of vsnprintf when writing into a character array.}} expected-note {{This will prevent passing in the wrong size to vsnprintf accidentally.}}
27 const int hundred = 100;
28 vsnprintf(x, hundred, "bar", args); // expected-error {{Use VsprintfLiteral instead of vsnprintf when writing into a character array.}} expected-note {{This will prevent passing in the wrong size to vsnprintf accidentally.}}
31 void vargs_good(va_list args) {
32 char x[100];
33 int y;
34 vsnprintf(x, sizeof(y), "foo", args);
36 vsnprintf(x, 50, "foo", args);
38 int nothundred = 100;
39 nothundred = 99;
40 vsnprintf(x, nothundred, "foo", args);