This code is adapted from posix_logger.h, which is why it is using vsprintf. Please do not do this in normal code
| 19 | // This code is adapted from posix_logger.h, which is why it is using vsprintf. |
| 20 | // Please do not do this in normal code |
| 21 | void Logv(const char * format, va_list ap) override { |
| 22 | if (!LogAcceptCategory(BCLog::LEVELDB)) { |
| 23 | return; |
| 24 | } |
| 25 | char buffer[500]; |
| 26 | for (int iter = 0; iter < 2; iter++) { |
| 27 | char* base; |
| 28 | int bufsize; |
| 29 | if (iter == 0) { |
| 30 | bufsize = sizeof(buffer); |
| 31 | base = buffer; |
| 32 | } |
| 33 | else { |
| 34 | bufsize = 30000; |
| 35 | base = new char[bufsize]; |
| 36 | } |
| 37 | char* p = base; |
| 38 | char* limit = base + bufsize; |
| 39 | |
| 40 | // Print the message |
| 41 | if (p < limit) { |
| 42 | va_list backup_ap; |
| 43 | va_copy(backup_ap, ap); |
| 44 | // Do not use vsnprintf elsewhere in bitcoin source code, see above. |
| 45 | p += vsnprintf(p, limit - p, format, backup_ap); |
| 46 | va_end(backup_ap); |
| 47 | } |
| 48 | |
| 49 | // Truncate to available space if necessary |
| 50 | if (p >= limit) { |
| 51 | if (iter == 0) { |
| 52 | continue; // Try again with larger buffer |
| 53 | } |
| 54 | else { |
| 55 | p = limit - 1; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | // Add newline if necessary |
| 60 | if (p == base || p[-1] != '\n') { |
| 61 | *p++ = '\n'; |
| 62 | } |
| 63 | |
| 64 | assert(p <= limit); |
| 65 | base[std::min(bufsize - 1, (int)(p - base))] = '\0'; |
| 66 | LogPrintf("leveldb: %s", base); /* Continued */ |
| 67 | if (base != buffer) { |
| 68 | delete[] base; |
| 69 | } |
| 70 | break; |
| 71 | } |
| 72 | } |
| 73 | }; |
| 74 | |
| 75 | static void SetMaxOpenFiles(leveldb::Options *options) { |
nothing calls this directly
no test coverage detected