MCPcopy Create free account
hub / github.com/MegEngine/MegCC / svsprintf

Function svsprintf

compiler/lib/KernelGen/Utils/Utils.cpp:9–40  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7
8namespace {
9std::string svsprintf(const char* fmt, va_list ap_orig) {
10 int size = 100; /* Guess we need no more than 100 bytes */
11 char* p;
12
13 if ((p = (char*)malloc(size)) == nullptr)
14 return "svsprintf: malloc failed";
15
16 for (;;) {
17 va_list ap;
18 va_copy(ap, ap_orig);
19 int n = vsnprintf(p, size, fmt, ap);
20 va_end(ap);
21
22 if (n < 0)
23 return "svsprintf: vsnprintf failed";
24
25 if (n < size) {
26 std::string rst(p);
27 free(p);
28 return rst;
29 }
30
31 size = n + 1;
32
33 char* np = (char*)realloc(p, size);
34 if (!np) {
35 free(p);
36 return "svsprintf: realloc failed";
37 } else
38 p = np;
39 }
40}
41} // anonymous namespace
42
43std::string Utils::ssprintf(const char* fmt, ...) {

Callers 1

ssprintfMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected