On Wed, Dec 02, 2020 at 12:19:11PM +0100, Claudio Jeker wrote:
> The overflow check for the relative metric adjustments of filtersets
> assumes a certain overflow behaviour of signed integers. I think it is
> better to write this in a way that does not involve an overflow.
> 

Here a small follow up. The underflow check can be adjusted to be similar
to the overflow check which makes my OCD happy.

OK?
-- 
:wq Claudio

Index: rde_filter.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/rde_filter.c,v
retrieving revision 1.125
diff -u -p -r1.125 rde_filter.c
--- rde_filter.c        3 Dec 2020 11:53:34 -0000       1.125
+++ rde_filter.c        3 Dec 2020 11:58:58 -0000
@@ -55,8 +55,8 @@ rde_apply_set(struct filter_set_head *sh
                                        state->aspath.lpref +=
                                            set->action.relative;
                        } else {
-                               if ((u_int32_t)-set->action.relative >
-                                   state->aspath.lpref)
+                               if (state->aspath.lpref <
+                                   0U - set->action.relative)
                                        state->aspath.lpref = 0;
                                else
                                        state->aspath.lpref +=
@@ -77,8 +77,8 @@ rde_apply_set(struct filter_set_head *sh
                                        state->aspath.med +=
                                            set->action.relative;
                        } else {
-                               if ((u_int32_t)-set->action.relative >
-                                   state->aspath.med)
+                               if (state->aspath.med <
+                                   0U - set->action.relative)
                                        state->aspath.med = 0;
                                else
                                        state->aspath.med +=
@@ -97,8 +97,8 @@ rde_apply_set(struct filter_set_head *sh
                                        state->aspath.weight +=
                                            set->action.relative;
                        } else {
-                               if ((u_int32_t)-set->action.relative >
-                                   state->aspath.weight)
+                               if (state->aspath.weight <
+                                   0U - set->action.relative)
                                        state->aspath.weight = 0;
                                else
                                        state->aspath.weight +=

Reply via email to