mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Fix PS2Keyboard memcpy(dest, NULL, 0) undefined behavior.
This commit is contained in:
parent
421f907055
commit
f2eb347e9f
1 changed files with 10 additions and 7 deletions
|
@ -210,6 +210,8 @@ bool PS2Keyboard::PushKey(int key)
|
|||
int* newqueue = new int[newqueuelength];
|
||||
if ( !newqueue )
|
||||
return false;
|
||||
if ( queue )
|
||||
{
|
||||
size_t elemsize = sizeof(*queue);
|
||||
size_t leadingavai = queuelength-queueoffset;
|
||||
size_t leading = (leadingavai < queueused) ? leadingavai : queueused;
|
||||
|
@ -217,6 +219,7 @@ bool PS2Keyboard::PushKey(int key)
|
|||
memcpy(newqueue, queue + queueoffset, leading * elemsize);
|
||||
memcpy(newqueue + leading, queue, trailing * elemsize);
|
||||
delete[] queue;
|
||||
}
|
||||
queue = newqueue;
|
||||
queuelength = newqueuelength;
|
||||
queueoffset = 0;
|
||||
|
|
Loading…
Reference in a new issue