diff options
author | David Barksdale <amatus@amat.us> | 2017-02-20 13:08:08 -0600 |
---|---|---|
committer | David Barksdale <amatus@amat.us> | 2017-02-20 13:11:19 -0600 |
commit | fe4f6e8cedfa8d0a57b0247727fc4849d38c2f3a (patch) | |
tree | cbcbc99a93ec8f466426190a340cc46f54d2641e /src/datastore/plugin_datastore_heap.c | |
parent | f553963d649374a75cc5a6e57df39d83565eb913 (diff) |
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.
Diffstat (limited to 'src/datastore/plugin_datastore_heap.c')
-rw-r--r-- | src/datastore/plugin_datastore_heap.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/datastore/plugin_datastore_heap.c b/src/datastore/plugin_datastore_heap.c index 977d599d20..199c03a507 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); |