V501 There are identical sub-expressions ‘(uintptr_t) b->handler’ to the left and to the right of the ‘>’ operator. ip_fw_sockopt.c 2893

static int
compare_sh(const void *_a, const void *_b)
  const struct ipfw_sopt_handler *a, *b;

  a = (const struct ipfw_sopt_handler *)_a;
  b = (const struct ipfw_sopt_handler *)_b;
  if ((uintptr_t)a->handler < (uintptr_t)b->handler)
    return (-1);
  else if ((uintptr_t)b->handler > (uintptr_t)b->handler) 
    return (1);
  return (0);

Here is a vivid example of a bad practice – giving the variables short and uninformative names. Now because of the typo in the letter b, the a part of the condition will never be return 1. Thus, the function returns a zero status not always correctly.

Please click here to see more bugs from this project.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.