forked from Lephenixnoir/fxos
fix mismatch of new[] and delete in Buffer
This commit is contained in:
parent
9e37c2685c
commit
4ab1df810b
|
@ -46,7 +46,7 @@ struct Buffer
|
|||
/* Buffer size */
|
||||
size_t size;
|
||||
/* Data */
|
||||
std::shared_ptr<char> data;
|
||||
std::unique_ptr<char[]> data;
|
||||
/* File path, when constructed from file */
|
||||
std::string path;
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ struct Binding: public AbstractMemory
|
|||
/* Constructor from data buffer. An error is raised if the buffer is
|
||||
not at least of the size of the region. In this case, a new buffer
|
||||
can be constructed with the required size. */
|
||||
Binding(MemoryRegion region, Buffer buffer);
|
||||
Binding(MemoryRegion region, Buffer const &buffer);
|
||||
|
||||
/* Targeted region, might overlap with other bindings */
|
||||
MemoryRegion region;
|
||||
|
|
|
@ -26,11 +26,8 @@ Buffer::Buffer():
|
|||
Buffer::Buffer(size_t bufsize, int fill)
|
||||
{
|
||||
this->size = bufsize;
|
||||
// TODO: Buffer(size, fill) -> use std::make_unique<>
|
||||
char *buffer = new char[size];
|
||||
memset(buffer, fill, size);
|
||||
|
||||
this->data = std::shared_ptr<char>(buffer);
|
||||
this->data = std::make_unique<char[]>(bufsize);
|
||||
memset(this->data.get(), fill, bufsize);
|
||||
this->path = "(anonymous)";
|
||||
}
|
||||
|
||||
|
@ -53,9 +50,8 @@ void Buffer::loadFromFile(std::string const &filepath, ssize_t bufsize,
|
|||
size_t size_to_read = std::min(size, (size_t)statbuf.st_size);
|
||||
|
||||
/* Read buffer and fill whatever is left */
|
||||
// TODO: use make_unique<>
|
||||
this->data = std::shared_ptr<char>(new char[size]);
|
||||
memset(this->data.get(), fill, size);
|
||||
this->data = std::make_unique<char[]>(this->size);
|
||||
memset(this->data.get(), fill, this->size);
|
||||
ssize_t x = read(fd, this->data.get(), size_to_read);
|
||||
|
||||
close(fd);
|
||||
|
|
|
@ -11,12 +11,9 @@
|
|||
|
||||
namespace FxOS {
|
||||
|
||||
Binding::Binding(MemoryRegion source_region, Buffer source_buffer):
|
||||
region {source_region}, buffer {source_buffer}
|
||||
Binding::Binding(MemoryRegion source_region, Buffer const &source_buffer):
|
||||
region {source_region}, buffer {source_buffer, region.size()}
|
||||
{
|
||||
/* Extend the buffer if it's not at least as large as the region */
|
||||
if(buffer.size < region.size())
|
||||
buffer = Buffer(buffer, region.size());
|
||||
}
|
||||
|
||||
char const *Binding::translate_dynamic(uint32_t addr, int *size)
|
||||
|
|
Loading…
Reference in New Issue