Skip to content

Commit

Permalink
Don't break if sizeof(int) > 4
Browse files Browse the repository at this point in the history
  • Loading branch information
myrsloik committed Nov 6, 2024
1 parent 9fa8446 commit 7ffd5b4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/audiosource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,7 @@ void BestAudioSource::GetPlanarAudio(uint8_t *const *const Data, int64_t Start,
////////////////////////////////////////
// Index read/write

typedef std::array<uint8_t, 40> AudioCompArray;
typedef std::array<uint8_t, sizeof(int64_t) + sizeof(int64_t) + sizeof(int) + sizeof(int) + sizeof(int) + sizeof(int) + sizeof(uint64_t)> AudioCompArray;

static AudioCompArray GetAudioCompArray(int64_t PTS, int64_t Length, int Format, int BitsPerSample, int SampleRate, int Channels, uint64_t ChannelLayout) {
AudioCompArray Result;
Expand All @@ -1127,6 +1127,8 @@ static AudioCompArray GetAudioCompArray(int64_t PTS, int64_t Length, int Format,
memcpy(Result.data() + sizeof(PTS) + sizeof(Length) + sizeof(Format) + sizeof(BitsPerSample) + sizeof(SampleRate), &Channels, sizeof(Channels));
memcpy(Result.data() + sizeof(PTS) + sizeof(Length) + sizeof(Format) + sizeof(BitsPerSample) + sizeof(SampleRate) + sizeof(Channels), &ChannelLayout, sizeof(ChannelLayout));

static_assert(sizeof(PTS) + sizeof(Length) + sizeof(Format) + sizeof(BitsPerSample) + sizeof(SampleRate) + sizeof(Channels) + sizeof(ChannelLayout) == sizeof(AudioCompArray));

return Result;
}

Expand Down
8 changes: 5 additions & 3 deletions src/videosource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1517,7 +1517,7 @@ void BestVideoSource::SelectFormatSet(int Index) {
////////////////////////////////////////
// Index read/write

typedef std::array<uint8_t, 25> VideoCompArray;
typedef std::array<uint8_t, sizeof(int64_t) + sizeof(int) + sizeof(int) + sizeof(int) + sizeof(int) + sizeof(uint8_t)> VideoCompArray;

static VideoCompArray GetVideoCompArray(int64_t PTS, int RepeatPict, int Format, int Width, int Height, bool KeyFrame, bool TFF) {
VideoCompArray Result;
Expand All @@ -1527,8 +1527,10 @@ static VideoCompArray GetVideoCompArray(int64_t PTS, int RepeatPict, int Format,
memcpy(Result.data() + sizeof(PTS) + sizeof(RepeatPict) + sizeof(Format), &Width, sizeof(Width));
memcpy(Result.data() + sizeof(PTS) + sizeof(RepeatPict) + sizeof(Format) + sizeof(Width), &Height, sizeof(Height));
uint8_t Flags = static_cast<uint8_t>(KeyFrame) | (static_cast<uint8_t>(TFF) << 1);
memcpy(Result.data() + sizeof(PTS) + sizeof(RepeatPict) + sizeof(Format) + sizeof(Width) + sizeof(Width), &Flags, sizeof(Flags));
static_assert(sizeof(PTS) + sizeof(RepeatPict) + sizeof(Format) + sizeof(Width) + sizeof(Width) + sizeof(Flags) == sizeof(VideoCompArray));
memcpy(Result.data() + sizeof(PTS) + sizeof(RepeatPict) + sizeof(Format) + sizeof(Width) + sizeof(Height), &Flags, sizeof(Flags));

static_assert(sizeof(PTS) + sizeof(RepeatPict) + sizeof(Format) + sizeof(Width) + sizeof(Height) + sizeof(Flags) == sizeof(VideoCompArray));

return Result;
}

Expand Down

0 comments on commit 7ffd5b4

Please sign in to comment.