aboutsummaryrefslogtreecommitdiff
path: root/termkey.c
diff options
context:
space:
mode:
authorPaul LeoNerd Evans <leonerd@leonerd.org.uk>2008-02-10 20:24:25 +0000
committerPaul LeoNerd Evans <leonerd@leonerd.org.uk>2008-02-10 20:24:25 +0000
commit53b0d0aca9d87361f6add5c1ff8380b8101ffceb (patch)
tree457baf78672d96890018b7f32cf868df43fce973 /termkey.c
parent31414eac3bbc40ac10a46a2f5c49ea87b216311a (diff)
downloadtermo-53b0d0aca9d87361f6add5c1ff8380b8101ffceb.tar.gz
termo-53b0d0aca9d87361f6add5c1ff8380b8101ffceb.tar.xz
termo-53b0d0aca9d87361f6add5c1ff8380b8101ffceb.zip
More robust eatbytes() that guards against the buffer going negative, because size_t is not signed
Diffstat (limited to 'termkey.c')
-rw-r--r--termkey.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/termkey.c b/termkey.c
index 819b49f..644629f 100644
--- a/termkey.c
+++ b/termkey.c
@@ -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) {