static void no_options(abts_case *tc, void *data) { int largc = 5; const char * const largv[] = {"testprog", "-a", "-b", "-c", "-d"}; apr_getopt_t *opt; apr_status_t rv; char ch; const char *optarg; char str[8196]; str[0] = '\0'; rv = apr_getopt_init(&opt, p, largc, largv); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); opt->errfn = unknown_arg; opt->errarg = str; while (apr_getopt(opt, "efgh", &ch, &optarg) == APR_SUCCESS) { switch (ch) { case 'a': case 'b': case 'c': case 'd': format_arg(str, ch, optarg); break; default: break; } } ABTS_STR_EQUAL(tc, "testprog: illegal option -- a\n", str); }
static void optional_option_notgiven(abts_case *tc, void *data) { int largc = 2; const char * const largv[] = {"testprog", "-a"}; apr_getopt_t *opt; apr_status_t rv; char ch; const char *optarg; char str[8196]; str[0] = '\0'; rv = apr_getopt_init(&opt, p, largc, largv); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); opt->errfn = unknown_arg; opt->errarg = str; while (apr_getopt(opt, "a::", &ch, &optarg) == APR_SUCCESS) { switch (ch) { case 'a': format_arg(str, ch, optarg); break; default: break; } } #if 0 /* Our version of getopt doesn't allow for optional arguments. */ ABTS_STR_EQUAL(tc, "option: a\n", str); #endif ABTS_STR_EQUAL(tc, "testprog: option requires an argument -- a\n", str); }
static void no_options_found(abts_case *tc, void *data) { int largc = 5; const char * const largv[] = {"testprog", "-a", "-b", "-c", "-d"}; apr_getopt_t *opt; apr_status_t rv; char ch; const char *optarg; char str[8196]; str[0] = '\0'; rv = apr_getopt_init(&opt, p, largc, largv); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); while (apr_getopt(opt, "abcd", &ch, &optarg) == APR_SUCCESS) { switch (ch) { case 'a': case 'b': case 'c': case 'd': default: format_arg(str, ch, optarg); } } ABTS_STR_EQUAL(tc, "option: a\n" "option: b\n" "option: c\n" "option: d\n", str); }
static void optional_option(abts_case *tc, void *data) { int largc = 3; const char * const largv[] = {"testprog", "-a", "foo"}; apr_getopt_t *opt; apr_status_t rv; char ch; const char *optarg; char str[8196]; str[0] = '\0'; rv = apr_getopt_init(&opt, p, largc, largv); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); opt->errfn = unknown_arg; opt->errarg = str; while (apr_getopt(opt, "a::", &ch, &optarg) == APR_SUCCESS) { switch (ch) { case 'a': format_arg(str, ch, optarg); break; default: break; } } ABTS_STR_EQUAL(tc, "option: a with foo\n", str); }
char * unquote_arg(const char *fmt, const char *arg, int *match, int *len) { char *ptr; char c; c = fmt[0]; fmt++; if ((ptr = strchr(fmt, c)) != NULL) { *ptr++ = '\0'; while (*ptr == ' ' || *ptr == '\t') { ptr++; } *len = ptr - fmt; return format_arg(fmt, arg, match); } else { *len = strlen(fmt); XDVI_WARNING((stderr, "Ignoring lonesome quote in string %s", fmt - 1)); return format_arg(fmt, arg, match); } }
static Boolean test_format_arg(int verbose) { static struct stringtest { char *str1; char *arg; char *result; } tests[] = { { "netscape(%s, same-window)", "file.html", "netscape(file.html, same-window)" }, { "netscape(same-window)", "file.html", "netscape(same-window)" }, { "%s", "a", "a" }, { "", "", "" }, }; size_t i; int tmpcnt = 0; Boolean result = True; for (i = 0; i < (sizeof tests / sizeof tests[0]); i++) { if (verbose) { INFO((stderr, "format_arg(%s) -> %s == %s, %d\n", tests[i].str1, format_arg(tests[i].str1, tests[i].arg, &tmpcnt), tests[i].result, tmpcnt)); } if (!test_str_equality(verbose, format_arg(tests[i].str1, tests[i].arg, &tmpcnt), tests[i].result)) { result = False; } } /* tempcnt shouldn't be reset to 0 by format_arg() */ if (tmpcnt != 1) { ERROR((stderr, "tmpcnt should be 1\n")); result = False; } return result; }
void f(char **sp, float *fp) { scanf("%as", sp); // expected-warning{{'a' length modifier is not supported by ISO C}} // TODO: Warn that the 'a' conversion specifier is a C++11 feature. printf("%a", 1.0); scanf("%afoobar", fp); } void g() { printf("%ls", "foo"); // expected-warning{{format specifies type 'wchar_t *' but the argument has type 'const char *'}} } // Test that we properly handle format_idx on C++ members. class Foo { public: const char *gettext(const char *fmt) __attribute__((format_arg(2))); int scanf(const char *, ...) __attribute__((format(scanf, 2, 3))); int printf(const char *, ...) __attribute__((format(printf, 2, 3))); int printf2(const char *, ...); static const char *gettext_static(const char *fmt) __attribute__((format_arg(1))); static int printf_static(const char *fmt, ...) __attribute__((format(printf, 1, 2))); }; void h(int *i) { Foo foo; foo.scanf("%d"); // expected-warning{{more '%' conversions than data arguments}} foo.printf("%d", i); // expected-warning{{format specifies type 'int' but the argument has type 'int *'}} Foo::printf_static("%d", i); // expected-warning{{format specifies type 'int' but the argument has type 'int *'}}
//:: if call[0] == "MODIFY_FIELD": //:: dst = args[0][1] //:: dst_bytes = field_info[dst]["byte_width_phv"] //:: src_type, src = args[1] //:: src_bytes = arg_byte_width(action, args[1]) //:: if len(args) > 2: //:: mask_str = format_arg(action, args[2]) //:: mask_bytes = arg_byte_width(action, args[2]) //:: else: //:: mask = [255 for i in xrange(dst_bytes)] //:: mask_str = format_arg(action, ("immediate", mask)) //:: mask_bytes = dst_bytes //:: #endif //:: if src_type == "field_ref": MODIFY_FIELD(phv, ${format_arg(action, args[0])}, ${dst_bytes}, ${format_arg(action, args[1])}, ${src_bytes}, ${mask_str}, ${mask_bytes}); //:: else: MODIFY_FIELD_GENERIC(phv, ${format_arg(action, args[0])}, ${dst_bytes}, ${format_arg(action, args[1])}, ${src_bytes}, ${mask_str}, ${mask_bytes}); //:: #endif //:: elif call[0] == "MODIFY_FIELD_WITH_HASH_BASED_OFFSET": //:: dst = args[0][1] //:: dst_bytes = field_info[dst]["byte_width_phv"] //:: mask = [255 for i in xrange(dst_bytes)] //:: mask_str = format_arg(action, ("immediate", mask)) //:: mask_bytes = dst_bytes MODIFY_FIELD_WITH_HASH_BASED_OFFSET(phv,
/* Test for format attributes: test bad uses of __attribute__. */ /* Origin: Joseph Myers <*****@*****.**> */ /* { dg-do compile } */ /* { dg-options "-std=gnu99 -Wformat" } */ #define DONT_GNU_PROTOTYPE #include "format.h" /* Proper uses of the attributes. */ extern void fa0 (const char *, ...) __attribute__((format(gnu_attr_printf, 1, 2))); extern void fa1 (char *, ...) __attribute__((format(gnu_attr_printf, 1, 2))); extern char *fa2 (const char *) __attribute__((format_arg(1))); extern char *fa3 (char *) __attribute__((format_arg(1))); /* Uses with too few or too many arguments. */ extern void fb0 (const char *, ...) __attribute__((format)); /* { dg-error "wrong number of arguments" "bad format" } */ extern void fb1 (const char *, ...) __attribute__((format())); /* { dg-error "wrong number of arguments" "bad format" } */ extern void fb2 (const char *, ...) __attribute__((format(gnu_attr_printf))); /* { dg-error "wrong number of arguments" "bad format" } */ extern void fb3 (const char *, ...) __attribute__((format(gnu_attr_printf, 1))); /* { dg-error "wrong number of arguments" "bad format" } */ extern void fb4 (const char *, ...) __attribute__((format(gnu_attr_printf, 1, 2, 3))); /* { dg-error "wrong number of arguments" "bad format" } */ extern void fc1 (const char *) __attribute__((format_arg)); /* { dg-error "wrong number of arguments" "bad format_arg" } */ extern void fc2 (const char *) __attribute__((format_arg())); /* { dg-error "wrong number of arguments" "bad format_arg" } */ extern void fc3 (const char *) __attribute__((format_arg(1, 2))); /* { dg-error "wrong number of arguments" "bad format_arg" } */ /* These attributes presently only apply to declarations, not to types. Eventually, they should be usable with declarators for function types anywhere, but still not with structure/union/enum types. */ struct s0 { int i; } __attribute__((format(gnu_attr_printf, 1, 2))); /* { dg-error "does not apply|only applies" "format on struct" } */ union u0 { int i; } __attribute__((format(gnu_attr_printf, 1, 2))); /* { dg-error "does not apply|only applies" "format on union" } */ enum e0 { E0V0 } __attribute__((format(gnu_attr_printf, 1, 2))); /* { dg-error "does not apply|only applies" "format on enum" } */
#define VC_EXTRALEAN #ifndef __MINGW32__ #define NOGDI #endif #define NOCRYPT #include "postgres_fe.h" #include "win32.h" /* Declared here to avoid pulling in all includes, which causes name collissions */ #ifdef ENABLE_NLS extern char * libpq_gettext(const char *msgid) __attribute__((format_arg(1))); #else #define libpq_gettext(x) (x) #endif static struct WSErrorEntry { DWORD error; const char *description; } WSErrors[] = { { 0, "No error" },
// Test for format attributes: test applying them to types in C++. // Origin: Joseph Myers <*****@*****.**> // { dg-do compile } // { dg-options "-Wformat" } __attribute__((format(printf, 1, 2))) void (*tformatprintf0) (const char *, ...); void (*tformatprintf1) (const char *, ...) __attribute__((format(printf, 1, 2))); void (__attribute__((format(printf, 1, 2))) *tformatprintf2) (const char *, ...); void (__attribute__((format(printf, 1, 2))) ****tformatprintf3) (const char *, ...); char * (__attribute__((format_arg(1))) *tformat_arg) (const char *); void baz (int i) { (*tformatprintf0) ("%d", i); (*tformatprintf0) ((*tformat_arg) ("%d"), i); (*tformatprintf0) ("%"); // { dg-warning "format" "prefix" } (*tformatprintf0) ((*tformat_arg) ("%")); // { dg-warning "format" "prefix" } (*tformatprintf1) ("%d", i); (*tformatprintf1) ((*tformat_arg) ("%d"), i); (*tformatprintf1) ("%"); // { dg-warning "format" "postfix" } (*tformatprintf1) ((*tformat_arg) ("%")); // { dg-warning "format" "postfix" } (*tformatprintf2) ("%d", i); (*tformatprintf2) ((*tformat_arg) ("%d"), i); (*tformatprintf2) ("%"); // { dg-warning "format" "nested" } (*tformatprintf2) ((*tformat_arg) ("%")); // { dg-warning "format" "nested" } (****tformatprintf3) ("%d", i); (****tformatprintf3) ((*tformat_arg) ("%d"), i); (****tformatprintf3) ("%"); // { dg-warning "format" "nested 2" } (****tformatprintf3) ((*tformat_arg) ("%")); // { dg-warning "format" "nested 2" }
(void)0/* vprintf(...) would go here */; } void callnull(void){ null(0, 0); // no error null(0, (char*)0); // no error null(0, (void*)0); // no error null(0, (int*)0); // expected-warning {{incompatible pointer types}} } // PR4470 int xx_vprintf(const char *, va_list); const char *foo(const char *format) __attribute__((format_arg(1))); void __attribute__((format(printf, 1, 0))) foo2(const char *fmt, va_list va) { xx_vprintf(foo(fmt), va); } // PR6542 extern void gcc_format (const char *, ...) __attribute__ ((__format__(__gcc_diag__, 1, 2))); extern void gcc_cformat (const char *, ...) __attribute__ ((__format__(__gcc_cdiag__, 1, 2))); extern void gcc_cxxformat (const char *, ...) __attribute__ ((__format__(__gcc_cxxdiag__, 1, 2))); extern void gcc_tformat (const char *, ...) __attribute__ ((__format__(__gcc_tdiag__, 1, 2)));
extern void tformatscanf (const char *, ...) __attribute__((format(gnu_attr_scanf, 1, 2))); extern void tformat__scanf__ (const char *, ...) __attribute__((format(gnu_attr___scanf__, 1, 2))); extern void tformatstrftime (const char *) __attribute__((format(gnu_attr_strftime, 1, 0))); extern void tformat__strftime__ (const char *) __attribute__((format(gnu_attr___strftime__, 1, 0))); extern void tformatstrfmon (const char *, ...) __attribute__((format(strfmon, 1, 2))); extern void tformat__strfmon__ (const char *, ...) __attribute__((format(__strfmon__, 1, 2))); extern void t__format__printf (const char *, ...) __attribute__((__format__(gnu_attr_printf, 1, 2))); extern void t__format____printf__ (const char *, ...) __attribute__((__format__(gnu_attr___printf__, 1, 2))); extern void t__format__scanf (const char *, ...) __attribute__((__format__(gnu_attr_scanf, 1, 2))); extern void t__format____scanf__ (const char *, ...) __attribute__((__format__(gnu_attr___scanf__, 1, 2))); extern void t__format__strftime (const char *) __attribute__((__format__(gnu_attr_strftime, 1, 0))); extern void t__format____strftime__ (const char *) __attribute__((__format__(gnu_attr___strftime__, 1, 0))); extern void t__format__strfmon (const char *, ...) __attribute__((__format__(strfmon, 1, 2))); extern void t__format____strfmon__ (const char *, ...) __attribute__((__format__(__strfmon__, 1, 2))); extern char *tformat_arg (const char *) __attribute__((format_arg(1))); extern char *t__format_arg__ (const char *) __attribute__((__format_arg__(1))); void foo (int i, int *ip, double d) { tformatprintf ("%d", i); tformatprintf ("%"); /* { dg-warning "format" "attribute format printf" } */ tformat__printf__ ("%d", i); tformat__printf__ ("%"); /* { dg-warning "format" "attribute format __printf__" } */ tformatscanf ("%d", ip); tformatscanf ("%"); /* { dg-warning "format" "attribute format scanf" } */ tformat__scanf__ ("%d", ip); tformat__scanf__ ("%"); /* { dg-warning "format" "attribute format __scanf__" } */ tformatstrftime ("%a"); tformatstrftime ("%"); /* { dg-warning "format" "attribute format strftime" } */
int main(int argc, char ** argv) { try { const std::string description = "Parallel Empirical Variogram: A massively parallel solution " "for computing empirical variograms of large-scale data."; const std::string input_desc = "Path to input file"; const std::string output_desc = "Path to output file. Defaults to stdout."; const std::string timing_desc = "Path to timing file. " "Defaults to not writing timing information."; const std::string repl_desc = "Desired replication factor. Defaults to 1."; const std::string bins_desc = "Number of distance bins to use for empirical variogram. " "Defaults to 15."; const std::string format_desc = "Prints information about output formats instead of performing computations."; // TODO: Improve input file descriptions to describe output formats TCLAP::CmdLine cmd(description, ' ', "0.1"); TCLAP::ValueArg<std::string> input_file_arg("i", "input", input_desc, true, "", "path"); TCLAP::ValueArg<std::string> output_file_arg("o", "output", output_desc, false, "", "path"); TCLAP::ValueArg<std::string> timing_file_arg("t", "timing", timing_desc, false, "", "path"); // TCLAP::ValueArg<int> repl_factor_arg("c", "replication", repl_desc, // false, 1, &positive_constraint); TCLAP::ValueArg<int> num_bins_arg("b", "bins", bins_desc, false, 15, &positive_constraint); TCLAP::SwitchArg format_arg("p", "print-formats", format_desc, false); // We only want EITHER input file or format cmd.xorAdd(input_file_arg, format_arg); cmd.add(output_file_arg); cmd.add(timing_file_arg); // cmd.add(repl_factor_arg); cmd.add(num_bins_arg); cmd.parse(argc, argv); const int num_bins = num_bins_arg.getValue(); // const int replication_factor = repl_factor_arg.getValue(); const std::string input_path = input_file_arg.getValue(); const std::string output_path = output_file_arg.getValue(); const std::string timing_path = timing_file_arg.getValue(); MPI_Init(&argc, &argv); int rank, ranks; MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &ranks); if (format_arg.isSet()) { if (rank == 0) print_formats(); MPI_Finalize(); return 0; } pev::parallel_options options(ranks, 1); if (rank == 0) { std::cout << "Using " << options.active_processor_count() << " of " << ranks << " processors with replication factor " << options.replication_factor() << std::endl; } pev::variogram_data variogram = pev::empirical_variogram_parallel(input_path, num_bins); if (rank == 0) { std::ofstream outfile; if (output_file_arg.isSet()) outfile.open(output_path); // Print to stdout if output file not supplied std::ostream & out = output_file_arg.isSet() ? outfile : std::cout; pev::print_variogram(out, variogram); if (timing_file_arg.isSet()) { std::ofstream outfile; // Append to timing file if path is given if (timing_path != "-") outfile.open(timing_path, std::ios_base::out | std::ios_base::app); std::ostream & out = timing_path == "-" ? std::cout : outfile; pev::print_timing_info(out, variogram); } } MPI_Finalize(); return 0; } catch (const TCLAP::ArgException & e) { std::cerr << "ERROR: " << e.what() << " for argument " << e.argId() << std::endl; return -1; } }