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

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).