mirror of
https://github.com/upx/upx
synced 2025-09-28 19:06:07 +08:00
MemBuffer.subref(errfmt, skip, take) checks that a subinterval is inside
modified: mem.cpp modified: mem.h
This commit is contained in:
parent
58771ecca6
commit
f014406b65
12
src/mem.cpp
12
src/mem.cpp
|
@ -73,6 +73,18 @@ MemBuffer::~MemBuffer()
|
|||
this->dealloc();
|
||||
}
|
||||
|
||||
// similar to BoundedPtr, except checks only at creation
|
||||
unsigned char *MemBuffer::subref(char const *errfmt, unsigned skip, unsigned take)
|
||||
{
|
||||
if ((take + skip) < take // wrap-around
|
||||
|| (take + skip) > b_size // overrun
|
||||
) {
|
||||
char buf[100]; snprintf(buf, sizeof(buf), errfmt, skip, take);
|
||||
throwCantPack(buf);
|
||||
}
|
||||
return &b[skip];
|
||||
}
|
||||
|
||||
void MemBuffer::dealloc()
|
||||
{
|
||||
if (b != NULL)
|
||||
|
|
|
@ -64,6 +64,11 @@ public:
|
|||
void clear(unsigned off, unsigned len) { fill(off, len, 0); }
|
||||
void clear() { fill(0, b_size, 0); }
|
||||
|
||||
// If the entire range [skip, take+skip) is inside the buffer,
|
||||
// then return &b[skip]; else throwCantPack(sprintf(errfmt, skip, take)).
|
||||
// This is similar to BoundedPtr, except only checks once.
|
||||
unsigned char *subref(char const *errfmt, unsigned skip, unsigned take);
|
||||
|
||||
private:
|
||||
unsigned char *b;
|
||||
unsigned b_size;
|
||||
|
|
Loading…
Reference in New Issue
Block a user