Skip to content

Commit

Permalink
Prevent arithmetic overflow after 2^32 microseconds, i.e. about one h…
Browse files Browse the repository at this point in the history
…oour and 11 minutes...
  • Loading branch information
mikebrady committed Jul 29, 2018
1 parent 17793bd commit c91a991
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
3 changes: 1 addition & 2 deletions audio_alsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -910,8 +910,7 @@ static void play(void *buf, int samples) {
}
frame_index = 0; // we'll be starting over
measurement_data_is_valid = 0;
}
if ((snd_pcm_state(alsa_handle) == SND_PCM_STATE_PREPARED) ||
} else if ((snd_pcm_state(alsa_handle) == SND_PCM_STATE_PREPARED) ||
(snd_pcm_state(alsa_handle) == SND_PCM_STATE_RUNNING)) {
if (buf == NULL)
debug(1, "NULL buffer passed to pcm_writei -- skipping it");
Expand Down
5 changes: 1 addition & 4 deletions player.c
Original file line number Diff line number Diff line change
Expand Up @@ -2301,10 +2301,7 @@ void *player_thread_func(void *arg) {
uint64_t elapsed_play_time, frames_played;
conn->frame_rate_status = config.output->rate_info(&elapsed_play_time,&frames_played);
if (conn->frame_rate_status==0) {
uint64_t elapsed_play_time_microseconds_fp, elapsed_play_time_microseconds;
elapsed_play_time_microseconds_fp = elapsed_play_time * 1000000;
elapsed_play_time_microseconds = elapsed_play_time_microseconds_fp >> 32;
conn->frame_rate = frames_played*1000000.0/elapsed_play_time_microseconds;
conn->frame_rate = 1.0*(frames_played*(uint64_t)0x100000000)/elapsed_play_time;
}
}
inform(
Expand Down

0 comments on commit c91a991

Please sign in to comment.