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

Function svsprintf

lite/src/misc.cpp:33–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31
32namespace {
33std::string svsprintf(const char* fmt, va_list ap_orig) {
34 int size = 100; /* Guess we need no more than 100 bytes */
35 char* p;
36
37 if ((p = (char*)malloc(size)) == nullptr)
38 return "svsprintf: malloc failed";
39
40 for (;;) {
41 va_list ap;
42 va_copy(ap, ap_orig);
43 int n = vsnprintf(p, size, fmt, ap);
44 va_end(ap);
45
46 if (n < 0)
47 return "svsprintf: vsnprintf failed";
48
49 if (n < size) {
50 std::string rst(p);
51 free(p);
52 return rst;
53 }
54
55 size = n + 1;
56
57 char* np = (char*)realloc(p, size);
58 if (!np) {
59 free(p);
60 return "svsprintf: realloc failed";
61 } else
62 p = np;
63 }
64}
65} // namespace
66
67void lite::set_log_level(LiteLogLevel l) {

Callers 6

ssprintfMethod · 0.70
print_logMethod · 0.70
py_log_handlerMethod · 0.50
__assert_fail__Method · 0.50
ssprintfMethod · 0.50
assert_failed_logFunction · 0.50

Calls 1

freeFunction · 0.85

Tested by

no test coverage detected