MCPcopy Create free account
hub / github.com/BernardoGiordano/Checkpoint / writeToString

Function writeToString

common/script/httpcall.cpp:54–64  ·  view source on GitHub ↗

Allocation-safe on purpose. The prebuilt curl portlib carries no unwind info, so a std::bad_alloc out of append() — the realistic case on an O3DS pulling a multi-MB body — would unwind into curl's frames and std::terminate the app. Returning short instead makes curl fail the transfer with CURLE_WRITE_ERROR, which perform() reports as OutOfMemory.

Source from the content-addressed store, hash-verified

52 // std::terminate the app. Returning short instead makes curl fail the
53 // transfer with CURLE_WRITE_ERROR, which perform() reports as OutOfMemory.
54 size_t writeToString(char* ptr, size_t size, size_t nmemb, void* userdata)
55 {
56 const size_t n = size * nmemb;
57 try {
58 ((std::string*)userdata)->append(ptr, n);
59 }
60 catch (...) {
61 return 0;
62 }
63 return n;
64 }
65
66 // Nonzero aborts the transfer: a script being aborted mustn't sit in a
67 // transfer it can't reach the per-statement abort hook from.

Callers

nothing calls this directly

Calls 1

appendMethod · 0.80

Tested by

no test coverage detected