Re: [PATCH] grep: remove tautological check

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



David Soria Parra:

-		if (p->field < 0 || GREP_HEADER_FIELD_MAX <= p->field)
+		if (GREP_HEADER_FIELD_MAX <= p->field)

A friend taught me this trick, which will check that it isn't negative for compilers that have the enumeration be signed (notably MSVC), while not complaining for compilers that have it unsigned (GCC, Clang):

  const unsigned int sign = 1u << (sizeof(p->field) * CHAR_BIT - 1);
  if (!(sign & (unsigned int) p->field) || GREP_HEADER_FIELD_MAX <= p->field)

--
\\// Peter - http://www.softwolves.pp.se/
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]