{"thread":{"id":"62855","subject":"[PATCH v3 2/4] date.c: Fix type conversation warnings from msvc","startedAt":"2025-01-26T12:59:59Z","lastAt":"2025-01-28T08:46:00Z","messageCount":4,"participants":["Sören Krecker","Patrick Steinhardt","Junio C Hamano"],"isPatch":true,"patchVersion":3,"patchTotal":4},"messages":[{"id":"511208","messageId":"20250126125850.3195-1-soekkle@freenet.de","threadId":"62855","inReplyTo":null,"subject":"[PATCH v3 2/4] date.c: Fix type conversation warnings from msvc","fromName":"Sören Krecker","fromEmail":"soekkle@freenet.de","sentAt":"2025-01-26T12:58:50Z","receivedAt":"2025-01-26T12:59:59Z","isPatch":true,"sender":{"key":"soekkle@freenet.de","avatar":"https://avatars.githubusercontent.com/u/6253399?v=4"},"body":"Fix compiler warnings from msvc in date.c for value truncation from 64\nbit to 32 bit integers.\n\nAlso switch from int to size_t for all variables with result of strlen()\nwhich cannot become negative.\n\nSigned-off-by: Sören Krecker <soekkle@freenet.de>\n---\n date.c | 8 ++++----\n 1 file changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/date.c b/date.c\nindex a1b26a8dce..0a3fafc8a4 100644\n--- a/date.c\n+++ b/date.c\n@@ -1244,7 +1244,7 @@ static const char *approxidate_alpha(const char *date, struct tm *tm, struct tm\n \t}\n \n \tfor (s = special; s->name; s++) {\n-\t\tint len = strlen(s->name);\n+\t\tsize_t len = strlen(s->name);\n \t\tif (match_string(date, s->name) == len) {\n \t\t\ts->fn(tm, now, num);\n \t\t\t*touched = 1;\n@@ -1254,7 +1254,7 @@ static const char *approxidate_alpha(const char *date, struct tm *tm, struct tm\n \n \tif (!*num) {\n \t\tfor (i = 1; i < 11; i++) {\n-\t\t\tint len = strlen(number_name[i]);\n+\t\t\tsize_t len = strlen(number_name[i]);\n \t\t\tif (match_string(date, number_name[i]) == len) {\n \t\t\t\t*num = i;\n \t\t\t\t*touched = 1;\n@@ -1270,8 +1270,8 @@ static const char *approxidate_alpha(const char *date, struct tm *tm, struct tm\n \n \ttl = typelen;\n \twhile (tl->type) {\n-\t\tint len = strlen(tl->type);\n-\t\tif (match_string(date, tl->type) >= len-1) {\n+\t\tsize_t len = strlen(tl->type);\n+\t\tif (match_string(date, tl->type)+1 >= len) {\n \t\t\tupdate_tm(tm, now, tl->length * *num);\n \t\t\t*num = 0;\n \t\t\t*touched = 1;\n-- \n2.39.5\n\n"},{"id":"511222","messageId":"Z5c1F7oqsaPrHRiT@pks.im","threadId":"62855","inReplyTo":"20250126125850.3195-1-soekkle@freenet.de","subject":"Re: [PATCH v3 2/4] date.c: Fix type conversation warnings from msvc","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2025-01-27T07:26:15Z","receivedAt":"2025-01-27T07:26:19Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Sun, Jan 26, 2025 at 01:58:50PM +0100, Sören Krecker wrote:\n> Fix compiler warnings from msvc in date.c for value truncation from 64\n> bit to 32 bit integers.\n> \n> Also switch from int to size_t for all variables with result of strlen()\n> which cannot become negative.\n\nAs far as I can see this patch only does the latter and doesn't do the\nformer, so the commit message seems inaccurate to me.\n\n> diff --git a/date.c b/date.c\n> index a1b26a8dce..0a3fafc8a4 100644\n> --- a/date.c\n> +++ b/date.c\n> @@ -1270,8 +1270,8 @@ static const char *approxidate_alpha(const char *date, struct tm *tm, struct tm\n>  \n>  \ttl = typelen;\n>  \twhile (tl->type) {\n> -\t\tint len = strlen(tl->type);\n> -\t\tif (match_string(date, tl->type) >= len-1) {\n> +\t\tsize_t len = strlen(tl->type);\n> +\t\tif (match_string(date, tl->type)+1 >= len) {\n\nFormatting is off here, there should be spaces around `+`, even though\nyou simply followed previous style. It would be nice to point out why\nthis change is makde in the commit message.\n\nPatrick\n"},{"id":"511278","messageId":"xmqqwmegutbe.fsf@gitster.g","threadId":"62855","inReplyTo":"Z5c1F7oqsaPrHRiT@pks.im","subject":"Re: [PATCH v3 2/4] date.c: Fix type conversation warnings from msvc","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-01-27T16:15:17Z","receivedAt":"2025-01-27T16:15:20Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n>> diff --git a/date.c b/date.c\n>> index a1b26a8dce..0a3fafc8a4 100644\n>> --- a/date.c\n>> +++ b/date.c\n>> @@ -1270,8 +1270,8 @@ static const char *approxidate_alpha(const char *date, struct tm *tm, struct tm\n>>  \n>>  \ttl = typelen;\n>>  \twhile (tl->type) {\n>> -\t\tint len = strlen(tl->type);\n>> -\t\tif (match_string(date, tl->type) >= len-1) {\n>> +\t\tsize_t len = strlen(tl->type);\n>> +\t\tif (match_string(date, tl->type)+1 >= len) {\n>\n> Formatting is off here, there should be spaces around `+`, even though\n> you simply followed previous style. It would be nice to point out why\n> this change is makde in the commit message.\n\nI think len-1 here is perfectly fine, as there is no element in\ntypelen[] whose .type member is an empty string, and no need to\ntouch that.\n\nBesides, we already have this one in 'next'.\n\nThanks.\n\n"},{"id":"511351","messageId":"Z5iZQ3-egivQOcJp@pks.im","threadId":"62855","inReplyTo":"xmqqwmegutbe.fsf@gitster.g","subject":"Re: [PATCH v3 2/4] date.c: Fix type conversation warnings from msvc","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2025-01-28T08:45:55Z","receivedAt":"2025-01-28T08:46:00Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Mon, Jan 27, 2025 at 08:15:17AM -0800, Junio C Hamano wrote:\n> Patrick Steinhardt <ps@pks.im> writes:\n> \n> >> diff --git a/date.c b/date.c\n> >> index a1b26a8dce..0a3fafc8a4 100644\n> >> --- a/date.c\n> >> +++ b/date.c\n> >> @@ -1270,8 +1270,8 @@ static const char *approxidate_alpha(const char *date, struct tm *tm, struct tm\n> >>  \n> >>  \ttl = typelen;\n> >>  \twhile (tl->type) {\n> >> -\t\tint len = strlen(tl->type);\n> >> -\t\tif (match_string(date, tl->type) >= len-1) {\n> >> +\t\tsize_t len = strlen(tl->type);\n> >> +\t\tif (match_string(date, tl->type)+1 >= len) {\n> >\n> > Formatting is off here, there should be spaces around `+`, even though\n> > you simply followed previous style. It would be nice to point out why\n> > this change is makde in the commit message.\n> \n> I think len-1 here is perfectly fine, as there is no element in\n> typelen[] whose .type member is an empty string, and no need to\n> touch that.\n> \n> Besides, we already have this one in 'next'.\n\nHuh, do we? Oh, indeed. I guess this patch should then be dropped from\nfuture rerolls of this patch series, shouldn't it?\n\nPatrick\n"}]}