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

Function SlLoadCheckChunk

src/saveload/saveload.cpp:2201–2245  ·  view source on GitHub ↗

* Load a chunk of data for checking savegames. * If the chunkhandler is nullptr, the chunk is skipped. * @param ch The chunkhandler that will be used for the operation */

Source from the content-addressed store, hash-verified

2199 * @param ch The chunkhandler that will be used for the operation
2200 */
2201static void SlLoadCheckChunk(const ChunkHandler &ch)
2202{
2203 uint8_t m = SlReadByte();
2204
2205 _sl.block_mode = m & CH_TYPE_MASK;
2206 _sl.obj_len = 0;
2207 _sl.expect_table_header = (_sl.block_mode == CH_TABLE || _sl.block_mode == CH_SPARSE_TABLE);
2208
2209 /* The header should always be at the start. Read the length; the
2210 * LoadCheck() should as first action process the header. */
2211 if (_sl.expect_table_header) {
2212 if (SlIterateArray() != INT32_MAX) SlErrorCorrupt("Table chunk without header");
2213 }
2214
2215 switch (_sl.block_mode) {
2216 case CH_TABLE:
2217 case CH_ARRAY:
2218 _sl.array_index = 0;
2219 ch.LoadCheck();
2220 break;
2221 case CH_SPARSE_TABLE:
2222 case CH_SPARSE_ARRAY:
2223 ch.LoadCheck();
2224 break;
2225 case CH_RIFF: {
2226 /* Read length */
2227 size_t len = (SlReadByte() << 16) | ((m >> 4) << 24);
2228 len += SlReadUint16();
2229 _sl.obj_len = len;
2230 size_t start_pos = _sl.reader->GetSize();
2231 size_t endoffs = start_pos + len;
2232 ch.LoadCheck(len);
2233
2234 if (_sl.reader->GetSize() != endoffs) {
2235 SlErrorCorruptFmt("Invalid chunk size in RIFF in {} - expected {}, got {}", ch.GetName(), len, _sl.reader->GetSize() - start_pos);
2236 }
2237 break;
2238 }
2239 default:
2240 SlErrorCorrupt("Invalid chunk type");
2241 break;
2242 }
2243
2244 if (_sl.expect_table_header) SlErrorCorrupt("Table chunk without header");
2245}
2246
2247/**
2248 * Save a chunk of data (eg. vehicles, stations, etc.). Each chunk is

Callers 1

SlLoadCheckChunksFunction · 0.85

Calls 8

SlReadByteFunction · 0.85
SlIterateArrayFunction · 0.85
SlErrorCorruptFunction · 0.85
SlReadUint16Function · 0.85
SlErrorCorruptFmtFunction · 0.85
LoadCheckMethod · 0.45
GetSizeMethod · 0.45
GetNameMethod · 0.45

Tested by

no test coverage detected