{"action":"created","issue":{"url":"https://api.github.com/repos/the-tcpdump-group/tcpdump/issues/443","labels_url":"https://api.github.com/repos/the-tcpdump-group/tcpdump/issues/443/labels{/name}","comments_url":"https://api.github.com/repos/the-tcpdump-group/tcpdump/issues/443/comments","events_url":"https://api.github.com/repos/the-tcpdump-group/tcpdump/issues/443/events","html_url":"https://github.com/the-tcpdump-group/tcpdump/issues/443","id":60684762,"number":443,"title":"Many warnings with ND_TTEST2 macro last update","user":{"login":"fxlb","id":2846004,"avatar_url":"https://avatars.githubusercontent.com/u/2846004?v=3","gravatar_id":"","url":"https://api.github.com/users/fxlb","html_url":"https://github.com/fxlb","followers_url":"https://api.github.com/users/fxlb/followers","following_url":"https://api.github.com/users/fxlb/following{/other_user}","gists_url":"https://api.github.com/users/fxlb/gists{/gist_id}","starred_url":"https://api.github.com/users/fxlb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fxlb/subscriptions","organizations_url":"https://api.github.com/users/fxlb/orgs","repos_url":"https://api.github.com/users/fxlb/repos","events_url":"https://api.github.com/users/fxlb/events{/privacy}","received_events_url":"https://api.github.com/users/fxlb/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2015-03-11T16:18:49Z","updated_at":"2015-03-14T21:05:06Z","closed_at":null,"body":"With the last change, we have more than 100 warnings on Travis.\r\nSee: https://travis-ci.org/the-tcpdump-group/tcpdump/builds/53903144\r\n```patch\r\n #define ND_TTEST2(var, l) \\\r\n+  ((l) >= 0 && \\\r\n \t((uintptr_t)ndo->ndo_snapend - (l) <= (uintptr_t)ndo->ndo_snapend && \\\r\n-\t    (uintptr_t)&(var) <= (uintptr_t)ndo->ndo_snapend - (l))\r\n+         (uintptr_t)&(var) <= (uintptr_t)ndo->ndo_snapend - (l)))\r\n```\r\nI don't see now a straightforward fix."},"comment":{"url":"https://api.github.com/repos/the-tcpdump-group/tcpdump/issues/comments/80719920","html_url":"https://github.com/the-tcpdump-group/tcpdump/issues/443#issuecomment-80719920","issue_url":"https://api.github.com/repos/the-tcpdump-group/tcpdump/issues/443","id":80719920,"user":{"login":"guyharris","id":3599441,"avatar_url":"https://avatars.githubusercontent.com/u/3599441?v=3","gravatar_id":"","url":"https://api.github.com/users/guyharris","html_url":"https://github.com/guyharris","followers_url":"https://api.github.com/users/guyharris/followers","following_url":"https://api.github.com/users/guyharris/following{/other_user}","gists_url":"https://api.github.com/users/guyharris/gists{/gist_id}","starred_url":"https://api.github.com/users/guyharris/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guyharris/subscriptions","organizations_url":"https://api.github.com/users/guyharris/orgs","repos_url":"https://api.github.com/users/guyharris/repos","events_url":"https://api.github.com/users/guyharris/events{/privacy}","received_events_url":"https://api.github.com/users/guyharris/received_events","type":"User","site_admin":false},"created_at":"2015-03-14T21:05:05Z","updated_at":"2015-03-14T21:05:05Z","body":"In the example you give, foo is unsigned - and 9 is signed, as per \"Semantics\" in section 6.1.3.2 \"Integer constants\" in C90:\r\n\r\n> The type of an integer constant is the first of the corresponding list in which its value can be represented. Unsuffixed decimal: ***`int`***, ***`long int`***, ***`unsigned long int`***; ...\r\n\r\nSo the \"Usual arithmetic conversions\", section 6.2.1.5 of C90, apply:\r\n\r\n> Otherwise, the integral promotions are performed on both operands. Then the following rules are applied:\r\n\r\n> If either operand has type ***`unsigned long int`***, the other operand is converted to ***`unsigned long int`***.\r\n> Otherwise, if one operand has type ***`long int`*** and the other has type ***`unsigned int`***, if a ***`long int`*** can represent all values of an ***`unsigned int`***, the operand of type ***`unsigned int`*** is converted to ***`long int`***; if a ***`long int`*** cannot represent all the values of an ***`unsigned int`***, both operands are converted to ***`unsigned long int`***.\r\n> Otherwise, if either operand has type ***`long int`***, the other operand is converted to ***`long int`***.\r\n> Otherwise, if either operand has type ***`unsigned int`***, the other operand is converted to ***`unsigned int`***.\r\n> Otherwise, both operands have type ***`int`***.\r\n\r\nwhere the \"integral promotions\", from section 6.2.1.1 \"Characters and integers\" of C90, are:\r\n\r\n> A ***`char`***, a ***`short int`***, or an ***`int`*** bit-field, or their signed or unsigned varieties, or an\r\nenumeration type, may be used in an expression wherever an ***`int`*** or ***`unsigned int`*** may be\r\nused. If an ***`int`*** can represent all values of the original type, the value is converted to an ***`int`***;\r\notherwise, it is converted to an ***`unsigned int`***. These are called the *integral promotions*. other arithmetic types are unchanged by the integral promotions.\r\n\r\nThe \"integral promotions\" don't apply, as we're not dealing with shorter-than-`int` values.  What *does* apply is \"Otherwise, if either operand has type ***`unsigned int`***, the other operand is converted to ***`unsigned int`***, so 9 gets converted from `int` to `unsigned int`.\r\n\r\nSection 6.1.2.5 \"Types\" of C90 says:\r\n\r\n> A computation involving unsigned operands can never overflow, because a result that cannot be represented by the resulting unsigned integer type is reduced modulo the number that is one greater than the largest value that can be represented by the resulting unsigned integer type.\r\n\r\nPresumably by \"overflow ... reduced\" they mean both \"overflow ... reduced\" and \"underflow ... increased\", so that a subtraction cannot underflow, so `foo-9` evaluates as 2^32-1 on an ILP32, LP64, or ILP64 platform.\r\n\r\nIf `foo` were `int`, however, the subtraction really *would* result in -1, and `ND_TTEST2()` would succeed."}}