date.c: Fix type conversation warnings from msvc
PATCH v3 2/4 date.c: Fix type conversation warnings from msvc
Fix compiler warnings from msvc in date.c for value truncation from 64 bit to 32 bit integers.
Also switch from int to size_t for all variables with result of strlen() which cannot become negative.
--- date.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
date.c +4 -4
@@ -1244,7 +1244,7 @@ static const char *approxidate_alpha(const char *date, struct tm *tm, struct tm }for (s = special; s->name; s++) { -int len =strlen (s->name); +size_t len =strlen (s->name);if (match_string (date, s->name) == len) { s->fn (tm, now, num); *touched =1 ;
@@ -1254,7 +1254,7 @@ static const char *approxidate_alpha(const char *date, struct tm *tm, struct tmif (!*num) {for (i =1 ; i <11 ; i++) { -int len =strlen (number_name[i]); +size_t len =strlen (number_name[i]);if (match_string (date, number_name[i]) == len) { *num = i; *touched =1 ;
@@ -1270,8 +1270,8 @@ static const char *approxidate_alpha(const char *date, struct tm *tm, struct tm tl = typelen;while (tl->type) { -int len =strlen (tl->type); -if (match_string (date, tl->type) >= len-1 ) { +size_t len =strlen (tl->type); +if (match_string (date, tl->type)+1 >= len) {update_tm (tm, now, tl->length * *num); *num =0 ; *touched =1 ;
Signature · 1 line
2.39.5
Quoted 5 lines · Sören Krecker
Fix compiler warnings from msvc in
date.cfor value truncation from 64 bit to 32 bit integers.Also switch from int to
size_tfor all variables with result ofstrlen()which cannot become negative.
As far as I can see this patch only does the latter and doesn't do the former, so the commit message seems inaccurate to me.
date.c static const char *approxidate_alpha(const char *date, struct tm *tm, struct tm · line 1274
Quoted 12 lines
date.c +2
-2@@ -1270,8 +1270,8 @@ static const char *approxidate_alpha(const char *date, struct tm *tm, struct tm tl = typelen;while (tl->type) { -int len =strlen (tl->type); -if (match_string (date, tl->type) >= len-1 ) { +size_t len =strlen (tl->type); +if (match_string (date, tl->type)+1 >= len) {
Formatting is off here, there should be spaces around +, even though you simply followed previous style. It would be nice to point out why this change is makde in the commit message.
Patrick
Quoted 6 lines · Patrick Steinhardt
Quoted 6 lines
date.c +0
-0@@ -1270,8 +1270,8 @@ static const char *approxidate_alpha(const char *date, struct tm *tm, struct tm
Quoted 10 lines
date.c static const char *approxidate_alpha(const char *date, struct tm *tm, struct tm · line 1274
Quoted 6 lines
date.c +2
-2tl = typelen;while (tl->type) { -int len =strlen (tl->type); -if (match_string (date, tl->type) >= len-1 ) { +size_t len =strlen (tl->type); +if (match_string (date, tl->type)+1 >= len) {Formatting is off here, there should be spaces around
+, even though you simply followed previous style. It would be nice to point out why this change is makde in the commit message.
I think len-1 here is perfectly fine, as there is no element in typelen[] whose .type member is an empty string, and no need to touch that.
Besides, we already have this one in 'next'.
Thanks.
Quoted 19 lines · Junio C Hamano
Quoted 6 lines · Patrick Steinhardt
Quoted 6 lines
date.c +0
-0@@ -1270,8 +1270,8 @@ static const char *approxidate_alpha(const char *date, struct tm *tm, struct tmQuoted 10 lines
date.c static const char *approxidate_alpha(const char *date, struct tm *tm, struct tm · line 1274
Quoted 6 lines
date.c +2
-2tl = typelen;while (tl->type) { -int len =strlen (tl->type); -if (match_string (date, tl->type) >= len-1 ) { +size_t len =strlen (tl->type); +if (match_string (date, tl->type)+1 >= len) {Formatting is off here, there should be spaces around
+, even though you simply followed previous style. It would be nice to point out why this change is makde in the commit message.
Quoted 5 lines
I think len-1 here is perfectly fine, as there is no element in typelen[] whose .type member is an empty string, and no need to touch that.
Besides, we already have this one in 'next'.
Huh, do we? Oh, indeed. I guess this patch should then be dropped from future rerolls of this patch series, shouldn't it?
Patrick