Move initialization of state up in stream_encoder_new

In stream_encoder_new, set_defaults_ was called before setting
encoder->protected_->state to uninitialized. However, this state
was being accessed by set_compression_level in set_defaults_. As
this is undefined behaviour, move the initialization of
encoder->protected_->state up to before calling set_default_
This commit is contained in:
Martijn van Beurden 2022-02-28 15:53:57 +01:00
parent 4a8ec07e95
commit 7b73bbcca4
1 changed files with 2 additions and 2 deletions

View File

@ -536,6 +536,8 @@ FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void)
encoder->private_->file = 0;
encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
set_defaults_(encoder);
encoder->private_->is_being_deleted = false;
@ -568,8 +570,6 @@ FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void)
for(i = 0; i < 2; i++)
FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_extra[i]);
encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
return encoder;
}