summaryrefslogtreecommitdiff
path: root/apps/buffering.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/buffering.c')
-rw-r--r--apps/buffering.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/apps/buffering.c b/apps/buffering.c
index 3adbc4a6b9..f80d73a4a8 100644
--- a/apps/buffering.c
+++ b/apps/buffering.c
@@ -71,8 +71,6 @@
71/* amount of data to read in one read() call */ 71/* amount of data to read in one read() call */
72#define BUFFERING_DEFAULT_FILECHUNK (1024*32) 72#define BUFFERING_DEFAULT_FILECHUNK (1024*32)
73 73
74#define BUF_HANDLE_MASK 0x7FFFFFFF
75
76enum handle_flags 74enum handle_flags
77{ 75{
78 H_CANWRAP = 0x1, /* Handle data may wrap in buffer */ 76 H_CANWRAP = 0x1, /* Handle data may wrap in buffer */
@@ -295,12 +293,11 @@ static int next_handle_id(void)
295{ 293{
296 static int cur_handle_id = 0; 294 static int cur_handle_id = 0;
297 295
298 /* Wrap signed int is safe and 0 doesn't happen */ 296 int next_hid = cur_handle_id + 1;
299 int next_hid = (cur_handle_id + 1) & BUF_HANDLE_MASK; 297 if (next_hid == INT_MAX)
300 if (next_hid == 0) 298 cur_handle_id = 0; /* next would overflow; reset the counter */
301 next_hid = 1; 299 else
302 300 cur_handle_id = next_hid;
303 cur_handle_id = next_hid;
304 301
305 return next_hid; 302 return next_hid;
306} 303}