Today, we encountered a bug. When audioflinger returns a negative number from audiostreaminalsa: Read (), but when it should return a negative number, returns a super large positive number. After a long query, the system finally realized that the signed positive number and the unsigned positive number will cause an error during forced conversion during an expression operation. In C language, when the expression contains a signed or unsigned type, all operands are automatically converted to the unsigned type.
Ssize_t audiostreaminalsa: Read (void * buffer, ssize_t bytes)
{Return static_cast <ssize_t> (snd_pcm_frames_to_bytes (mhandle-> handle, n);} When n =-32, static_cast <ssize_t> (handle (mhandle-> handle, n) is a very large positive number.
Ssize_t snd_pcm_frames_to_bytes (snd_pcm_t * PCM, snd_pcm_sframes_t frames)
{
Assert (PCM );
If (check_sanity (! PCM-> setup )){
Sndmsg ("PCM not set up ");
Return-EIO;
}
Return frames * PCM-> frame_bits/8;
}
This is because PCM-> frame_bits is an unsigned integer. First, frames is converted to an unsigned integer. When frames =-32, it is a very large integer, frames * PCM-> frame_bits/8 is a very large integer. It is also a big integer when a signed integer is returned when the switch is performed.
ALSA-lib/src/pcmpcm_local.h
Struct _ snd_pcm
{
Unsigned int frame_bits;
}