History

fix low memory crash issue

wayne committed 7 years ago

Commit d58148c1 parent 9a815399 files · +38 −24Browse files

Showing the changes to test/api/BaseDecoderTest.cpp (1 of 9 files). Show all

Unified · Split

test/api/BaseDecoderTest.cpp+19−12
@@ -5,7 +5,7 @@ · 4 unmodified lines
55 #include "utils/BufferedData.h"
66 #include "BaseDecoderTest.h"
77
8−static void ReadFrame (std::ifstream* file, BufferedData* buf) {
8+static bool ReadFrame (std::ifstream* file, BufferedData* buf) {
99 // start code of a frame is {0, 0, 0, 1}
1010 int zeroCount = 0;
1111 char b;
@@ -14,10 +14,11 @@ static void ReadFrame (std::ifstream* file, BufferedData* buf) { · 2 unmodified lines
1414 for (;;) {
1515 file->read (&b, 1);
1616 if (file->gcount() != 1) { // end of file
17− return;
17+ return true;
1818 }
1919 if (!buf->PushBack (b)) {
20− FAIL() << "unable to allocate memory";
20+ std::cout << "unable to allocate memory" << std::endl;
21+ return false;
2122 }
2223
2324 if (buf->Length() <= 4) {
@@ -29,10 +30,12 @@ static void ReadFrame (std::ifstream* file, BufferedData* buf) { · 5 unmodified lines
2930 } else {
3031 if (b == 1) {
3132 if (file->seekg (-4, file->cur).good()) {
32− buf->SetLength (buf->Length() - 4);
33− return;
33+ if (-1 == buf->SetLength(buf->Length() - 4))
34+ return false;
35+ return true;
3436 } else {
35− FAIL() << "unable to seek file";
37+ std::cout << "unable to seek file" << std::endl;
38+ return false;
3639 }
3740 } else if (b == 0) {
3841 zeroCount = 3;
@@ -145,22 +148,24 @@ void BaseDecoderTest::FlushFrame (Callback* cbk) { · 106 unmodified lines
145148 cbk->onDecodeFrame (frame);
146149 }
147150 }
148−void BaseDecoderTest::DecodeFile (const char* fileName, Callback* cbk) {
151+bool BaseDecoderTest::DecodeFile (const char* fileName, Callback* cbk) {
149152 std::ifstream file (fileName, std::ios::in | std::ios::binary);
150− ASSERT_TRUE (file.is_open());
153+ if (!file.is_open())
154+ return false;
151155
152156 BufferedData buf;
153157 while (true) {
154− ReadFrame (&file, &buf);
158+ if (false == ReadFrame(&file, &buf))
159+ return false;
155160 if (::testing::Test::HasFatalFailure()) {
156− return;
161+ return false;
157162 }
158163 if (buf.Length() == 0) {
159164 break;
160165 }
161166 DecodeFrame (buf.data(), buf.Length(), cbk);
162167 if (::testing::Test::HasFatalFailure()) {
163− return;
168+ return false;
164169 }
165170 }
166171
@@ -175,6 +180,7 @@ void BaseDecoderTest::DecodeFile (const char* fileName, Callback* cbk) { · 8 unmodified lines
175180 for (int32_t i = 0; i < num_of_frames_in_buffer; ++i) {
176181 FlushFrame (cbk);
177182 }
183+ return true;
178184 }
179185
180186 bool BaseDecoderTest::Open (const char* fileName) {
@@ -191,7 +197,8 @@ bool BaseDecoderTest::Open (const char* fileName) { · 10 unmodified lines
191197 bool BaseDecoderTest::DecodeNextFrame (Callback* cbk) {
192198 switch (decodeStatus_) {
193199 case Decoding:
194− ReadFrame (&file_, &buf_);
200+ if (false == ReadFrame(&file_, &buf_))
201+ return false;
195202 if (::testing::Test::HasFatalFailure()) {
196203 return false;
197204 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t