# [PATCH] Remove redundant assignments

2 messages from 2011-11-27 to 2011-11-27. Participants: Jan Stępień, Junio C Hamano.
Thread: https://gitlist.dev/t/29026

## Jan Stępień, 2011-11-27 08:05

Subject: [PATCH] Remove redundant assignments
Message-ID: <1322381142-20645-1-git-send-email-jstepien@users.sourceforge.net>
URL: https://gitlist.dev/e/1322381142-20645-1-git-send-email-jstepien%40users.sourceforge.net

```
There were two redundant variable assignments in transport.c and
wt-status.c. Removing them hasn't introduced any compiler warnings or
regressions.

Signed-off-by: Jan Stępień <jstepien@users.sourceforge.net>
---
 transport.c |    2 +-
 wt-status.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/transport.c b/transport.c
index 51814b5..5143718 100644
--- a/transport.c
+++ b/transport.c
@@ -105,7 +105,7 @@ static void insert_packed_refs(const char *packed_refs, struct ref **list)
 		return;
 
 	for (;;) {
-		int cmp = cmp, len;
+		int cmp, len;
 
 		if (!fgets(buffer, sizeof(buffer), f)) {
 			fclose(f);
diff --git a/wt-status.c b/wt-status.c
index 70fdb76..35f61f4 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -229,7 +229,7 @@ static void wt_status_print_change_data(struct wt_status *s,
 {
 	struct wt_status_change_data *d = it->util;
 	const char *c = color(change_type, s);
-	int status = status;
+	int status;
 	char *one_name;
 	char *two_name;
 	const char *one, *two;
-- 
1.7.7.4

```

## Junio C Hamano, 2011-11-27 08:26

Subject: Re: [PATCH] Remove redundant assignments
Message-ID: <7vfwhavum2.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vfwhavum2.fsf%40alter.siamese.dyndns.org
In-Reply-To: <1322381142-20645-1-git-send-email-jstepien@users.sourceforge.net>

```
Jan Stępień  <jstepien@users.sourceforge.net> writes:

> There were two redundant variable assignments in transport.c and
> wt-status.c. Removing them hasn't introduced any compiler warnings or
> regressions.

It may not have added any warnings for _you_.

These "type a = a;" initializations (they are not even assignments and
would not result in any code in the output for sane compilers) are idioms
to squelch "unused" warnings from versions of compiler whose data flow
analysis is less than perfect by telling them that the author of the
section of the code knows what s/he is doing.

At least, that is why these pseudo initializations were added in these
codepaths. I personally feel that they should be made into useless but
real assignments (which may result in a useless assignment emited in the
resulting object code) rather than removing like your patch did which
unfortunately forces people with imperfect compilers to live with the
warnings, if one finds them ugly.

> Signed-off-by: Jan Stępień <jstepien@users.sourceforge.net>
> ---
>  transport.c |    2 +-
>  wt-status.c |    2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/transport.c b/transport.c
> index 51814b5..5143718 100644
> --- a/transport.c
> +++ b/transport.c
> @@ -105,7 +105,7 @@ static void insert_packed_refs(const char *packed_refs, struct ref **list)
>  		return;
>  
>  	for (;;) {
> -		int cmp = cmp, len;
> +		int cmp, len;
>  
>  		if (!fgets(buffer, sizeof(buffer), f)) {
>  			fclose(f);
> diff --git a/wt-status.c b/wt-status.c
> index 70fdb76..35f61f4 100644
> --- a/wt-status.c
> +++ b/wt-status.c
> @@ -229,7 +229,7 @@ static void wt_status_print_change_data(struct wt_status *s,
>  {
>  	struct wt_status_change_data *d = it->util;
>  	const char *c = color(change_type, s);
> -	int status = status;
> +	int status;
>  	char *one_name;
>  	char *two_name;
>  	const char *one, *two;

```
