From 65a922f1144a89ad9aa95a29899fc3338ad8a35a Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 26 Jul 2016 12:27:28 +0000 Subject: [PATCH] change time multiplication/division API to long long to avoid accidental range reduction --- src/include/gnunet_bandwidth_lib.h | 4 ++-- src/include/gnunet_time_lib.h | 4 ++-- src/util/bandwidth.c | 4 ++++ src/util/time.c | 8 ++++---- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/include/gnunet_bandwidth_lib.h b/src/include/gnunet_bandwidth_lib.h index 7b63de390..178ddaaac 100644 --- a/src/include/gnunet_bandwidth_lib.h +++ b/src/include/gnunet_bandwidth_lib.h @@ -126,7 +126,7 @@ struct GNUNET_BANDWIDTH_Tracker struct GNUNET_TIME_Absolute last_update__; /** - * Bandwidth limit to enforce in bytes per s. + * Bandwidth limit to enforce in bytes per second. */ uint32_t available_bytes_per_s__; @@ -289,7 +289,7 @@ GNUNET_BANDWIDTH_tracker_consume (struct GNUNET_BANDWIDTH_Tracker *av, /** - * Compute how long we should wait until consuming 'size' + * Compute how long we should wait until consuming @a size * bytes of bandwidth in order to stay within the given * quota. * diff --git a/src/include/gnunet_time_lib.h b/src/include/gnunet_time_lib.h index 3dad179b5..64c5769c6 100644 --- a/src/include/gnunet_time_lib.h +++ b/src/include/gnunet_time_lib.h @@ -417,7 +417,7 @@ GNUNET_TIME_absolute_subtract (struct GNUNET_TIME_Absolute start, */ struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel, - unsigned int factor); + unsigned long long factor); /** @@ -429,7 +429,7 @@ GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel, */ struct GNUNET_TIME_Relative GNUNET_TIME_relative_divide (struct GNUNET_TIME_Relative rel, - unsigned int factor); + unsigned long long factor); /** diff --git a/src/util/bandwidth.c b/src/util/bandwidth.c index 61677fdcf..008963c3c 100644 --- a/src/util/bandwidth.c +++ b/src/util/bandwidth.c @@ -147,7 +147,11 @@ excess_trigger (void *cls) av->excess_task = NULL; if (NULL != av->excess_cb) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Notifying application about excess bandwidth\n"); av->excess_cb (av->excess_cb_cls); + } } diff --git a/src/util/time.c b/src/util/time.c index 91bbbf72a..eb168d531 100644 --- a/src/util/time.c +++ b/src/util/time.c @@ -427,7 +427,7 @@ GNUNET_TIME_absolute_subtract (struct GNUNET_TIME_Absolute start, */ struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel, - unsigned int factor) + unsigned long long factor) { struct GNUNET_TIME_Relative ret; @@ -435,7 +435,7 @@ GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel, return GNUNET_TIME_UNIT_ZERO; if (rel.rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us) return GNUNET_TIME_UNIT_FOREVER_REL; - ret.rel_value_us = rel.rel_value_us * (unsigned long long) factor; + ret.rel_value_us = rel.rel_value_us * factor; if (ret.rel_value_us / factor != rel.rel_value_us) { GNUNET_break (0); @@ -454,14 +454,14 @@ GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel, */ struct GNUNET_TIME_Relative GNUNET_TIME_relative_divide (struct GNUNET_TIME_Relative rel, - unsigned int factor) + unsigned long long factor) { struct GNUNET_TIME_Relative ret; if ((0 == factor) || (rel.rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)) return GNUNET_TIME_UNIT_FOREVER_REL; - ret.rel_value_us = rel.rel_value_us / (unsigned long long) factor; + ret.rel_value_us = rel.rel_value_us / factor; return ret; } -- 2.25.1