From patchwork Mon Jan 6 19:08:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?S=C3=B6ren_Krecker?= X-Patchwork-Id: 13927758 Received: from mout3.freenet.de (mout3.freenet.de [195.4.92.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1FB681DF244 for ; Mon, 6 Jan 2025 19:14:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.4.92.93 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736190887; cv=none; b=jikm95oE4dA5UrIrBf9eFpTfnTpgEQlF1h8AQePJFSyM7GTzR45f9M99uq2bggRN5jamMfy9LPks0KIz/UvK7/tpxloMy98oF5z+CY8waLP2YLpUU4Jc3aiNqiKCK8R/c5mioTej72UlY77gL1W1aR4N8Lt2p7kD74repdiBaKI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736190887; c=relaxed/simple; bh=D1vs9+R/dwP5lC4I8kKXXTYBZauu0GBNIsBXT7kgpSA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=pv5yMWBd6ZlUgynpmg1kA0w3/n68lwky2sTIS8Im3XlKn5PxV6A5RmkoaDn3ZpF2gaWZSaVCAnLadL4HzIrBkK2f2vsXJpiqcNXjgg33Te+pe332M+dxNuIp2Pxqu4lWGdh7OLB2sHAngE1tctssRAS+CKZdbZ3VI38QS3xpu/8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=freenet.de; spf=pass smtp.mailfrom=freenet.de; dkim=pass (2048-bit key) header.d=freenet.de header.i=@freenet.de header.b=q/73I+/y; arc=none smtp.client-ip=195.4.92.93 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=freenet.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=freenet.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=freenet.de header.i=@freenet.de header.b="q/73I+/y" Received: from [195.4.92.126] (helo=sub7.freenet.de) by mout3.freenet.de with esmtpa (ID soekkle@freenet.de) (port 25) (Exim 4.94.2 #2) id 1tUsTc-003JGo-W3; Mon, 06 Jan 2025 20:09:24 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=freenet.de; s=mjaymdexmjqk; h=Content-Transfer-Encoding:Content-Type:MIME-Version: Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=bCs8PDXtCYzvJUSezVTcGg/6LZNUJ9tgAe+ytGp4tm4=; b=q/73I+/ygVQhw0EmxWlaiFWREi RnNtizBVEWXjU11amwbI7ztcv6bdB6ZH9NuaUjZP5TXujZkcq7DNix9B9v4hQq5uhauicNEAtvHHH AjCfJapmhOQ3biFAw2BgM9jQ7TYbopVXD0tCNjnzLkuTLcmIA2lAjqgF5U220acBvrEV+eFkVfx35 WxJ6bxGsFUnTGGDy8zpaWOG0FW/fmSb3C4sQrvkHf0jgctk9HcIH3QIVibdQOumB+V7q/nOv8+zHr Ojn3W1UmCjuAQK79rxkDQBbAeMNpUNHlkqRXHNrFX8dhAk/yI9wGOKYKU3OTyT8FUGvRNdFvyqdRK VSSNycVQ==; Received: from p200300e2e705fb00dacb8afffee0ca63.dip0.t-ipconnect.de ([2003:e2:e705:fb00:dacb:8aff:fee0:ca63]:46380 helo=soren-pc.lan) by sub7.freenet.de with esmtpsa (ID soekkle@freenet.de) (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (port 465) (Exim 4.94.2 #2) id 1tUsTc-00Brik-Km; Mon, 06 Jan 2025 20:09:24 +0100 From: =?utf-8?q?S=C3=B6ren_Krecker?= To: git@vger.kernel.org Cc: gitster@pobox.com, phillip.wood123@gmail.com, ps@pks.im, =?utf-8?q?S?= =?utf-8?q?=C3=B6ren_Krecker?= Subject: [PATCHv2 1/4] add-patch: Fix type missmatch rom msvc Date: Mon, 6 Jan 2025 20:08:52 +0100 Message-Id: <20250106190855.3098-2-soekkle@freenet.de> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250106190855.3098-1-soekkle@freenet.de> References: <20250106190855.3098-1-soekkle@freenet.de> Reply-To: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-FN-MUUID: 1736190564B0D8969A13E6O X-Originated-At: 2003:e2:e705:fb00:dacb:8aff:fee0:ca63!46380 X-Scan-TS: Mon, 06 Jan 2025 20:09:24 +0100 Fix some compiler warings from msvw in add-patch.c for value truncation form 64 bit to 32 bit integers.Change unsigned long to size_t for correct variable size on linux and windows. Add macro strtos for converting a string to size_t. Test if convertion fails with over or underflow. Signed-off-by: Sören Krecker Uses strtouq impove linux support Change Macro name --- add-patch.c | 53 +++++++++++++++++++++++++++-------------------- gettext.h | 2 +- git-compat-util.h | 6 ++++++ 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/add-patch.c b/add-patch.c index 7b598e14df..67a7f68d23 100644 --- a/add-patch.c +++ b/add-patch.c @@ -242,7 +242,7 @@ static struct patch_mode patch_mode_worktree_nothead = { }; struct hunk_header { - unsigned long old_offset, old_count, new_offset, new_count; + size_t old_offset, old_count, new_offset, new_count; /* * Start/end offsets to the extra text after the second `@@` in the * hunk header, e.g. the function signature. This is expected to @@ -322,11 +322,12 @@ static void setup_child_process(struct add_p_state *s, } static int parse_range(const char **p, - unsigned long *offset, unsigned long *count) + size_t *offset, size_t *count) { char *pend; - - *offset = strtoul(*p, &pend, 10); + *offset = strtos(*p, &pend, 10); + if (errno == ERANGE) + return error("Number dose not fit datatype"); if (pend == *p) return -1; if (*pend != ',') { @@ -334,7 +335,9 @@ static int parse_range(const char **p, *p = pend; return 0; } - *count = strtoul(pend + 1, (char **)p, 10); + *count = strtos(pend + 1, (char **)p, 10); + if (errno == ERANGE) + return error("Number dose not fit datatype"); return *p == pend + 1 ? -1 : 0; } @@ -673,8 +676,8 @@ static void render_hunk(struct add_p_state *s, struct hunk *hunk, */ const char *p; size_t len; - unsigned long old_offset = header->old_offset; - unsigned long new_offset = header->new_offset; + size_t old_offset = header->old_offset; + size_t new_offset = header->new_offset; if (!colored) { p = s->plain.buf + header->extra_start; @@ -700,12 +703,14 @@ static void render_hunk(struct add_p_state *s, struct hunk *hunk, else new_offset += delta; - strbuf_addf(out, "@@ -%lu", old_offset); + strbuf_addf(out, "@@ -%" PRIuMAX, (uintmax_t)old_offset); if (header->old_count != 1) - strbuf_addf(out, ",%lu", header->old_count); - strbuf_addf(out, " +%lu", new_offset); + strbuf_addf(out, ",%" PRIuMAX, + (uintmax_t)header->old_count); + strbuf_addf(out, " +%" PRIuMAX, (uintmax_t)new_offset); if (header->new_count != 1) - strbuf_addf(out, ",%lu", header->new_count); + strbuf_addf(out, ",%" PRIuMAX, + (uintmax_t)header->new_count); strbuf_addstr(out, " @@"); if (len) @@ -1066,11 +1071,13 @@ static int split_hunk(struct add_p_state *s, struct file_diff *file_diff, /* last hunk simply gets the rest */ if (header->old_offset != remaining.old_offset) - BUG("miscounted old_offset: %lu != %lu", - header->old_offset, remaining.old_offset); + BUG("miscounted old_offset: %"PRIuMAX" != %"PRIuMAX, + (uintmax_t)header->old_offset, + (uintmax_t)remaining.old_offset); if (header->new_offset != remaining.new_offset) - BUG("miscounted new_offset: %lu != %lu", - header->new_offset, remaining.new_offset); + BUG("miscounted new_offset: %"PRIuMAX" != %"PRIuMAX, + (uintmax_t)header->new_offset, + (uintmax_t)remaining.new_offset); header->old_count = remaining.old_count; header->new_count = remaining.new_count; hunk->end = end; @@ -1354,9 +1361,10 @@ static void summarize_hunk(struct add_p_state *s, struct hunk *hunk, struct strbuf *plain = &s->plain; size_t len = out->len, i; - strbuf_addf(out, " -%lu,%lu +%lu,%lu ", - header->old_offset, header->old_count, - header->new_offset, header->new_count); + strbuf_addf(out, + " -%"PRIuMAX",%"PRIuMAX" +%"PRIuMAX",%"PRIuMAX" ", + (uintmax_t)header->old_offset, (uintmax_t)header->old_count, + (uintmax_t)header->new_offset, (uintmax_t)header->new_count); if (out->len - len < SUMMARY_HEADER_WIDTH) strbuf_addchars(out, ' ', SUMMARY_HEADER_WIDTH + len - out->len); @@ -1625,10 +1633,11 @@ static int patch_update_file(struct add_p_state *s, else if (0 < response && response <= file_diff->hunk_nr) hunk_index = response - 1; else - err(s, Q_("Sorry, only %d hunk available.", - "Sorry, only %d hunks available.", - file_diff->hunk_nr), - (int)file_diff->hunk_nr); + err(s, + Q_("Sorry, only %"PRIuMAX" hunk available.", + "Sorry, only %"PRIuMAX" hunks available.", + (uintmax_t)file_diff->hunk_nr), + (uintmax_t)file_diff->hunk_nr); } else if (s->answer.buf[0] == '/') { regex_t regex; int ret; diff --git a/gettext.h b/gettext.h index 484cafa562..d36f5a7ade 100644 --- a/gettext.h +++ b/gettext.h @@ -53,7 +53,7 @@ static inline FORMAT_PRESERVING(1) const char *_(const char *msgid) } static inline FORMAT_PRESERVING(1) FORMAT_PRESERVING(2) -const char *Q_(const char *msgid, const char *plu, unsigned long n) +const char *Q_(const char *msgid, const char *plu, size_t n) { if (!git_gettext_enabled) return n == 1 ? msgid : plu; diff --git a/git-compat-util.h b/git-compat-util.h index e283c46c6f..4c33990a05 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -291,6 +291,12 @@ static inline int _have_unix_sockets(void) #ifdef HAVE_BSD_SYSCTL #include #endif +#if defined _WIN64 +# define strtos strtoull +#else +#define strtos strtoul +#endif + /* Used by compat/win32/path-utils.h, and more */ static inline int is_xplatform_dir_sep(int c) From patchwork Mon Jan 6 19:08:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?S=C3=B6ren_Krecker?= X-Patchwork-Id: 13927756 Received: from mout3.freenet.de (mout3.freenet.de [195.4.92.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E2E981DED58 for ; Mon, 6 Jan 2025 19:14:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.4.92.93 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736190884; cv=none; b=KvpObzqEBV5gkWxlbq3FHxIuRjO40vItb648c6+zUZ5UuFMt8AVnXItyJDzYQ6OpgGWNxkZ21LGbB4HRFURQftAoUjpPvKhnGEnD3txv07W84L8NnuN6FYrV4PeAaKjzZ8gfuhAXCN9YFoMNS8tUL69pjdbu6bLLbj2iYLQlFf0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736190884; c=relaxed/simple; bh=Q7/s3knV1iPBIaqsacFXfftdYGSrphdiQFTIQ1Sxu7I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=PkrH4ZNuaFkvcxj6WjlZqS4/Mp7Wqtx/p7NGfcSS/JneyPOaXkPk52bP51r0ILrro2qnREhr8raF9gPFUKwX6x6RFIrgrtHskzFmkMkSudiqKXMfgIvS1C+tb1i4ebd1WWDZOx/EymqPM9hi2nw35eUHRXLZSWAu2oa07uukZYs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=freenet.de; spf=pass smtp.mailfrom=freenet.de; dkim=pass (2048-bit key) header.d=freenet.de header.i=@freenet.de header.b=hHBY8UoZ; arc=none smtp.client-ip=195.4.92.93 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=freenet.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=freenet.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=freenet.de header.i=@freenet.de header.b="hHBY8UoZ" Received: from [195.4.92.126] (helo=sub7.freenet.de) by mout3.freenet.de with esmtpa (ID soekkle@freenet.de) (port 25) (Exim 4.94.2 #2) id 1tUsTd-003JHA-4Z; Mon, 06 Jan 2025 20:09:25 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=freenet.de; s=mjaymdexmjqk; h=Content-Transfer-Encoding:Content-Type:MIME-Version: Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=unC5M9H6fSQmOq4y3fWMF7t0vqeeXbk15rlW2JsZ6c4=; b=hHBY8UoZ3JGuhBhxpLRgjp091q WiTYIntGysViNvBnxOFdgUNet8rrUuyBN2kqa0iCIxd7IoQT6y+jzAoBc3y2SV8FWh7pEen2InZ49 EmfxYaAkiYmE2enJYiEbYCwNlp25plv4hnp0vaq7Jo/qvuuB0sfjLD5v0KsQGX26QRnB5P/ZAGEtU efaLM9Erf4tYbaCWM/oTDt4lxwaBC1ZyIKgjrU8EetZsxb2QaRHqzmLbUc9eJ5grb/zAsY88pbr3Q 2JRhreKcylF3fV9/DjHGLWEO6mVmOwQu1bs/+KDm5Eme/ahZHR2/i5Le4wm9AcyzEt+URaD6LG/gj 4F9jqeTg==; Received: from p200300e2e705fb00dacb8afffee0ca63.dip0.t-ipconnect.de ([2003:e2:e705:fb00:dacb:8aff:fee0:ca63]:46380 helo=soren-pc.lan) by sub7.freenet.de with esmtpsa (ID soekkle@freenet.de) (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (port 465) (Exim 4.94.2 #2) id 1tUsTc-00Brik-RI; Mon, 06 Jan 2025 20:09:24 +0100 From: =?utf-8?q?S=C3=B6ren_Krecker?= To: git@vger.kernel.org Cc: gitster@pobox.com, phillip.wood123@gmail.com, ps@pks.im, =?utf-8?q?S?= =?utf-8?q?=C3=B6ren_Krecker?= Subject: [PATCHv2 2/4] date.c: Fix type missmatch warings from msvc Date: Mon, 6 Jan 2025 20:08:53 +0100 Message-Id: <20250106190855.3098-3-soekkle@freenet.de> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250106190855.3098-1-soekkle@freenet.de> References: <20250106190855.3098-1-soekkle@freenet.de> Reply-To: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-FN-MUUID: 1736190564167A1567EA1FO X-Originated-At: 2003:e2:e705:fb00:dacb:8aff:fee0:ca63!46380 X-Scan-TS: Mon, 06 Jan 2025 20:09:24 +0100 Fix compiler warings 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 --- date.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/date.c b/date.c index a1b26a8dce..17a95077cf 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,7 +1270,7 @@ static const char *approxidate_alpha(const char *date, struct tm *tm, struct tm tl = typelen; while (tl->type) { - int len = strlen(tl->type); + size_t len = strlen(tl->type); if (match_string(date, tl->type) >= len-1) { update_tm(tm, now, tl->length * *num); *num = 0; From patchwork Mon Jan 6 19:08:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?S=C3=B6ren_Krecker?= X-Patchwork-Id: 13927760 Received: from mout3.freenet.de (mout3.freenet.de [195.4.92.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 550F41DFD86 for ; Mon, 6 Jan 2025 19:14:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.4.92.93 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736190892; cv=none; b=Gme1IybTpLqvEeAzePpcVwEZMTmCnKQHR8jfTc/pe3J3rzi5QGIbKAOe0H3Pj0Lcl33XXDImKG89bd8bXvxV5PlkmzlopeDN9ycWbVk+WE6sRxj8PdUULOTnqk57OpfTOhbhA3rGCkW7uS9lO1nu7mZU7RTg91mXHgJTYWTC5n0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736190892; c=relaxed/simple; bh=Op9hqSTZZikKovPTRcylU82Ok8bO56jXbjMCDlBsbGY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=E6BwFMm+K3+uVRAGJtS4PysDDekKwgmp2Z5cFiktkrq1MlhRlOsIdvekI3+6s8DL4dInaK5CR09eG5nKHeKeTkBIrfyL0eSrCKuRDQaHIoxz7GrCyVgBrXSkHDjUmBuO3cKpBM7Bgk25h1SOuKUT2/h7zDBU68UNMcaiM+qvVWE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=freenet.de; spf=pass smtp.mailfrom=freenet.de; dkim=pass (2048-bit key) header.d=freenet.de header.i=@freenet.de header.b=ZfpOskYB; arc=none smtp.client-ip=195.4.92.93 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=freenet.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=freenet.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=freenet.de header.i=@freenet.de header.b="ZfpOskYB" Received: from [195.4.92.126] (helo=sub7.freenet.de) by mout3.freenet.de with esmtpa (ID soekkle@freenet.de) (port 25) (Exim 4.94.2 #2) id 1tUsTd-003JHf-C3; Mon, 06 Jan 2025 20:09:25 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=freenet.de; s=mjaymdexmjqk; h=Content-Transfer-Encoding:Content-Type:MIME-Version: Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=lPCNFJZgW0FH+3kf9a/EannA1s4Ditf/MyuSqODLip8=; b=ZfpOskYB1lsX8v3Xz9yecxI/SX KcqT/v0ixD8/6mFeNStSK+K0XjIbgKijVQtsESgha2NPr5bsdnpHlI7PFu6S3BMle7HF1rsSEMLTs G11UUr8t3fbfY2zrzH4FaiV/Cox577w77Su4UUdVSEF53Pla3XwfxpUtl2UtPK5LkJcDS9hKmr2oo j0G5iD6TjnWPGQO/ChTy9xzrv4nu1eTAUeQv9XiPZVV0IoNrzAXaBNZRyR3EV7JeE6FW2ATkvUFGB CJePco/NOcDLueXtXBIy4ZgfsbmNep9t0LtcfqkBcXAVbRe1ehjKzf1BA3X+5eWGqoaubVwk052Ow 2RbET9hw==; Received: from p200300e2e705fb00dacb8afffee0ca63.dip0.t-ipconnect.de ([2003:e2:e705:fb00:dacb:8aff:fee0:ca63]:46380 helo=soren-pc.lan) by sub7.freenet.de with esmtpsa (ID soekkle@freenet.de) (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (port 465) (Exim 4.94.2 #2) id 1tUsTd-00Brik-0r; Mon, 06 Jan 2025 20:09:25 +0100 From: =?utf-8?q?S=C3=B6ren_Krecker?= To: git@vger.kernel.org Cc: gitster@pobox.com, phillip.wood123@gmail.com, ps@pks.im, =?utf-8?q?S?= =?utf-8?q?=C3=B6ren_Krecker?= Subject: [PATCHv2 3/4] apply.c : Fix type missmatch warings from msvc Date: Mon, 6 Jan 2025 20:08:54 +0100 Message-Id: <20250106190855.3098-4-soekkle@freenet.de> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250106190855.3098-1-soekkle@freenet.de> References: <20250106190855.3098-1-soekkle@freenet.de> Reply-To: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-FN-MUUID: 1736190565C92DEE465CE7O X-Originated-At: 2003:e2:e705:fb00:dacb:8aff:fee0:ca63!46380 X-Scan-TS: Mon, 06 Jan 2025 20:09:25 +0100 Fix compiler warings 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 --- apply.c | 37 +++++++++++++++++++------------------ apply.h | 6 +++--- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/apply.c b/apply.c index 4a7b6120ac..b896889505 100644 --- a/apply.c +++ b/apply.c @@ -414,9 +414,9 @@ static int read_patch_file(struct strbuf *sb, int fd) return 0; } -static unsigned long linelen(const char *buffer, unsigned long size) +static size_t linelen(const char *buffer, size_t size) { - unsigned long len = 0; + size_t len = 0; while (size--) { len++; if (*buffer++ == '\n') @@ -688,7 +688,7 @@ static char *find_name_common(struct strbuf *root, * or "file~"). */ if (def) { - int deflen = strlen(def); + size_t deflen = strlen(def); if (deflen < len && !strncmp(start, def, deflen)) return squash_slash(xstrdup(def)); } @@ -1088,7 +1088,7 @@ static int gitdiff_index(struct gitdiff_data *state, */ const char *ptr, *eol; int len; - const unsigned hexsz = the_hash_algo->hexsz; + const size_t hexsz = the_hash_algo->hexsz; ptr = strchr(line, '.'); if (!ptr || ptr[1] != '.' || hexsz < ptr - line) @@ -1131,7 +1131,7 @@ static int gitdiff_unrecognized(struct gitdiff_data *state UNUSED, */ static const char *skip_tree_prefix(int p_value, const char *line, - int llen) + size_t llen) { int nslash; int i; @@ -1158,7 +1158,7 @@ static const char *skip_tree_prefix(int p_value, */ static char *git_header_name(int p_value, const char *line, - int llen) + ssize_t llen) { const char *name; const char *second = NULL; @@ -1313,15 +1313,15 @@ static int check_header_line(int linenr, struct patch *patch) return 0; } -int parse_git_diff_header(struct strbuf *root, +size_t parse_git_diff_header(struct strbuf *root, int *linenr, int p_value, const char *line, - int len, - unsigned int size, + size_t len, + size_t size, struct patch *patch) { - unsigned long offset; + size_t offset; struct gitdiff_data parse_hdr_state; /* A git diff has explicit new/delete information, so we don't guess */ @@ -1378,7 +1378,7 @@ int parse_git_diff_header(struct strbuf *root, break; for (i = 0; i < ARRAY_SIZE(optable); i++) { const struct opentry *p = optable + i; - int oplen = strlen(p->str); + size_t oplen = strlen(p->str); int res; if (len < oplen || memcmp(p->str, line, oplen)) continue; @@ -1430,7 +1430,8 @@ static int parse_num(const char *line, unsigned long *p) static int parse_range(const char *line, int len, int offset, const char *expect, unsigned long *p1, unsigned long *p2) { - int digits, ex; + int digits; + size_t ex; if (offset < 0 || offset >= len) return -1; @@ -1465,7 +1466,7 @@ static int parse_range(const char *line, int len, int offset, const char *expect return offset + ex; } -static void recount_diff(const char *line, int size, struct fragment *fragment) +static void recount_diff(const char *line, size_t size, struct fragment *fragment) { int oldlines = 0, newlines = 0, ret = 0; @@ -1475,7 +1476,7 @@ static void recount_diff(const char *line, int size, struct fragment *fragment) } for (;;) { - int len = linelen(line, size); + size_t len = linelen(line, size); size -= len; line += len; @@ -1543,11 +1544,11 @@ static int parse_fragment_header(const char *line, int len, struct fragment *fra */ static int find_header(struct apply_state *state, const char *line, - unsigned long size, + size_t size, int *hdrsize, struct patch *patch) { - unsigned long offset, len; + size_t offset, len; patch->is_toplevel_relative = 0; patch->is_rename = patch->is_copy = 0; @@ -2132,7 +2133,7 @@ static int use_patch(struct apply_state *state, struct patch *p) * the number of bytes consumed otherwise, * so that the caller can call us again for the next patch. */ -static int parse_chunk(struct apply_state *state, char *buffer, unsigned long size, struct patch *patch) +static int parse_chunk(struct apply_state *state, char *buffer, size_t size, struct patch *patch) { int hdrsize, patchsize; int offset = find_header(state, buffer, size, &hdrsize, patch); @@ -2491,7 +2492,7 @@ static int match_fragment(struct apply_state *state, struct strbuf fixed = STRBUF_INIT; char *fixed_buf; size_t fixed_len; - int preimage_limit; + ssize_t preimage_limit; int ret; if (preimage->line_nr + current_lno <= img->line_nr) { diff --git a/apply.h b/apply.h index 90e887ec0e..bb01ce7dbc 100644 --- a/apply.h +++ b/apply.h @@ -166,12 +166,12 @@ int check_apply_state(struct apply_state *state, int force_apply); * * Returns -1 on failure, the length of the parsed header otherwise. */ -int parse_git_diff_header(struct strbuf *root, +size_t parse_git_diff_header(struct strbuf *root, int *linenr, int p_value, const char *line, - int len, - unsigned int size, + size_t len, + size_t size, struct patch *patch); void release_patch(struct patch *patch); From patchwork Mon Jan 6 19:08:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?S=C3=B6ren_Krecker?= X-Patchwork-Id: 13927759 Received: from mout3.freenet.de (mout3.freenet.de [195.4.92.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 820FE1DFD85 for ; Mon, 6 Jan 2025 19:14:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.4.92.93 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736190888; cv=none; b=g/9YpskqlKm+pMNujBerKqtXTRagMs0LQjEgA1T9W7mQIZN+NFC3IVx8CDzHksHO8zs8dbM+QzX3/9CATBu5VtSLotJWURXhXekpA+A70WVr1JzPxLzALL0NM4mZznvANkpPU1AYHWntyxz+9vToID117Ne8VSnknY5jhkmyPiY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736190888; c=relaxed/simple; bh=8PAa18Y3Q3NKMjaPLVW7AQbssy0YRo6cbZVKtXBFIFA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=eueJbiEdOUnwmJuru/wVXU9zjNbRjGq816ylkkto+GFgy+nXai6Q4DYtTx5NrM9KFcw77EaoGioEEyUmYN9Ti8hBM6GlbCFuRgm4tjKd9p50xMaMz2F8Agh+HKx38PHopr+V1YQ2AuxnRuVi2vmQTWHux1OUy9nVEtUChY14qEI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=freenet.de; spf=pass smtp.mailfrom=freenet.de; dkim=pass (2048-bit key) header.d=freenet.de header.i=@freenet.de header.b=PGySRvbV; arc=none smtp.client-ip=195.4.92.93 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=freenet.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=freenet.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=freenet.de header.i=@freenet.de header.b="PGySRvbV" Received: from [195.4.92.126] (helo=sub7.freenet.de) by mout3.freenet.de with esmtpa (ID soekkle@freenet.de) (port 25) (Exim 4.94.2 #2) id 1tUsTd-003JI2-Hs; Mon, 06 Jan 2025 20:09:25 +0100 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=freenet.de; s=mjaymdexmjqk; h=Content-Transfer-Encoding:Content-Type:MIME-Version: Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=1w80BtQ+ed/z1mH1FpbC172tIShkMQjpooQm+jJ+VHw=; b=PGySRvbV095do2Awpj5bffT7JZ ijLDP7ogwSvYYgH64lz1uN1Zhn0fnvef83in/PEbjR0oftOidfnDB2DQVumu0pFyYpNmW0bO+L1d+ a7BDgKiqT9d3FM2JhB7h/FZeaYC4YItkphDkWQWzZx4vpTPJyWQYGz2B+AL7cWoOrsn490C9wne/X hVJdQAawxobLdx1q0YjgOEyeeujdwUsCc57oegLjC04MzWgKCCphpRZn90lSaZ3tp/vX1LIMLlL/v p8uR6zI3Y5bMwW6UNFQmoJfYjQ/MuUgFL4+3kv0ddMWSPqZ+tE6pcfmaN7LMAkJuT5PBFCX/IbkDM UQJmXAxg==; Received: from p200300e2e705fb00dacb8afffee0ca63.dip0.t-ipconnect.de ([2003:e2:e705:fb00:dacb:8aff:fee0:ca63]:46380 helo=soren-pc.lan) by sub7.freenet.de with esmtpsa (ID soekkle@freenet.de) (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (port 465) (Exim 4.94.2 #2) id 1tUsTd-00Brik-80; Mon, 06 Jan 2025 20:09:25 +0100 From: =?utf-8?q?S=C3=B6ren_Krecker?= To: git@vger.kernel.org Cc: gitster@pobox.com, phillip.wood123@gmail.com, ps@pks.im, =?utf-8?q?S?= =?utf-8?q?=C3=B6ren_Krecker?= Subject: [PATCHv2 4/4] commit.c: Fix type missmatch warings from msvc Date: Mon, 6 Jan 2025 20:08:55 +0100 Message-Id: <20250106190855.3098-5-soekkle@freenet.de> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250106190855.3098-1-soekkle@freenet.de> References: <20250106190855.3098-1-soekkle@freenet.de> Reply-To: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-FN-MUUID: 1736190565F64ABA71F9A5O X-Originated-At: 2003:e2:e705:fb00:dacb:8aff:fee0:ca63!46380 X-Scan-TS: Mon, 06 Jan 2025 20:09:25 +0100 Fix compiler warings 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 --- commit.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/commit.c b/commit.c index a127fe60c5..78993395e6 100644 --- a/commit.c +++ b/commit.c @@ -466,8 +466,8 @@ int parse_commit_buffer(struct repository *r, struct commit *item, const void *b struct object_id parent; struct commit_list **pptr; struct commit_graft *graft; - const int tree_entry_len = the_hash_algo->hexsz + 5; - const int parent_entry_len = the_hash_algo->hexsz + 7; + const size_t tree_entry_len = the_hash_algo->hexsz + 5; + const size_t parent_entry_len = the_hash_algo->hexsz + 7; struct tree *tree; if (item->object.parsed) @@ -1114,10 +1114,10 @@ static const char *gpg_sig_headers[] = { int add_header_signature(struct strbuf *buf, struct strbuf *sig, const struct git_hash_algo *algo) { - int inspos, copypos; + ssize_t inspos, copypos; const char *eoh; const char *gpg_sig_header = gpg_sig_headers[hash_algo_by_ptr(algo)]; - int gpg_sig_header_len = strlen(gpg_sig_header); + size_t gpg_sig_header_len = strlen(gpg_sig_header); /* find the end of the header */ eoh = strstr(buf->buf, "\n\n"); @@ -1530,7 +1530,7 @@ int commit_tree(const char *msg, size_t msg_len, const struct object_id *tree, return result; } -static int find_invalid_utf8(const char *buf, int len) +static int find_invalid_utf8(const char *buf, size_t len) { int offset = 0; static const unsigned int max_codepoint[] = { @@ -1539,7 +1539,7 @@ static int find_invalid_utf8(const char *buf, int len) while (len) { unsigned char c = *buf++; - int bytes, bad_offset; + size_t bytes, bad_offset; unsigned int codepoint; unsigned int min_val, max_val;