# [PATCH 0/4] Fix minor warnings reported by icc

9 messages from 2011-11-15 to 2011-11-16. Participants: Ramkumar Ramachandra, Junio C Hamano.
Thread: https://gitlist.dev/t/28941

## Ramkumar Ramachandra, 2011-11-15 16:59

Subject: [PATCH 0/4] Fix minor warnings reported by icc
Message-ID: <1321376379-31750-1-git-send-email-artagnon@gmail.com>
URL: https://gitlist.dev/e/1321376379-31750-1-git-send-email-artagnon%40gmail.com

```
Hi,

Thomas Rast tried compiling Git with Intel's C compiler (icc) recently
and the results can be found here [1].  Most of them don't amount to
anything, are probably not worth fixing.  Here are fixes to a few that
caught my eye.

Thanks.

[1]: https://gist.github.com/1367335

-- Ram

Ramkumar Ramachandra (4):
  http: remove unused function hex()
  convert: don't mix enum with int
  ll-merge: initialize default_opts const
  sha1_file: don't mix enum with int

 convert.c   |    6 +++---
 http.c      |    8 --------
 ll-merge.c  |    2 +-
 sha1_file.c |    2 +-
 4 files changed, 5 insertions(+), 13 deletions(-)

-- 
1.7.6.351.gb35ac.dirty

```

## Ramkumar Ramachandra, 2011-11-15 16:59

Subject: [PATCH 1/4] http: remove unused function hex()
Message-ID: <1321376379-31750-2-git-send-email-artagnon@gmail.com>
URL: https://gitlist.dev/e/1321376379-31750-2-git-send-email-artagnon%40gmail.com
In-Reply-To: <1321376379-31750-1-git-send-email-artagnon@gmail.com>

```
Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 http.c |    8 --------
 1 files changed, 0 insertions(+), 8 deletions(-)

diff --git a/http.c b/http.c
index 008ad72..e6c7597 100644
--- a/http.c
+++ b/http.c
@@ -747,14 +747,6 @@ static inline int needs_quote(int ch)
 	return 1;
 }
 
-static inline int hex(int v)
-{
-	if (v < 10)
-		return '0' + v;
-	else
-		return 'A' + v - 10;
-}
-
 static char *quote_ref_url(const char *base, const char *ref)
 {
 	struct strbuf buf = STRBUF_INIT;
-- 
1.7.6.351.gb35ac.dirty

```

## Ramkumar Ramachandra, 2011-11-15 16:59

Subject: [PATCH 2/4] convert: don't mix enum with int
Message-ID: <1321376379-31750-3-git-send-email-artagnon@gmail.com>
URL: https://gitlist.dev/e/1321376379-31750-3-git-send-email-artagnon%40gmail.com
In-Reply-To: <1321376379-31750-1-git-send-email-artagnon@gmail.com>

```
Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 convert.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/convert.c b/convert.c
index 3bb5a4d..038b0be 100644
--- a/convert.c
+++ b/convert.c
@@ -641,7 +641,7 @@ static int ident_to_worktree(const char *path, const char *src, size_t len,
 	return 1;
 }
 
-static int git_path_check_crlf(const char *path, struct git_attr_check *check)
+static enum crlf_action git_path_check_crlf(const char *path, struct git_attr_check *check)
 {
 	const char *value = check->value;
 
@@ -658,7 +658,7 @@ static int git_path_check_crlf(const char *path, struct git_attr_check *check)
 	return CRLF_GUESS;
 }
 
-static int git_path_check_eol(const char *path, struct git_attr_check *check)
+static enum crlf_action git_path_check_eol(const char *path, struct git_attr_check *check)
 {
 	const char *value = check->value;
 
@@ -811,7 +811,7 @@ int renormalize_buffer(const char *path, const char *src, size_t len, struct str
 		src = dst->buf;
 		len = dst->len;
 	}
-	return ret | convert_to_git(path, src, len, dst, 0);
+	return ret | convert_to_git(path, src, len, dst, SAFE_CRLF_FALSE);
 }
 
 /*****************************************************************
-- 
1.7.6.351.gb35ac.dirty

```

## Ramkumar Ramachandra, 2011-11-15 16:59

Subject: [PATCH 3/4] ll-merge: initialize default_opts const
Message-ID: <1321376379-31750-4-git-send-email-artagnon@gmail.com>
URL: https://gitlist.dev/e/1321376379-31750-4-git-send-email-artagnon%40gmail.com
In-Reply-To: <1321376379-31750-1-git-send-email-artagnon@gmail.com>

```
Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 ll-merge.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/ll-merge.c b/ll-merge.c
index da59738..205aed3 100644
--- a/ll-merge.c
+++ b/ll-merge.c
@@ -351,7 +351,7 @@ int ll_merge(mmbuffer_t *result_buf,
 	     const struct ll_merge_options *opts)
 {
 	static struct git_attr_check check[2];
-	static const struct ll_merge_options default_opts;
+	static const struct ll_merge_options default_opts = {0, 0, 0, 0};
 	const char *ll_driver_name = NULL;
 	int marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
 	const struct ll_merge_driver *driver;
-- 
1.7.6.351.gb35ac.dirty

```

## Ramkumar Ramachandra, 2011-11-15 16:59

Subject: [PATCH 4/4] sha1_file: don't mix enum with int
Message-ID: <1321376379-31750-5-git-send-email-artagnon@gmail.com>
URL: https://gitlist.dev/e/1321376379-31750-5-git-send-email-artagnon%40gmail.com
In-Reply-To: <1321376379-31750-1-git-send-email-artagnon@gmail.com>

