More robust eatbytes() that guards against the buffer going negative, because size_t is not signed
This commit is contained in:
parent
31414eac3b
commit
53b0d0aca9
@ -188,14 +188,15 @@ int termkey_getwaittime(termkey_t *tk)
|
||||
|
||||
static inline void eatbytes(termkey_t *tk, size_t count)
|
||||
{
|
||||
tk->buffstart += count;
|
||||
tk->buffcount -= count;
|
||||
|
||||
if(tk->buffcount <= 0) {
|
||||
if(count >= tk->buffcount) {
|
||||
tk->buffstart = 0;
|
||||
tk->buffcount = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
tk->buffstart += count;
|
||||
tk->buffcount -= count;
|
||||
|
||||
size_t halfsize = tk->buffsize / 2;
|
||||
|
||||
if(tk->buffstart > halfsize) {
|
||||
|
Loading…
Reference in New Issue
Block a user