Messages in this thread | | | Date | Fri, 14 Oct 2022 08:52:19 -0700 | From | Jakub Kicinski <> | Subject | Re: [PATCH V2 1/2] net: Fixup netif_attrmask_next_and warning |
| |
On Fri, 14 Oct 2022 14:38:56 +0800 Guo Ren wrote: > > This does not look equivalent, have you tested it? > > > > nr_ids is unsigned, doesn't it mean we'll never enter the loop? > > Yes, you are right. Any unsigned int would break the result. > (gdb) p (int)-1 < (int)2 > $1 = 1 > (gdb) p (int)-1 < (unsigned int)2 > $2 = 0 > (gdb) p (unsigned int)-1 < (int)2 > $4 = 0 > > So it should be: > - for (j = -1; j = netif_attrmask_next_and(j, online_mask, mask, nr_ids), > - j < nr_ids;) { > + for (j = -1; j < (int)nr_ids; > + j = netif_attrmask_next_and(j, online_mask, mask, nr_ids)) { > > Right? Of cause, nr_ids couldn't be 0xffffffff (-1).
No. You can't enter the loop with -1 as the iterator either. Let's move on.
| |