From: "Sören Krecker" <soekkle@freenet.de>
To: git@vger.kernel.org
Cc: gitster@pobox.com, phillip.wood123@gmail.com, ps@pks.im,
"Sören Krecker" <soekkle@freenet.de>
Subject: [PATCHv2 3/4] apply.c : Fix type missmatch warings from msvc
Date: Mon, 6 Jan 2025 20:08:54 +0100 [thread overview]
Message-ID: <20250106190855.3098-4-soekkle@freenet.de> (raw)
In-Reply-To: <20250106190855.3098-1-soekkle@freenet.de>
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 <soekkle@freenet.de>
---
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);
--
2.39.5
next prev parent reply other threads:[~2025-01-06 19:14 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-06 19:08 [PATCHv2 0/4] Fixes typemissmatch warinigs from msvc Sören Krecker
2025-01-06 19:08 ` [PATCHv2 1/4] add-patch: Fix type missmatch rom msvc Sören Krecker
2025-01-07 0:13 ` brian m. carlson
2025-01-07 0:26 ` Junio C Hamano
2025-01-07 0:53 ` Junio C Hamano
2025-01-06 19:08 ` [PATCHv2 2/4] date.c: Fix type missmatch warings from msvc Sören Krecker
2025-01-06 22:22 ` Eric Sunshine
2025-01-06 22:53 ` Andreas Schwab
2025-01-06 19:08 ` Sören Krecker [this message]
2025-01-06 22:26 ` [PATCHv2 3/4] apply.c : " Eric Sunshine
2025-01-06 19:08 ` [PATCHv2 4/4] commit.c: " Sören Krecker
2025-01-06 22:27 ` Eric Sunshine
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250106190855.3098-4-soekkle@freenet.de \
--to=soekkle@freenet.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=phillip.wood123@gmail.com \
--cc=ps@pks.im \
--cc=xmqqfrm9t6up.fsf@gitster.g \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).