1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

fix bug of buffer assert, erase can accept any value

This commit is contained in:
winlin 2014-06-10 16:06:18 +08:00
parent d48d739fa7
commit a639eb0596
4 changed files with 29 additions and 12 deletions

View file

@ -58,7 +58,9 @@ char* SrsBuffer::bytes()
void SrsBuffer::erase(int size)
{
srs_assert(size > 0);
if (size <= 0) {
return;
}
if (size >= length()) {
data.clear();

View file

@ -71,7 +71,7 @@ public:
* erase size of bytes from begin.
* @param size to erase size of bytes.
* clear if size greater than or equals to length()
* @remark assert size is positive.
* @remark ignore size is not positive.
*/
virtual void erase(int size);
/**

View file

@ -79,20 +79,34 @@ VOID TEST(BufferTest, EraseBytes)
{
SrsBuffer b;
b.erase(0);
b.erase(-1);
EXPECT_EQ(0, b.length());
char winlin[] = "winlin";
b.append(winlin, strlen(winlin));
b.erase(b.length());
EXPECT_EQ(0, b.length());
b.erase(0);
b.erase(-1);
EXPECT_EQ(0, b.length());
b.append(winlin, strlen(winlin));
b.erase(1);
EXPECT_EQ(5, b.length());
EXPECT_EQ('i', b.bytes()[0]);
EXPECT_EQ('n', b.bytes()[4]);
b.erase(2);
EXPECT_EQ(3, b.length());
EXPECT_EQ('l', b.bytes()[0]);
EXPECT_EQ('n', b.bytes()[2]);
b.erase(0);
b.erase(-1);
EXPECT_EQ(3, b.length());
b.erase(3);
EXPECT_EQ(0, b.length());
}