```
Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 sha1_file.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/sha1_file.c b/sha1_file.c
index 27f3b9b..869852b 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -2616,7 +2616,7 @@ static int index_mem(unsigned char *sha1, void *buf, size_t size,
 	if ((type == OBJ_BLOB) && path) {
 		struct strbuf nbuf = STRBUF_INIT;
 		if (convert_to_git(path, buf, size, &nbuf,
-		                   write_object ? safe_crlf : 0)) {
+		                   write_object ? safe_crlf : SAFE_CRLF_FALSE)) {
 			buf = strbuf_detach(&nbuf, &size);
 			re_allocated = 1;
 		}
-- 
1.7.6.351.gb35ac.dirty

```

## Ramkumar Ramachandra, 2011-11-15 17:31

Subject: [PATCH 5/4] git-compat-util: don't assume value for undefined variable
Message-ID: <1321378269-13867-1-git-send-email-artagnon@gmail.com>
URL: https://gitlist.dev/e/1321378269-13867-1-git-send-email-artagnon%40gmail.com
In-Reply-To: <1321376379-31750-1-git-send-email-artagnon@gmail.com>

```
Suggested-by: Thomas Rast <trast@student.ethz.ch>
Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 And here's another probably worth fixing.

 git-compat-util.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/git-compat-util.h b/git-compat-util.h
index 5ef8ff7..8b4dd5c 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -219,7 +219,7 @@ extern char *gitbasename(char *);
 #define find_last_dir_sep(path) strrchr(path, '/')
 #endif
 
-#if __HP_cc >= 61000
+#if defined(__HP_cc) && (__HP_cc >= 61000)
 #define NORETURN __attribute__((noreturn))
 #define NORETURN_PTR
 #elif defined(__GNUC__) && !defined(NO_NORETURN)
-- 
1.7.6.351.gb35ac.dirty

```

## Junio C Hamano, 2011-11-15 23:17

Subject: Re: [PATCH 3/4] ll-merge: initialize default_opts const
Message-ID: <7vty65t1qp.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vty65t1qp.fsf%40alter.siamese.dyndns.org
In-Reply-To: <1321376379-31750-4-git-send-email-artagnon@gmail.com>

```
Ramkumar Ramachandra <artagnon@gmail.com> writes:

> Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
> ---
>  ll-merge.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/ll-merge.c b/ll-merge.c
> index da59738..205aed3 100644
> --- a/ll-merge.c
> +++ b/ll-merge.c
> @@ -351,7 +351,7 @@ int ll_merge(mmbuffer_t *result_buf,
>  	     const struct ll_merge_options *opts)
>  {
>  	static struct git_attr_check check[2];
> -	static const struct ll_merge_options default_opts;
> +	static const struct ll_merge_options default_opts = {0, 0, 0, 0};

Doesn't "static" tell us that it will be in BSS, initialized to all zero
by definition?

```

## Ramkumar Ramachandra, 2011-11-16 06:06

Subject: Re: [PATCH 3/4] ll-merge: initialize default_opts const
Message-ID: <CALkWK0mVxxq0345B_OJQwejpTBD=evOU_iAv39CvXv4mAi=09A@mail.gmail.com>
URL: https://gitlist.dev/e/CALkWK0mVxxq0345B_OJQwejpTBD%3DevOU_iAv39CvXv4mAi%3D09A%40mail.gmail.com
In-Reply-To: <7vty65t1qp.fsf@alter.siamese.dyndns.org>

```
Hi Junio,

Junio C Hamano wrote:
> Ramkumar Ramachandra <artagnon@gmail.com> writes:
>> [...]
>> diff --git a/ll-merge.c b/ll-merge.c
>> index da59738..205aed3 100644
>> --- a/ll-merge.c
>> +++ b/ll-merge.c
>> @@ -351,7 +351,7 @@ int ll_merge(mmbuffer_t *result_buf,
>>            const struct ll_merge_options *opts)
>>  {
>>       static struct git_attr_check check[2];
>> -     static const struct ll_merge_options default_opts;
>> +     static const struct ll_merge_options default_opts = {0, 0, 0, 0};
>
> Doesn't "static" tell us that it will be in BSS, initialized to all zero
> by definition?

I'm uncertain about whether the C89 standard says this explicitly- icc
is more pedantic than most mainstream compilers.  Feel free to drop
this part if you don't think it adds value.

Thanks.

-- Ram

```

## Junio C Hamano, 2011-11-16 07:49

Subject: Re: [PATCH 3/4] ll-merge: initialize default_opts const
Message-ID: <7vd3csqzgs.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vd3csqzgs.fsf%40alter.siamese.dyndns.org
In-Reply-To: <CALkWK0mVxxq0345B_OJQwejpTBD=evOU_iAv39CvXv4mAi=09A@mail.gmail.com>

```
Ramkumar Ramachandra <artagnon@gmail.com> writes:

> Hi Junio,
>
> Junio C Hamano wrote:
>> Ramkumar Ramachandra <artagnon@gmail.com> writes:
>>> [...]
>>> -     static const struct ll_merge_options default_opts;
>>> +     static const struct ll_merge_options default_opts = {0, 0, 0, 0};
>>
>> Doesn't "static" tell us that it will be in BSS, initialized to all zero
>> by definition?
>
> I'm uncertain about whether the C89 standard says this explicitly- icc
> is more pedantic than most mainstream compilers.

Actually I take a part of the comment back; as this is "static const", it
is entirely plausible for a compiler to tell the linker to put it in rodata
instead of bss, to cause any attempt to modify it to segv.

A datum that is implicitly initialized to all zero and not allowed to be
modified might appear suspect to some compiler writers (especially when
they are under influence ;-)), so I am not so surprised if a compiler
issued a warning saying "did you forget to initialize it?".

```
