[PATCH] git-name-rev: don't use printf without format

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



printf() without an explicit format string is not a good coding practise,
unless the printed string is guaranteed to not contain percent signs.  While
fixing this, we might as well combine the calls to fwrite() and printf().

Signed-off-by: Rene Scharfe <rene.scharfe@xxxxxxxxxxxxxx>
---
 builtin-name-rev.c |   12 +++++-------
 1 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/builtin-name-rev.c b/builtin-name-rev.c
index 7055ac3..08c8aab 100644
--- a/builtin-name-rev.c
+++ b/builtin-name-rev.c
@@ -189,6 +189,7 @@ static void name_rev_line(char *p, struct name_ref_data *data)
 			unsigned char sha1[40];
 			const char *name = NULL;
 			char c = *(p+1);
+			int p_len = p - p_start + 1;
 
 			forty = 0;
 
@@ -204,13 +205,10 @@ static void name_rev_line(char *p, struct name_ref_data *data)
 			if (!name)
 				continue;
 
-			if (data->name_only) {
-				fwrite(p_start, p - p_start + 1 - 40, 1, stdout);
-				printf(name);
-			} else {
-				fwrite(p_start, p - p_start + 1, 1, stdout);
-				printf(" (%s)", name);
-			}
+			if (data->name_only)
+				printf("%.*s%s", p_len - 40, p_start, name);
+			else
+				printf("%.*s (%s)", p_len, p_start, name);
 			p_start = p + 1;
 		}
 	}

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux