{"thread":{"id":"46800","subject":"[PATCH 1/4] git-compat-util.h: xsize_t() - avoid -Wsign-compare warnings","startedAt":"2017-09-21T16:46:30Z","lastAt":"2017-09-21T19:02:51Z","messageCount":4,"participants":["Ramsay Jones","Torsten Bögershausen","Stefan Beller"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"328575","messageId":"15367a04-754c-f6b8-a89b-2c1ff65dedf5@ramsayjones.plus.com","threadId":"46800","inReplyTo":null,"subject":"[PATCH 1/4] git-compat-util.h: xsize_t() - avoid -Wsign-compare warnings","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsayjones.plus.com","sentAt":"2017-09-21T16:46:24Z","receivedAt":"2017-09-21T16:46:30Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"\nSigned-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>\n---\n git-compat-util.h | 6 ++++--\n 1 file changed, 4 insertions(+), 2 deletions(-)\n\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex 9bc15b036..cedad4d58 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -898,9 +898,11 @@ static inline char *xstrdup_or_null(const char *str)\n \n static inline size_t xsize_t(off_t len)\n {\n-\tif (len > (size_t) len)\n+\tsize_t size = (size_t) len;\n+\n+\tif (len != (off_t) size)\n \t\tdie(\"Cannot handle files this big\");\n-\treturn (size_t)len;\n+\treturn size;\n }\n \n __attribute__((format (printf, 3, 4)))\n-- \n2.14.0\n"},{"id":"328586","messageId":"75416139-74c5-8a60-22e8-79c53dd062c1@web.de","threadId":"46800","inReplyTo":"15367a04-754c-f6b8-a89b-2c1ff65dedf5@ramsayjones.plus.com","subject":"Re: [PATCH 1/4] git-compat-util.h: xsize_t() - avoid -Wsign-compare warnings","fromName":"Torsten Bögershausen","fromEmail":"tboegi@web.de","sentAt":"2017-09-21T18:49:31Z","receivedAt":"2017-09-21T18:50:09Z","isPatch":true,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"On 2017-09-21 18:46, Ramsay Jones wrote:\n> \n> Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>\n> ---\n>  git-compat-util.h | 6 ++++--\n>  1 file changed, 4 insertions(+), 2 deletions(-)\n> \n> diff --git a/git-compat-util.h b/git-compat-util.h\n> index 9bc15b036..cedad4d58 100644\n> --- a/git-compat-util.h\n> +++ b/git-compat-util.h\n> @@ -898,9 +898,11 @@ static inline char *xstrdup_or_null(const char *str)\n>  \n>  static inline size_t xsize_t(off_t len)\n>  {\n> -\tif (len > (size_t) len)\n> +\tsize_t size = (size_t) len;\n> +\n> +\tif (len != (off_t) size)\n>  \t\tdie(\"Cannot handle files this big\");\n> -\treturn (size_t)len;\n> +\treturn size;\n\nHm, can someone help me out ?\nWhy is the cast not needed ?\n\n>  }\n>  \n>  __attribute__((format (printf, 3, 4)))\n> \n\n"},{"id":"328587","messageId":"CAGZ79kYuGpO5Ji9vwqwy_2=ea2Vd9CG2ethzyhXUc709KQSSaQ@mail.gmail.com","threadId":"46800","inReplyTo":"75416139-74c5-8a60-22e8-79c53dd062c1@web.de","subject":"Re: [PATCH 1/4] git-compat-util.h: xsize_t() - avoid -Wsign-compare warnings","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2017-09-21T18:57:26Z","receivedAt":"2017-09-21T18:57:32Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Thu, Sep 21, 2017 at 11:49 AM, Torsten Bögershausen <tboegi@web.de> wrote:\n> On 2017-09-21 18:46, Ramsay Jones wrote:\n>>\n>> Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>\n>> ---\n>>  git-compat-util.h | 6 ++++--\n>>  1 file changed, 4 insertions(+), 2 deletions(-)\n>>\n>> diff --git a/git-compat-util.h b/git-compat-util.h\n>> index 9bc15b036..cedad4d58 100644\n>> --- a/git-compat-util.h\n>> +++ b/git-compat-util.h\n>> @@ -898,9 +898,11 @@ static inline char *xstrdup_or_null(const char *str)\n>>\n>>  static inline size_t xsize_t(off_t len)\n>>  {\n>> -     if (len > (size_t) len)\n>> +     size_t size = (size_t) len;\n>> +\n>> +     if (len != (off_t) size)\n>>               die(\"Cannot handle files this big\");\n>> -     return (size_t)len;\n>> +     return size;\n>\n> Hm, can someone help me out ?\n> Why is the cast not needed ?\n\nBecause 'size' is already size_t,\n(cast was done in first line of the function:\n    size_t size = (size_t) len;\n), previously we cast len multiple times,\nnow we cast it once and use size thereafter.\n\n>\n>>  }\n>>\n>>  __attribute__((format (printf, 3, 4)))\n>>\n>\n"},{"id":"328588","messageId":"1b778d3b-56d5-4cda-1b75-b0e81e19874e@ramsayjones.plus.com","threadId":"46800","inReplyTo":"75416139-74c5-8a60-22e8-79c53dd062c1@web.de","subject":"Re: [PATCH 1/4] git-compat-util.h: xsize_t() - avoid -Wsign-compare warnings","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsayjones.plus.com","sentAt":"2017-09-21T19:02:44Z","receivedAt":"2017-09-21T19:02:51Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"\n\nOn 21/09/17 19:49, Torsten Bögershausen wrote:\n> On 2017-09-21 18:46, Ramsay Jones wrote:\n>>\n>> Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>\n>> ---\n>>  git-compat-util.h | 6 ++++--\n>>  1 file changed, 4 insertions(+), 2 deletions(-)\n>>\n>> diff --git a/git-compat-util.h b/git-compat-util.h\n>> index 9bc15b036..cedad4d58 100644\n>> --- a/git-compat-util.h\n>> +++ b/git-compat-util.h\n>> @@ -898,9 +898,11 @@ static inline char *xstrdup_or_null(const char *str)\n>>  \n>>  static inline size_t xsize_t(off_t len)\n>>  {\n>> -\tif (len > (size_t) len)\n>> +\tsize_t size = (size_t) len;\n>> +\n>> +\tif (len != (off_t) size)\n>>  \t\tdie(\"Cannot handle files this big\");\n>> -\treturn (size_t)len;\n>> +\treturn size;\n> \n> Hm, can someone help me out ?\n> Why is the cast not needed ?\n\nThe cast in the return statement? If so, because the 'size' variable\nhas been declared with the size_t type. (The truncation, if any, would\nhappen when 'size' is initialised in the declaration).\n\nHope that helps.\n\nATB,\nRamsay Jones\n\n\n"}]}