-----------------------------------------------------------------------------
| 79 | |
| 80 | //----------------------------------------------------------------------------- |
| 81 | tresult PLUGIN_API MemoryStream::read (void* data, int32 numBytes, int32* numBytesRead) |
| 82 | { |
| 83 | if (memory == nullptr) |
| 84 | { |
| 85 | if (allocationError) |
| 86 | return kOutOfMemory; |
| 87 | numBytes = 0; |
| 88 | } |
| 89 | else |
| 90 | { |
| 91 | // Does read exceed size ? |
| 92 | if (cursor + numBytes > size) |
| 93 | { |
| 94 | int32 maxBytes = int32 (size - cursor); |
| 95 | |
| 96 | // Has length become zero or negative ? |
| 97 | if (maxBytes <= 0) |
| 98 | { |
| 99 | cursor = size; |
| 100 | numBytes = 0; |
| 101 | } |
| 102 | else |
| 103 | numBytes = maxBytes; |
| 104 | } |
| 105 | |
| 106 | if (numBytes) |
| 107 | { |
| 108 | memcpy (data, &memory[cursor], static_cast<size_t> (numBytes)); |
| 109 | cursor += numBytes; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | if (numBytesRead) |
| 114 | *numBytesRead = numBytes; |
| 115 | |
| 116 | return kResultTrue; |
| 117 | } |
| 118 | |
| 119 | //----------------------------------------------------------------------------- |
| 120 | tresult PLUGIN_API MemoryStream::write (void* buffer, int32 numBytes, int32* numBytesWritten) |
no outgoing calls
no test coverage detected