On 10.02.2016 13:30, Samuel Thibault wrote: > Thomas Huth, on Wed 10 Feb 2016 11:47:05 +0100, wrote: >>> + ip = mtod(m, struct ip *); >>> + ip6 = mtod(m, struct ip6 *); >>> + save_ip = *ip; >>> + save_ip6 = *ip6; >> >> Could you do the "save_ip = *ip" within the "case AF_INET" below, and >> the "save_ip6 = *ip6" within the case AF_INET6 ? That would avoid to >> copy bytes that are not required. > > The issue is that when save_ip is used later on in another switch/case, > the compiler will warn that save_ip may be used uninitialized, because > the compiler is not smart enough to realize that the two codes are under > the same conditions. It seems to happen that my current version of gcc > doesn't warn about save_ip, but it does warn about ip if I moved that > too for instance. So we can move the assignment indeed, but there will > probably be some compilers which will emit a warning here, I don't know > what we prefer.
If current compilers only complain about the "ip = ..." statement, then I'd suggest to give it a try to only move the "save_ip = ..." statements into the switch cases (I think it's worth a try since this is the more expensive operation). If that causes trouble later, we can still move the statements back (or maybe fix the warnings by other means). Thomas