diff options
-rw-r--r-- | apps/buffering.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/apps/buffering.c b/apps/buffering.c index 77eaba8959..de9b28c298 100644 --- a/apps/buffering.c +++ b/apps/buffering.c | |||
@@ -105,7 +105,7 @@ | |||
105 | 105 | ||
106 | /* assert(sizeof(struct memory_handle)%4==0) */ | 106 | /* assert(sizeof(struct memory_handle)%4==0) */ |
107 | struct memory_handle { | 107 | struct memory_handle { |
108 | unsigned int id; /* A unique ID for the handle */ | 108 | int id; /* A unique ID for the handle */ |
109 | enum data_type type; /* Type of data buffered with this handle */ | 109 | enum data_type type; /* Type of data buffered with this handle */ |
110 | char path[MAX_PATH]; /* Path if data originated in a file */ | 110 | char path[MAX_PATH]; /* Path if data originated in a file */ |
111 | int fd; /* File descriptor to path (-1 if closed) */ | 111 | int fd; /* File descriptor to path (-1 if closed) */ |
@@ -146,7 +146,7 @@ static struct memory_handle *first_handle; | |||
146 | 146 | ||
147 | static int num_handles; /* number of handles in the list */ | 147 | static int num_handles; /* number of handles in the list */ |
148 | 148 | ||
149 | static unsigned int base_handle_id; | 149 | static int base_handle_id; |
150 | 150 | ||
151 | static struct mutex llist_mutex; | 151 | static struct mutex llist_mutex; |
152 | 152 | ||
@@ -223,8 +223,8 @@ buf_ridx == buf_widx means the buffer is empty. | |||
223 | static struct memory_handle *add_handle(size_t data_size, const bool can_wrap, | 223 | static struct memory_handle *add_handle(size_t data_size, const bool can_wrap, |
224 | const bool alloc_all) | 224 | const bool alloc_all) |
225 | { | 225 | { |
226 | /* gives each handle a unique id, unsigned to handle wraps gracefully */ | 226 | /* gives each handle a unique id */ |
227 | static unsigned int cur_handle_id = 1; | 227 | static int cur_handle_id = 1; |
228 | size_t shift; | 228 | size_t shift; |
229 | size_t new_widx; | 229 | size_t new_widx; |
230 | size_t len; | 230 | size_t len; |
@@ -291,9 +291,8 @@ static struct memory_handle *add_handle(size_t data_size, const bool can_wrap, | |||
291 | buf_widx = RINGBUF_ADD(buf_widx, sizeof(struct memory_handle)); | 291 | buf_widx = RINGBUF_ADD(buf_widx, sizeof(struct memory_handle)); |
292 | 292 | ||
293 | new_handle->id = cur_handle_id; | 293 | new_handle->id = cur_handle_id; |
294 | /* Use += 2 instead of ++ to guarantee that the low bit is always high and | 294 | /* Wrap signed int is safe and 0 doesn't happen */ |
295 | * prevent the assignment of a zero id when wrapping. */ | 295 | if (++cur_handle_id < 1) cur_handle_id = 1; |
296 | cur_handle_id += 2; | ||
297 | new_handle->next = NULL; | 296 | new_handle->next = NULL; |
298 | num_handles++; | 297 | num_handles++; |
299 | 298 | ||
@@ -358,7 +357,7 @@ static bool rm_handle(const struct memory_handle *h) | |||
358 | 357 | ||
359 | /* Return a pointer to the memory handle of given ID. | 358 | /* Return a pointer to the memory handle of given ID. |
360 | NULL if the handle wasn't found */ | 359 | NULL if the handle wasn't found */ |
361 | static struct memory_handle *find_handle(const unsigned int handle_id) | 360 | static struct memory_handle *find_handle(const int handle_id) |
362 | { | 361 | { |
363 | if (handle_id <= 0) | 362 | if (handle_id <= 0) |
364 | return NULL; | 363 | return NULL; |