mirror of
https://github.com/autc04/Retro68.git
synced 2024-12-06 15:52:08 +00:00
ConvertDiskImage: fix undefined behavior
This commit is contained in:
parent
3d84d382ad
commit
37cb3b81e8
@ -1,2 +1,4 @@
|
||||
add_executable(ConvertDiskImage ConvertDiskImage.cc)
|
||||
target_link_libraries(ConvertDiskImage ResourceFiles)
|
||||
|
||||
install(TARGETS ConvertDiskImage RUNTIME DESTINATION bin)
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
|
||||
void decompreassADC(std::vector<uint8_t>& outbuf, const std::vector<uint8_t>& inbuf)
|
||||
void decompressADC(std::vector<uint8_t>& outbuf, const std::vector<uint8_t>& inbuf)
|
||||
{
|
||||
outbuf.reserve(0x40000);
|
||||
auto p = inbuf.begin();
|
||||
@ -19,6 +19,7 @@ void decompreassADC(std::vector<uint8_t>& outbuf, const std::vector<uint8_t>& in
|
||||
int n = (cmd & 0x7f) + 1;
|
||||
outbuf.insert(outbuf.end(), p, p + n);
|
||||
p += n;
|
||||
assert(p <= inbuf.end());
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -37,8 +38,14 @@ void decompreassADC(std::vector<uint8_t>& outbuf, const std::vector<uint8_t>& in
|
||||
}
|
||||
++off;
|
||||
|
||||
outbuf.reserve(outbuf.size() + n);
|
||||
outbuf.insert(outbuf.end(), outbuf.end() - off, outbuf.end() - off + n);
|
||||
assert(n > 0);
|
||||
assert(off > 0);
|
||||
assert(outbuf.size() - off >= 0);
|
||||
outbuf.resize(outbuf.size() + n);
|
||||
auto dst = outbuf.end() - n;
|
||||
auto src = dst - off;
|
||||
while(n--)
|
||||
*dst++ = *src++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -119,7 +126,7 @@ int main(int argc, char* argv[])
|
||||
break;
|
||||
|
||||
case 0x83:
|
||||
decompreassADC(outbuf, inbuf);
|
||||
decompressADC(outbuf, inbuf);
|
||||
break;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user