MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / WriteLoop

Method WriteLoop

src/saveload/saveload.cpp:2631–2657  ·  view source on GitHub ↗

* Helper loop for writing the data. * @param p The bytes to write. * @param len Amount of bytes to write. * @param mode Mode for deflate. */

Source from the content-addressed store, hash-verified

2629 * @param mode Mode for deflate.
2630 */
2631 void WriteLoop(uint8_t *p, size_t len, int mode)
2632 {
2633 uint n;
2634 this->z.next_in = p;
2635 this->z.avail_in = (uInt)len;
2636 do {
2637 this->z.next_out = this->fwrite_buf;
2638 this->z.avail_out = sizeof(this->fwrite_buf);
2639
2640 /**
2641 * For the poor next soul who sees many valgrind warnings of the
2642 * "Conditional jump or move depends on uninitialised value(s)" kind:
2643 * According to the author of zlib it is not a bug and it won't be fixed.
2644 * http://groups.google.com/group/comp.compression/browse_thread/thread/b154b8def8c2a3ef/cdf9b8729ce17ee2
2645 * [Mark Adler, Feb 24 2004, 'zlib-1.2.1 valgrind warnings' in the newsgroup comp.compression]
2646 */
2647 int r = deflate(&this->z, mode);
2648
2649 /* bytes were emitted? */
2650 if ((n = sizeof(this->fwrite_buf) - this->z.avail_out) != 0) {
2651 this->chain->Write(this->fwrite_buf, n);
2652 }
2653 if (r == Z_STREAM_END) break;
2654
2655 if (r != Z_OK) SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR, "zlib returned error code");
2656 } while (this->z.avail_in || !this->z.avail_out);
2657 }
2658
2659 void Write(uint8_t *buf, size_t size) override
2660 {

Callers 2

WriteMethod · 0.95
FinishMethod · 0.95

Calls 2

SlErrorFunction · 0.85
WriteMethod · 0.45

Tested by

no test coverage detected