Cast pointer differences, widen some variables, make some function
returns unsigned as they never return a negative number.
Fix a format while we're at it.
Get rid of the global nfserr variable and, instead, have it be local to
interp_reply(). That means one less global variable, which may be good
if any multi-threaded program tries to use libnetdissect in more than
one thread (there are still global variables that would have to be
removed), and gets rid of some cases where we didn't need to set it.
Don't bundle multiple operations inside an if clause. This squelches
some warnings from MSVC, and makes the code a bit more uniform and a bit
easier to understand (and, in the process of doing that, found a bug
that was fixed in 596aca3d93).
This eliminates a warning from MSVC, and makes the flow a little
clearer.
(Yes, it duplicates some code, but compilers have been pretty good at
merging common code sequences, so it might just turn it into the
equivalent of
if (optopt == (int)':')
goto label;
oli = strchr(ostr, optopt);
if (!oli) {
label:
/*
* Unknown option character.
*/
if (!*place)
++optind;
...
}
although it does mean that the same C code exists in two places.)
Some of the narrowing warnings are false positives; newer versions of
Clang do a better job than older ones of determining the range of values
of expressions, and don't warn if the range is such that it can be
safely narrowed, so maybe the same is true of MSVC.
Because packet length (length) >= capture length (caplen), when
caplen >= ETHER_HDRLEN, length >= caplen cannot be < ETHER_HDRLEN.
Same for the other test (length < 4).
(see the sanity checks in print.c, pretty_print_packet() function)
Moreover:
Clean up indentation.
Prior to ARMv6, it didn't support it. ARMv6 supports it, if the "don't
act like ARMv5" bit isn't set in the system control register, but has
another bit in the system control register to cause unaligned accesses
to fault rather than succeed. ARMv7 and later don't have "act like
ARMv5" mode, but still has the "fault on unaligned access" bit.
At least some OSes might set the "fault on unaligned access" bit; if
your OS *doesn't* set it, feel free to modify the #if to check for your
OS and for ARM.
"_if", in function names, is just a convention used for the top-level
routine for a given DLT_ value; it's not part of the protocol name for
the link-layer type.