Download raw body.
bgpd: use unsigned int instead of uint8_t as loop iterator var
bgpd: use unsigned int instead of uint8_t as loop iterator var
bgpd: use unsigned int instead of uint8_t as loop iterator var
On Thu, May 07, 2026 at 11:04:49PM +0200, Theo Buehler wrote:
> On Thu, May 07, 2026 at 09:11:28PM +0200, Claudio Jeker wrote:
> > I like to move away from using size restricted variables for loop indexes
> > and length variables.
> >
> > Too often the limited range cause overflows in unexpeced ways. It is
> > better to use a default int type instead.
> >
> > This converts the uint8_t length vars for iterating over the others
> > attribute array to unsigned int. I also added early breaks in the loop in
> > two places since after the first NULL all values will be NULL as well.
>
> Small follow-up: when grepping for u_int, I spotted a few u_int8_t
> because I can't grep properly. So let's fix those.
>
> By the rationale for this diff, one of them should be a u_int because
> it's used in a for loop and there's another one in the vicinity (first
> two hunks).
>
> There are probably more for loops with uint8_t for aid in bgpd.
Yes, most certainly. Time to grep for AID_MAX.
Diff is OK claudio@.
> Index: parse.y
> ===================================================================
> RCS file: /cvs/src/usr.sbin/bgpd/parse.y,v
> diff -u -p -r1.489 parse.y
> --- parse.y 7 May 2026 18:55:05 -0000 1.489
> +++ parse.y 7 May 2026 21:01:23 -0000
> @@ -1989,7 +1989,7 @@ peeropts : REMOTEAS as4number {
> }
> | ANNOUNCE ADDPATH RECV yesnoenforce {
> int8_t *ap = curpeer->conf.capabilities.add_path;
> - uint8_t i;
> + u_int i;
>
> for (i = AID_MIN; i < AID_MAX; i++) {
> if ($4) {
> @@ -2003,7 +2003,7 @@ peeropts : REMOTEAS as4number {
> | ANNOUNCE ADDPATH SEND STRING addpathextra addpathmax enforce {
> int8_t *ap = curpeer->conf.capabilities.add_path;
> enum addpath_mode mode;
> - u_int8_t i;
> + u_int i;
>
> if (!strcmp($4, "no")) {
> free($4);
> @@ -5914,13 +5914,13 @@ push_binary_numop(enum comp_ops op, long
>
> struct icmptypeent {
> const char *name;
> - u_int8_t type;
> + uint8_t type;
> };
>
> struct icmpcodeent {
> const char *name;
> - u_int8_t type;
> - u_int8_t code;
> + uint8_t type;
> + uint8_t code;
> };
>
> static const struct icmptypeent icmp_type[] = {
>
--
:wq Claudio
bgpd: use unsigned int instead of uint8_t as loop iterator var
bgpd: use unsigned int instead of uint8_t as loop iterator var
bgpd: use unsigned int instead of uint8_t as loop iterator var