History

Fix buffer size checks when appending using SNPRINTF/WelsSnprintf

Checking iBufferLeft > iBufferUsed does not make sense, since this would stop writing into the buffer alredy after the buffer is half full, when there is less space left than has been used. The right check is iBufferLeft > 0.

Martin Storsjö committed 12 years ago

Commit a344d101 parent 98bad4f2 files · +8 −8Browse files

Showing the changes to codec/decoder/plus/src/welsDecoderExt.cpp (1 of 2 files). Show all

Unified · Split

codec/decoder/plus/src/welsDecoderExt.cpp+4−4
@@ -110,23 +110,23 @@ CWelsDecoder::CWelsDecoder (void_t) · 109 unmodified lines
110110 iBufUsedSize += WelsSnprintf (chFileNameSize, iBufLeftSize, "size_0x%p_", (void_t*)this);
111111
112112 iBufLeft -= iBufUsed;
113− if (iBufLeft > iBufUsed) {
113+ if (iBufLeft > 0) {
114114 iBufUsed += WelsStrftime (&chFileName[iBufUsed], iBufLeft, "%y%m%d%H%M%S", &sCurTime);
115115 iBufLeft -= iBufUsed;
116116 }
117117
118118 iBufLeftSize -= iBufUsedSize;
119− if (iBufLeftSize > iBufUsedSize) {
119+ if (iBufLeftSize > 0) {
120120 iBufUsedSize += WelsStrftime (&chFileNameSize[iBufUsedSize], iBufLeftSize, "%y%m%d%H%M%S", &sCurTime);
121121 iBufLeftSize -= iBufUsedSize;
122122 }
123123
124− if (iBufLeft > iBufUsed) {
124+ if (iBufLeft > 0) {
125125 iBufUsed += WelsSnprintf (&chFileName[iBufUsed], iBufLeft, ".%03.3u.264", WelsGetMillsecond (&sCurTime));
126126 iBufLeft -= iBufUsed;
127127 }
128128
129− if (iBufLeftSize > iBufUsedSize) {
129+ if (iBufLeftSize > 0) {
130130 iBufUsedSize += WelsSnprintf (&chFileNameSize[iBufUsedSize], iBufLeftSize, ".%03.3u.len",
131131 WelsGetMillsecond (&sCurTime));
132132 iBufLeftSize -= iBufUsedSize;

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