MCPcopy Create free account
hub / github.com/apache/kudu / StringPrintfVector

Function StringPrintfVector

src/kudu/gutil/stringprintf.cc:107–139  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

105static const char string_printf_empty_block[256] = { '\0' };
106
107string StringPrintfVector(const char* format, const vector<string>& v) {
108 CHECK_LE(v.size(), kStringPrintfVectorMaxArgs)
109 << "StringPrintfVector currently only supports up to "
110 << kStringPrintfVectorMaxArgs << " arguments. "
111 << "Feel free to add support for more if you need it.";
112
113 // Add filler arguments so that bogus format+args have a harder time
114 // crashing the program, corrupting the program (%n),
115 // or displaying random chunks of memory to users.
116
117 const char* cstr[kStringPrintfVectorMaxArgs];
118 for (int i = 0; i < v.size(); ++i) {
119 cstr[i] = v[i].c_str();
120 }
121 for (int i = v.size(); i < arraysize(cstr); ++i) {
122 cstr[i] = &string_printf_empty_block[0];
123 }
124
125 // I do not know any way to pass kStringPrintfVectorMaxArgs arguments,
126 // or any way to build a va_list by hand, or any API for printf
127 // that accepts an array of arguments. The best I can do is stick
128 // this COMPILE_ASSERT right next to the actual statement.
129
130 COMPILE_ASSERT(kStringPrintfVectorMaxArgs == 32, arg_count_mismatch);
131 return StringPrintf(format,
132 cstr[0], cstr[1], cstr[2], cstr[3], cstr[4],
133 cstr[5], cstr[6], cstr[7], cstr[8], cstr[9],
134 cstr[10], cstr[11], cstr[12], cstr[13], cstr[14],
135 cstr[15], cstr[16], cstr[17], cstr[18], cstr[19],
136 cstr[20], cstr[21], cstr[22], cstr[23], cstr[24],
137 cstr[25], cstr[26], cstr[27], cstr[28], cstr[29],
138 cstr[30], cstr[31]);
139}

Callers

nothing calls this directly

Calls 2

StringPrintfFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected