Diffstat (limited to 'noncore/apps/opie-reader/CBuffer.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/CBuffer.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/noncore/apps/opie-reader/CBuffer.cpp b/noncore/apps/opie-reader/CBuffer.cpp index 526b25f..0780a88 100644 --- a/noncore/apps/opie-reader/CBuffer.cpp +++ b/noncore/apps/opie-reader/CBuffer.cpp | |||
@@ -1,46 +1,46 @@ | |||
1 | #include "CBuffer.h" | 1 | #include "CBuffer.h" |
2 | 2 | ||
3 | CBufferBase& CBufferBase::assign(const void* sztmp, size_t ms) | 3 | CBufferBase& CBufferBase::assign(const void* sztmp, size_t ms) |
4 | { | 4 | { |
5 | if (ms*membersize > len) | 5 | if (ms*membersize > len) |
6 | { | 6 | { |
7 | delete [] buffer; | 7 | delete [] buffer; |
8 | buffer = new unsigned char[len = ms*membersize]; | 8 | buffer = new unsigned char[len = ms*membersize]; |
9 | } | 9 | } |
10 | memcpy(buffer, sztmp, ms*membersize); | 10 | memcpy(buffer, sztmp, ms*membersize); |
11 | return *this; | 11 | return *this; |
12 | } | 12 | } |
13 | 13 | ||
14 | CBufferBase::CBufferBase(size_t ms, size_t n = 16) : len(n), membersize(ms) | 14 | CBufferBase::CBufferBase(size_t ms, size_t n) : len(n), membersize(ms) |
15 | { | 15 | { |
16 | buffer = new unsigned char[len*membersize]; | 16 | buffer = new unsigned char[len*membersize]; |
17 | memset(buffer, 0, len*membersize); | 17 | memset(buffer, 0, len*membersize); |
18 | } | 18 | } |
19 | 19 | ||
20 | void* CBufferBase::operator[](int i) | 20 | void* CBufferBase::operator[](int i) |
21 | { | 21 | { |
22 | if ((i+1)*membersize > len) | 22 | if ((i+1)*membersize > len) |
23 | { | 23 | { |
24 | unsigned char* oldbuffer = buffer; | 24 | unsigned char* oldbuffer = buffer; |
25 | buffer = new unsigned char[(i+1)*membersize]; | 25 | buffer = new unsigned char[(i+1)*membersize]; |
26 | memcpy(buffer, oldbuffer, len); | 26 | memcpy(buffer, oldbuffer, len); |
27 | memset(buffer+len, 0, (i+1)*membersize-len); | 27 | memset(buffer+len, 0, (i+1)*membersize-len); |
28 | len = (i+1)*membersize; | 28 | len = (i+1)*membersize; |
29 | delete [] oldbuffer; | 29 | delete [] oldbuffer; |
30 | } | 30 | } |
31 | return buffer+i*membersize; | 31 | return buffer+i*membersize; |
32 | } | 32 | } |
33 | 33 | ||
34 | size_t CBufferBase::bstrlen(unsigned char* _buffer = NULL) | 34 | size_t CBufferBase::bstrlen(unsigned char* _buffer) |
35 | { | 35 | { |
36 | if (_buffer == NULL) _buffer = buffer; | 36 | if (_buffer == NULL) _buffer = buffer; |
37 | unsigned char* zero = new unsigned char[membersize]; | 37 | unsigned char* zero = new unsigned char[membersize]; |
38 | memset(zero,0,membersize); | 38 | memset(zero,0,membersize); |
39 | unsigned char* element = _buffer; | 39 | unsigned char* element = _buffer; |
40 | while (memcmp(element, zero, membersize) != 0) | 40 | while (memcmp(element, zero, membersize) != 0) |
41 | { | 41 | { |
42 | element += membersize; | 42 | element += membersize; |
43 | } | 43 | } |
44 | delete [] zero; | 44 | delete [] zero; |
45 | return (element - _buffer)/membersize; | 45 | return (element - _buffer)/membersize; |
46 | } | 46 | } |