From 3fd64ccb483b36a1ecd7078cec2590f853300d32 Mon Sep 17 00:00:00 2001 From: Ron Koenderink Date: Sat, 19 Nov 2005 14:55:03 +0000 Subject: [PATCH] (getcontact,putcontact): Generalize the interface back to an int. Add range checks to prevent unexpected results. --- include/nat.h | 5 ++--- src/lib/common/nat.c | 10 ++++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/include/nat.h b/include/nat.h index 4c292acee..c31647d24 100644 --- a/include/nat.h +++ b/include/nat.h @@ -167,11 +167,10 @@ extern s_char *rejectname(struct natstr *np, natid other); extern s_char *natstate(struct natstr *np); extern int getrel(struct natstr *np, natid them); extern int getrejects(natid them, struct natstr *np); -extern unsigned char getcontact(struct natstr *np, natid them); +extern int getcontact(struct natstr *np, natid them); extern void putrel(struct natstr *np, natid them, int relate); extern void putreject(struct natstr *np, natid them, int how, int what); -extern void putcontact(struct natstr *np, natid them, - unsigned char contact); +extern void putcontact(struct natstr *np, natid them, int contact); extern void agecontact(struct natstr *np); /* nation flags */ diff --git a/src/lib/common/nat.c b/src/lib/common/nat.c index b6628f153..e8bd47628 100644 --- a/src/lib/common/nat.c +++ b/src/lib/common/nat.c @@ -31,6 +31,7 @@ * Dave Pare, 1989 */ +#include "prototypes.h" #include "misc.h" #include "nat.h" #include "file.h" @@ -128,7 +129,7 @@ agecontact(struct natstr *np) } } -unsigned char +int getcontact(struct natstr *np, natid them) { return np->nat_contact[them]; @@ -159,8 +160,13 @@ putreject(struct natstr *np, natid them, int how, int what) } void -putcontact(struct natstr *np, natid them, unsigned char contact) +putcontact(struct natstr *np, natid them, int contact) { + if (CANT_HAPPEN(contact < 0)) + contact = 0; + if (CANT_HAPPEN(contact > 255)) + contact = 255; + if (np->nat_contact[them] < contact) np->nat_contact[them] = contact; } -- 2.43.0