Skip to content

Commit e1f62eb

Browse files
committed
Fix some more undefined behaviour
As #784 notified me of undefined behaviour going undetected by the fuzzers, I ran the test suite with the full undefined behaviour sanitizer enabled. There is one bit of undefined behaviour that I cannot fix, FLAC__metadata_get_picture allows a picture type of -1 to mean all, but this isn't part of the enum.
1 parent a628cca commit e1f62eb

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

src/libFLAC/include/private/ogg_encoder_aspect.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void FLAC__ogg_encoder_aspect_set_defaults(FLAC__OggEncoderAspect *aspect);
5858
FLAC__bool FLAC__ogg_encoder_aspect_init(FLAC__OggEncoderAspect *aspect);
5959
void FLAC__ogg_encoder_aspect_finish(FLAC__OggEncoderAspect *aspect);
6060

61-
typedef FLAC__StreamEncoderWriteStatus (*FLAC__OggEncoderAspectWriteCallbackProxy)(const void *encoder, const FLAC__byte buffer[], size_t bytes, uint32_t samples, uint32_t current_frame, void *client_data);
61+
typedef FLAC__StreamEncoderWriteStatus (*FLAC__OggEncoderAspectWriteCallbackProxy)(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, uint32_t samples, uint32_t current_frame, void *client_data);
6262

6363
FLAC__StreamEncoderWriteStatus FLAC__ogg_encoder_aspect_write_callback_wrapper(FLAC__OggEncoderAspect *aspect, const FLAC__byte buffer[], size_t bytes, uint32_t samples, uint32_t current_frame, FLAC__bool is_last_block, FLAC__OggEncoderAspectWriteCallbackProxy write_callback, void *encoder, void *client_data);
6464
#endif

src/share/grabbag/cuesheet.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ static FLAC__bool local__cuesheet_parse_(FILE *file, const char **error_message,
332332
}
333333
else if(0 == FLAC__STRCASECMP(field, "INDEX")) {
334334
FLAC__int64 xx;
335-
FLAC__StreamMetadata_CueSheet_Track *track = &cs->tracks[cs->num_tracks-1];
335+
FLAC__StreamMetadata_CueSheet_Track *track;
336336
if(in_track_num < 0) {
337337
*error_message = "found INDEX before any TRACK";
338338
return false;
@@ -347,6 +347,7 @@ static FLAC__bool local__cuesheet_parse_(FILE *file, const char **error_message,
347347
return false;
348348
}
349349
FLAC__ASSERT(cs->num_tracks > 0);
350+
track = &cs->tracks[cs->num_tracks-1];
350351
if(track->num_indices == 0) {
351352
/* it's the first index point of the track */
352353
if(in_index_num > 1) {

src/test_streams/main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,11 @@ static FLAC__bool write_little_endian_uint64(FILE *f, FLAC__uint64 x)
125125
static FLAC__bool write_big_endian(FILE *f, FLAC__int32 x, size_t bytes)
126126
{
127127
if(bytes < 4)
128-
x <<= 8*(4-bytes);
128+
x = (uint32_t)x << 8*(4-bytes);
129129
while(bytes) {
130130
if(fputc(x>>24, f) == EOF)
131131
return false;
132-
x <<= 8;
132+
x = (uint32_t)x << 8;
133133
bytes--;
134134
}
135135
return true;
@@ -1057,7 +1057,7 @@ static FLAC__bool write_simple_wavex_header (FILE * f, unsigned samplerate, unsi
10571057
static FLAC__bool generate_noisy_sine(void)
10581058
{
10591059
FILE *f;
1060-
int64_t randstate = 0x1243456;
1060+
uint64_t randstate = 0x1243456;
10611061
double sample, last_val = 0.0;
10621062
int k;
10631063
int seconds = 300;

0 commit comments

Comments
 (0)