1
0
Fork 0
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:
Jonas 'Sortie' Termansen 2015-12-12 22:52:40 +01:00
parent 421f907055
commit f2eb347e9f

View file

@ -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;