MCPcopy Create free account
hub / github.com/MhmRdd/NoHello / StringAppendV

Function StringAppendV

module/src/main/cpp/external/fdutils/stringprintf.cpp:22–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20
21namespace android::base {
22 void StringAppendV(std::string* dst, const char* format, va_list ap) {
23 // First try with a small fixed size buffer
24 char space[1024] __attribute__((__uninitialized__));
25 // It's possible for methods that use a va_list to invalidate
26 // the data in it upon use. The fix is to make a copy
27 // of the structure before using it and use that copy instead.
28 va_list backup_ap;
29 va_copy(backup_ap, ap);
30 int result = vsnprintf(space, sizeof(space), format, backup_ap);
31 va_end(backup_ap);
32 if (result < static_cast<int>(sizeof(space))) {
33 if (result >= 0) {
34 // Normal case -- everything fit.
35 dst->append(space, result);
36 return;
37 }
38 if (result < 0) {
39 // Just an error.
40 return;
41 }
42 }
43 // Increase the buffer size to the size requested by vsnprintf,
44 // plus one for the closing \0.
45 int length = result + 1;
46 char* buf = new char[length];
47 // Restore the va_list before we use it again
48 va_copy(backup_ap, ap);
49 result = vsnprintf(buf, length, format, backup_ap);
50 va_end(backup_ap);
51 if (result >= 0 && result < length) {
52 // It fit
53 dst->append(buf, result);
54 }
55 delete[] buf;
56 }
57 std::string StringPrintf(const char* fmt, ...) {
58 va_list ap;
59 va_start(ap, fmt);

Callers 2

StringPrintfFunction · 0.85
StringAppendFFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected