提交 0bc0ec90 编写于 作者: T Takashi Iwai

ALSA: info: Small refactoring and a sanity check in snd_info_get_line()

Signed-off-by: NTakashi Iwai <tiwai@suse.de>
上级 0d861ac2
...@@ -700,26 +700,21 @@ int snd_info_get_line(struct snd_info_buffer *buffer, char *line, int len) ...@@ -700,26 +700,21 @@ int snd_info_get_line(struct snd_info_buffer *buffer, char *line, int len)
{ {
int c = -1; int c = -1;
if (snd_BUG_ON(!buffer || !buffer->buffer))
return 1;
if (len <= 0 || buffer->stop || buffer->error) if (len <= 0 || buffer->stop || buffer->error)
return 1; return 1;
while (--len > 0) { while (!buffer->stop) {
c = buffer->buffer[buffer->curr++]; c = buffer->buffer[buffer->curr++];
if (c == '\n') { if (buffer->curr >= buffer->size)
if (buffer->curr >= buffer->size)
buffer->stop = 1;
break;
}
*line++ = c;
if (buffer->curr >= buffer->size) {
buffer->stop = 1; buffer->stop = 1;
if (c == '\n')
break; break;
if (len) {
len--;
*line++ = c;
} }
} }
while (c != '\n' && !buffer->stop) {
c = buffer->buffer[buffer->curr++];
if (buffer->curr >= buffer->size)
buffer->stop = 1;
}
*line = '\0'; *line = '\0';
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册