{"thread":{"id":"31877","subject":"[PATCH] grep: remove tautological check","startedAt":"2012-10-20T17:26:04Z","lastAt":"2012-10-22T13:20:50Z","messageCount":3,"participants":["David Soria Parra","Peter Krefting"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"201596","messageId":"1350753964-29346-1-git-send-email-dsp@php.net","threadId":"31877","inReplyTo":null,"subject":"[PATCH] grep: remove tautological check","fromName":"David Soria Parra","fromEmail":"dsp@php.net","sentAt":"2012-10-20T17:26:04Z","receivedAt":"2012-10-20T17:26:04Z","isPatch":true,"sender":{"key":"dsp@php.net","avatar":"https://avatars.githubusercontent.com/u/14013?v=4"},"body":"The enum grep_header_field is unsigned. Therefore the field part of the\ngrep_pat structure is unsigned and cannot be less then 0. We remove the\ntautological check for p->field < 0.\n\nSigned-off-by: David Soria Parra <dsp@php.net>\n---\n grep.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/grep.c b/grep.c\nindex 4bd1b8b..db177ef 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -625,7 +625,7 @@ static struct grep_expr *prep_header_patterns(struct grep_opt *opt)\n \tfor (p = opt->header_list; p; p = p->next) {\n \t\tif (p->token != GREP_PATTERN_HEAD)\n \t\t\tdie(\"bug: a non-header pattern in grep header list.\");\n-\t\tif (p->field < 0 || GREP_HEADER_FIELD_MAX <= p->field)\n+\t\tif (GREP_HEADER_FIELD_MAX <= p->field)\n \t\t\tdie(\"bug: unknown header field %d\", p->field);\n \t\tcompile_regexp(p, opt);\n \t}\n-- \n1.8.0.rc3.332.g181c802\n"},{"id":"201598","messageId":"alpine.DEB.2.00.1210202022270.19498@ds9.cixit.se","threadId":"31877","inReplyTo":"1350753964-29346-1-git-send-email-dsp@php.net","subject":"Re: [PATCH] grep: remove tautological check","fromName":"Peter Krefting","fromEmail":"peter@softwolves.pp.se","sentAt":"2012-10-20T19:23:43Z","receivedAt":"2012-10-20T19:23:43Z","isPatch":true,"sender":{"key":"peter@softwolves.pp.se","avatar":"https://avatars.githubusercontent.com/u/990764?v=4"},"body":"David Soria Parra:\n\n> The enum grep_header_field is unsigned.\n\nEnumerations can be either unsigned or signed, it is up to the \ncompiler to decide. Even if you assign only positive number to named \nenumeration values, there are compilers that make them signed. I've \nbeen bitten by that enough.\n\n-- \n\\\\// Peter - http://www.softwolves.pp.se/\n"},{"id":"201688","messageId":"alpine.DEB.2.00.1210221416080.32103@ds9.cixit.se","threadId":"31877","inReplyTo":"1350753964-29346-1-git-send-email-dsp@php.net","subject":"Re: [PATCH] grep: remove tautological check","fromName":"Peter Krefting","fromEmail":"peter@softwolves.pp.se","sentAt":"2012-10-22T13:20:50Z","receivedAt":"2012-10-22T13:20:50Z","isPatch":true,"sender":{"key":"peter@softwolves.pp.se","avatar":"https://avatars.githubusercontent.com/u/990764?v=4"},"body":"David Soria Parra:\n\n> -\t\tif (p->field < 0 || GREP_HEADER_FIELD_MAX <= p->field)\n> +\t\tif (GREP_HEADER_FIELD_MAX <= p->field)\n\nA friend taught me this trick, which will check that it isn't negative \nfor compilers that have the enumeration be signed (notably MSVC), \nwhile not complaining for compilers that have it unsigned (GCC, Clang):\n\n   const unsigned int sign = 1u << (sizeof(p->field) * CHAR_BIT - 1);\n   if (!(sign & (unsigned int) p->field) || GREP_HEADER_FIELD_MAX <= p->field)\n\n-- \n\\\\// Peter - http://www.softwolves.pp.se/\n"}]}