6222: Fix undefined demo timeline markers when recording is not stopped r=def- a=Robyt3

When the demo recording is not stopped properly (e.g. client crashes during recording), the timeline markers and the demo length are not updated. The length is always set to zero when starting the recording, but uninitialized memory is written for the timeline markers, which causes these demos to likely show the maximum number of markers with some markers possibly being outside the ticks that the demo contains. This is fixed by initially setting all timeline marker data to zero when starting the recording.

## Checklist

- [ ] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Robert Müller <robytemueller@gmail.com>
This commit is contained in:
bors[bot] 2023-01-03 15:37:13 +00:00 committed by GitHub
commit 1f5c2696d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -65,8 +65,6 @@ int CDemoRecorder::Start(class IStorage *pStorage, class IConsole *pConsole, con
return -1;
}
CDemoHeader Header;
CTimelineMarkers TimelineMarkers;
if(m_File)
{
io_close(DemoFile);
@ -130,6 +128,7 @@ int CDemoRecorder::Start(class IStorage *pStorage, class IConsole *pConsole, con
MapSize = io_length(MapFile);
// write header
CDemoHeader Header;
mem_zero(&Header, sizeof(Header));
mem_copy(Header.m_aMarker, gs_aHeaderMarker, sizeof(Header.m_aMarker));
Header.m_Version = gs_CurVersion;
@ -141,6 +140,9 @@ int CDemoRecorder::Start(class IStorage *pStorage, class IConsole *pConsole, con
// Header.m_Length - add this on stop
str_timestamp(Header.m_aTimestamp, sizeof(Header.m_aTimestamp));
io_write(DemoFile, &Header, sizeof(Header));
CTimelineMarkers TimelineMarkers;
mem_zero(&TimelineMarkers, sizeof(TimelineMarkers));
io_write(DemoFile, &TimelineMarkers, sizeof(TimelineMarkers)); // fill this on stop
//Write Sha256