git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 2/4] date.c: Fix type conversation warnings from msvc
@ 2025-01-26 12:58 Sören Krecker
  2025-01-27  7:26 ` Patrick Steinhardt
  0 siblings, 1 reply; 4+ messages in thread
From: Sören Krecker @ 2025-01-26 12:58 UTC (permalink / raw)
  To: git; +Cc: gitster, phillip.wood123, ps, sunshine, Sören Krecker

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.

Signed-off-by: Sören Krecker <soekkle@freenet.de>
---
 date.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/date.c b/date.c
index a1b26a8dce..0a3fafc8a4 100644
--- a/date.c
+++ b/date.c
@@ -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 tm
 
 	if (!*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;
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v3 2/4] date.c: Fix type conversation warnings from msvc
  2025-01-26 12:58 [PATCH v3 2/4] date.c: Fix type conversation warnings from msvc Sören Krecker
@ 2025-01-27  7:26 ` Patrick Steinhardt
  2025-01-27 16:15   ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Patrick Steinhardt @ 2025-01-27  7:26 UTC (permalink / raw)
  To: 20250126125638.3089-1-soekkle
  Cc: git, gitster, phillip.wood123, sunshine, Sören Krecker

On Sun, Jan 26, 2025 at 01:58:50PM +0100, Sören Krecker wrote:
> 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.

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.

> diff --git a/date.c b/date.c
> index a1b26a8dce..0a3fafc8a4 100644
> --- a/date.c
> +++ b/date.c
> @@ -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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v3 2/4] date.c: Fix type conversation warnings from msvc
  2025-01-27  7:26 ` Patrick Steinhardt
@ 2025-01-27 16:15   ` Junio C Hamano
  2025-01-28  8:45     ` Patrick Steinhardt
  0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2025-01-27 16:15 UTC (permalink / raw)
  To: Patrick Steinhardt
  Cc: 20250126125638.3089-1-soekkle, git, phillip.wood123, sunshine,
	Sören Krecker

Patrick Steinhardt <ps@pks.im> writes:

>> diff --git a/date.c b/date.c
>> index a1b26a8dce..0a3fafc8a4 100644
>> --- a/date.c
>> +++ b/date.c
>> @@ -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.

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.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v3 2/4] date.c: Fix type conversation warnings from msvc
  2025-01-27 16:15   ` Junio C Hamano
@ 2025-01-28  8:45     ` Patrick Steinhardt
  0 siblings, 0 replies; 4+ messages in thread
From: Patrick Steinhardt @ 2025-01-28  8:45 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: 20250126125638.3089-1-soekkle, git, phillip.wood123, sunshine,
	Sören Krecker

On Mon, Jan 27, 2025 at 08:15:17AM -0800, Junio C Hamano wrote:
> Patrick Steinhardt <ps@pks.im> writes:
> 
> >> diff --git a/date.c b/date.c
> >> index a1b26a8dce..0a3fafc8a4 100644
> >> --- a/date.c
> >> +++ b/date.c
> >> @@ -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.
> 
> 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-01-28  8:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-26 12:58 [PATCH v3 2/4] date.c: Fix type conversation warnings from msvc Sören Krecker
2025-01-27  7:26 ` Patrick Steinhardt
2025-01-27 16:15   ` Junio C Hamano
2025-01-28  8:45     ` Patrick Steinhardt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).