mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Fix memcpy(dest, NULL, 0) undefined behavior.
This commit is contained in:
parent
ef36a94912
commit
32feba2709
3 changed files with 18 additions and 7 deletions
|
@ -66,9 +66,12 @@ bool LineBuffer::Push(uint32_t unicode)
|
|||
size_t leadingavai = bufferlength-bufferoffset;
|
||||
size_t leading = (leadingavai < bufferused) ? leadingavai : bufferused;
|
||||
size_t trailing = bufferused - leading;
|
||||
memcpy(newbuffer, buffer + bufferoffset, leading * elemsize);
|
||||
memcpy(newbuffer + leading, buffer, trailing * elemsize);
|
||||
delete[] buffer;
|
||||
if ( buffer )
|
||||
{
|
||||
memcpy(newbuffer, buffer + bufferoffset, leading * elemsize);
|
||||
memcpy(newbuffer + leading, buffer, trailing * elemsize);
|
||||
delete[] buffer;
|
||||
}
|
||||
buffer = newbuffer;
|
||||
bufferlength = newbufferlength;
|
||||
bufferoffset = 0;
|
||||
|
|
|
@ -72,8 +72,12 @@ pid_t ProcessTable::Allocate(Process* process)
|
|||
struct ptable_entry* new_entries = new struct ptable_entry[new_length];
|
||||
if ( !new_entries )
|
||||
return -1;
|
||||
memcpy(new_entries, entries, sizeof(struct ptable_entry) * entries_length);
|
||||
delete[] entries;
|
||||
if ( entries )
|
||||
{
|
||||
size_t old_size = sizeof(struct ptable_entry) * entries_length;
|
||||
memcpy(new_entries, entries, old_size);
|
||||
delete[] entries;
|
||||
}
|
||||
entries = new_entries;
|
||||
entries_length = new_length;
|
||||
}
|
||||
|
|
|
@ -61,8 +61,12 @@ bool RegisterDevice(const char* name, VideoDevice* device)
|
|||
DeviceEntry* newdevices = new DeviceEntry[newdevices_length];
|
||||
if ( !newdevices )
|
||||
return false;
|
||||
memcpy(newdevices, devices, sizeof(*devices) * num_devices);
|
||||
delete[] devices; devices = newdevices;
|
||||
if ( devices )
|
||||
{
|
||||
memcpy(newdevices, devices, sizeof(*devices) * num_devices);
|
||||
delete[] devices;
|
||||
}
|
||||
devices = newdevices;
|
||||
devices_length = devices_length;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue