From fe4f6e8cedfa8d0a57b0247727fc4849d38c2f3a Mon Sep 17 00:00:00 2001 From: David Barksdale Date: Mon, 20 Feb 2017 13:08:08 -0600 Subject: Restrict update to positive priority deltas This is only ever called with positive values and the mysql and postgres plugins were not handling negative values correctly anyway. --- src/datastore/plugin_datastore_heap.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/datastore/plugin_datastore_heap.c') diff --git a/src/datastore/plugin_datastore_heap.c b/src/datastore/plugin_datastore_heap.c index 977d599d2..199c03a50 100644 --- a/src/datastore/plugin_datastore_heap.c +++ b/src/datastore/plugin_datastore_heap.c @@ -611,9 +611,7 @@ heap_plugin_get_expiration (void *cls, PluginDatumProcessor proc, * @param cls our `struct Plugin *` * @param uid unique identifier of the datum * @param delta by how much should the priority - * change? If priority + delta < 0 the - * priority should be set to 0 (never go - * negative). + * change? * @param expire new expiration time should be the * MAX of any existing expiration time and * this value @@ -623,7 +621,7 @@ heap_plugin_get_expiration (void *cls, PluginDatumProcessor proc, static void heap_plugin_update (void *cls, uint64_t uid, - int delta, + uint32_t delta, struct GNUNET_TIME_Absolute expire, PluginUpdateCont cont, void *cont_cls) @@ -638,8 +636,9 @@ heap_plugin_update (void *cls, GNUNET_CONTAINER_heap_update_cost (value->expire_heap, expire.abs_value_us); } - if ( (delta < 0) && (value->priority < - delta) ) - value->priority = 0; + /* Saturating add, don't overflow */ + if (value->priority > UINT32_MAX - delta) + value->priority = UINT32_MAX; else value->priority += delta; cont (cont_cls, GNUNET_OK, NULL); -- cgit v1.2.3