mirror of https://github.com/Icinga/icinga2.git
Merge pull request #6393 from Icinga/bugfix/elasticsearchwriter-not-writing-6354
Stream#ReadLine(): fix false positive buffer underflow indicator
This commit is contained in:
commit
cc294e14d2
|
@ -129,31 +129,19 @@ StreamReadStatus Stream::ReadLine(String *line, StreamReadContext& context, bool
|
|||
}
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
size_t first_newline;
|
||||
|
||||
for (size_t i = 0; i < context.Size; i++) {
|
||||
if (context.Buffer[i] == '\n') {
|
||||
count++;
|
||||
*line = String(context.Buffer, context.Buffer + i);
|
||||
boost::algorithm::trim_right(*line);
|
||||
|
||||
if (count == 1)
|
||||
first_newline = i;
|
||||
else if (count > 1)
|
||||
break;
|
||||
context.DropData(i + 1u);
|
||||
|
||||
context.MustRead = !context.Size;
|
||||
return StatusNewItem;
|
||||
}
|
||||
}
|
||||
|
||||
context.MustRead = (count <= 1);
|
||||
|
||||
if (count > 0) {
|
||||
*line = String(context.Buffer, &(context.Buffer[first_newline]));
|
||||
boost::algorithm::trim_right(*line);
|
||||
|
||||
context.DropData(first_newline + 1);
|
||||
|
||||
return StatusNewItem;
|
||||
}
|
||||
|
||||
context.MustRead = true;
|
||||
return StatusNeedData;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue