Hello, Coverity. A uint8_t is 8 bits long, and is unsigned; if you
shift it right by 4 bits, the result is the lower 4 bits. 4 bits can
represent values from 0 to 15, so YOU CAN BE CERTAIN THAT SAID VALUE CAN
SAFELY BE USED AS AN INDEX INTO AN ARRAY WITH 16 ELEMENTS.
Extract the value into a uint8_t, to see if *that* allows Coverity to
see that (rather than saying "ZOMG THAT CONVERTS TO AN int AND IT'S NOT
MASKED WITH 0xf IT MIGHT BE OUT OF RANGE DANGER DANGER WILL ROBINSON").
If not, we may just have to mask it with 0xf to pacify Coverity.
The resulting code also flows a bit better - no auto-incrementation in
the subscript operation, and the fetching being done separately from the
conversion to hex.
Should address Coverity CID
1449413, and possibly others.
etheraddr_string(netdissect_options *ndo, const uint8_t *ep)
{
int i;
etheraddr_string(netdissect_options *ndo, const uint8_t *ep)
{
int i;
char *cp;
struct enamemem *tp;
int oui;
char *cp;
struct enamemem *tp;
int oui;
#endif
cp = buf;
oui = EXTRACT_BE_U_3(ep);
#endif
cp = buf;
oui = EXTRACT_BE_U_3(ep);
- *cp++ = hex[*ep >> 4 ];
- *cp++ = hex[*ep++ & 0xf];
+ octet = *ep++;
+ *cp++ = hex[octet >> 4];
+ *cp++ = hex[octet & 0xf];
for (i = 5; --i >= 0;) {
*cp++ = ':';
for (i = 5; --i >= 0;) {
*cp++ = ':';
- *cp++ = hex[*ep >> 4 ];
- *cp++ = hex[*ep++ & 0xf];
+ octet = *ep++;
+ *cp++ = hex[octet >> 4];
+ *cp++ = hex[octet & 0xf];
{
const unsigned int len = 8;
u_int i;
{
const unsigned int len = 8;
u_int i;
char *cp;
struct bsnamemem *tp;
char buf[BUFSIZE];
char *cp;
struct bsnamemem *tp;
char buf[BUFSIZE];
cp = buf;
for (i = len; i > 0 ; --i) {
cp = buf;
for (i = len; i > 0 ; --i) {
- *cp++ = hex[*(ep + i - 1) >> 4];
- *cp++ = hex[*(ep + i - 1) & 0xf];
+ octet = *(ep + i - 1);
+ *cp++ = hex[octet >> 4];
+ *cp++ = hex[octet & 0xf];
const unsigned int type, const unsigned int len)
{
u_int i;
const unsigned int type, const unsigned int len)
{
u_int i;
char *cp;
struct bsnamemem *tp;
char *cp;
struct bsnamemem *tp;
if (tp->bs_name == NULL)
(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
"linkaddr_string: malloc");
if (tp->bs_name == NULL)
(*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
"linkaddr_string: malloc");
- *cp++ = hex[*ep >> 4];
- *cp++ = hex[*ep++ & 0xf];
+ octet = *ep++;
+ *cp++ = hex[octet >> 4];
+ *cp++ = hex[octet & 0xf];
for (i = len-1; i > 0 ; --i) {
*cp++ = ':';
for (i = len-1; i > 0 ; --i) {
*cp++ = ':';
- *cp++ = hex[*ep >> 4];
- *cp++ = hex[*ep++ & 0xf];
+ octet = *ep++;
+ *cp++ = hex[octet >> 4];
+ *cp++ = hex[octet & 0xf];
}
*cp = '\0';
return (tp->bs_name);
}
*cp = '\0';
return (tp->bs_name);
u_int nsap_length)
{
u_int nsap_idx;
u_int nsap_length)
{
u_int nsap_idx;
char *cp;
struct enamemem *tp;
char *cp;
struct enamemem *tp;
"isonsap_string: malloc");
for (nsap_idx = 0; nsap_idx < nsap_length; nsap_idx++) {
"isonsap_string: malloc");
for (nsap_idx = 0; nsap_idx < nsap_length; nsap_idx++) {
- *cp++ = hex[*nsap >> 4];
- *cp++ = hex[*nsap++ & 0xf];
+ octet = *nsap++;
+ *cp++ = hex[octet >> 4];
+ *cp++ = hex[octet & 0xf];
if (((nsap_idx & 1) == 0) &&
(nsap_idx + 1 < nsap_length)) {
*cp++ = '.';
if (((nsap_idx & 1) == 0) &&
(nsap_idx + 1 < nsap_length)) {
*cp++ = '.';