[alsa-devel] [PATCH] rawmidi: virtual: fix reading into a small buffer

Takashi Sakamoto o-takashi at sakamocchi.jp
Sun Mar 19 07:23:11 CET 2017


Hi,

On Mar 19 2017 07:10, Clemens Ladisch wrote:
> In the special case for handling partial messages, the pointer
> calculations were wrong, which would result in data corruption.
>
> Signed-off-by: Clemens Ladisch <clemens at ladisch.de>

Reviewd-by: Takashi Sakamoto <o-takashi at sakamocchi.jp>

> --- alsa-lib/src/rawmidi/rawmidi_virt.c
> +++ alsa-lib/src/rawmidi/rawmidi_virt.c
> @@ -263,8 +263,8 @@ static ssize_t snd_rawmidi_virtual_read(snd_rawmidi_t *rmidi, void *buffer, size
>  		}
>  		size1 = virt->in_buf_size - virt->in_buf_ofs;
>  		if ((size_t)size1 > size) {
> -			virt->in_buf_ofs += size1 - size;
> -			memcpy(buffer, virt->in_buf_ptr, size);
> +			memcpy(buffer, virt->in_buf_ptr + virt->in_buf_ofs, size);
> +			virt->in_buf_ofs += size;
>  			result += size;
>  			break;
>  		}


Regards

Takashi Sakamoto


More information about the Alsa-devel mailing list