n; charset=UTF-8
Content-Disposition: inline; filename="c4167cbd65acef801e6132ba1182f6ce246ed630..08a2b1b8f812c6d77489467c8ff120979c297bed.patch"
Last-Modified: Sun, 29 Dec 2024 12:00:16 GMT
Expires: Sun, 29 Dec 2024 16:00:16 GMT

From 08a2b1b8f812c6d77489467c8ff120979c297bed Mon Sep 17 00:00:00 2001
From: Jason A. Donenfeld
Date: Wed, 4 Jul 2018 03:13:31 +0200
Subject: Fix gcc 8.1.1 compiler warnings

    CC ../shared.o
../shared.c: In function ‘expand_macro’:
../shared.c:487:3: warning: ‘strncpy’ specified bound depends on the length of the source argument [-Wstringop-overflow=]
   strncpy(name, value, len);
   ^~~~~~~~~~~~~~~~~~~~~~~~~
../shared.c:484:9: note: length computed here
   len = strlen(value);
         ^~~~~~~~~~~~~
../ui-shared.c: In function ‘cgit_repobasename’:
../ui-shared.c:136:2: warning: ‘strncpy’ specified bound 1024 equals destination size [-Wstringop-truncation]
  strncpy(rvbuf, reponame, sizeof(rvbuf));
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    CC ../ui-ssdiff.o
../ui-ssdiff.c: In function ‘replace_tabs’:
../ui-ssdiff.c:142:4: warning: ‘strncat’ output truncated copying between 1 and 8 bytes from a string of length 8 [-Wstringop-truncation]
    strncat(result, spaces, 8 - (strlen(result) % 8));
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
 shared.c    |  7 ++++---
 ui-shared.c | 19 ++++++++++++-------
 ui-ssdiff.c | 12 +++++++-----
 3 files changed, 23 insertions(+), 15 deletions(-)

diff --git a/shared.c b/shared.c
index f7b64cf..609bd2a 100644
--- a/shared.c
+++ b/shared.c
@@ -476,15 +476,16 @@ static int is_token_char(char c)
 static char *expand_macro(char *name, int maxlength)
 {
 	char *value;
-	int len;
+	size_t len;
 
 	len = 0;
 	value = getenv(name);
 	if (value) {
-		len = strlen(value);
+		len = strlen(value) + 1;
 		if (len > maxlength)
 			len = maxlength;
-		strncpy(name, value, len);
+		strlcpy(name, value, len);
+		--len;
 	}
 	return name + len;
 }
diff --git a/ui-shared.c b/ui-shared.c
index 066a470..739505a 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -133,20 +133,25 @@ const char *cgit_repobasename(const char *reponame)
 	static char rvbuf[1024];
 	int p;
 	const char *rv;
-	strncpy(rvbuf, reponame, sizeof(rvbuf));
-	if (rvbuf[sizeof(rvbuf)-1])
+	size_t len;
+
+	len = strlcpy(rvbuf, reponame, sizeof(rvbuf));
+	if (len >= sizeof(rvbuf))
 		die("cgit_repobasename: truncated repository name '%s'", reponame);
-	p = strlen(rvbuf)-1;
+	p = len - 1;
 	/* strip trailing slashes */
-	while (p && rvbuf[p] == '/') rvbuf[p--] = 0;
+	while (p && rvbuf[p] == '/')
+		rvbuf[p--] = '\0';
 	/* strip trailing .git */
 	if (p >= 3 && starts_with(&rvbuf[p-3], ".git")) {
-		p -= 3; rvbuf[p--] = 0;
+		p -= 3;
+		rvbuf[p--] = '\0';
 	}
 	/* strip more trailing slashes if any */
-	while ( p && rvbuf[p] == '/') rvbuf[p--] = 0;
+	while (p && rvbuf[p] == '/')
+		rvbuf[p--] = '\0';
 	/* find last slash in the remaining string */
-	rv = strrchr(rvbuf,'/');
+	rv = strrchr(rvbuf, '/');
 	if (rv)
 		return ++rv;
 	return rvbuf;
diff --git a/ui-ssdiff.c b/ui-ssdiff.c
index 7f261ed..68c2044 100644
--- a/ui-ssdiff.c
+++ b/ui-ssdiff.c
@@ -114,11 +114,10 @@ static char *replace_tabs(char *line)
 {
 	char *prev_buf = line;
 	char *cur_buf;
-	int linelen = strlen(line);
+	size_t linelen = strlen(line);
 	int n_tabs = 0;
 	int i;
 	char *result;
-	char *spaces = "        ";
 
 	if (linelen == 0) {
 		result = xmalloc(1);
@@ -126,20 +125,23 @@ static char *replace_tabs(char *line)
 		return result;
 	}
 
-	for (i = 0; i < linelen; i++)
+	for (i = 0; i < linelen; i++) {
 		if (line[i] == '\t')
 			n_tabs += 1;
+	}
 	result = xmalloc(linelen + n_tabs * 8 + 1);
 	result[0] = '\0';
 
-	while (1) {
+	for (;;) {
 	<style>pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */</style><div class="highlight"><pre><span></span><span class="ch">#!/bin/sh</span>

<span class="c1"># Get version-info specified in Makefile</span>
<span class="nv">V</span><span class="o">=</span><span class="nv">$1</span>

<span class="c1"># Use `git describe` to get current version if we&#39;re inside a git repo</span>
<span class="k">if</span><span class="w"> </span><span class="nb">test</span><span class="w"> </span>-d<span class="w"> </span>.git
<span class="k">then</span>
<span class="w">	</span><span class="nv">V</span><span class="o">=</span><span class="k">$(</span>git<span class="w"> </span>describe<span class="w"> </span>--abbrev<span class="o">=</span><span class="m">4</span><span class="w"> </span>HEAD<span class="w"> </span><span class="m">2</span>&gt;/dev/null<span class="k">)</span>
<span class="k">fi</span>

<span class="nv">new</span><span class="o">=</span><span class="s2">&quot;CGIT_VERSION = </span><span class="nv">$V</span><span class="s2">&quot;</span>
<span class="nv">old</span><span class="o">=</span><span class="k">$(</span>cat<span class="w"> </span>VERSION<span class="w"> </span><span class="m">2</span>&gt;/dev/null<span class="k">)</span>

<span class="c1"># Exit if VERSION is uptodate</span>
<span class="nb">test</span><span class="w"> </span><span class="s2">&quot;</span><span class="nv">$old</span><span class="s2">&quot;</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">&quot;</span><span class="nv">$new</span><span class="s2">&quot;</span><span class="w"> </span><span class="o">&amp;&amp;</span><span class="w"> </span><span class="nb">exit</span><span class="w"> </span><span class="m">0</span>

<span class="c1"># Update VERSION with new version-info</span>
<span class="nb">echo</span><span class="w"> </span><span class="s2">&quot;</span><span class="nv">$new</span><span class="s2">&quot;</span><span class="w"> </span>&gt;<span class="w"> </span>VERSION
cat<span class="w"> </span>VERSION
</pre></div>
</code></pre></td></tr></table>
</div> <!-- class=content -->
<div class='footer'>generated by <a href='https://git.zx2c4.com/cgit/about/'>cgit v1.2.3-54-g00ecf</a> (<a href='https://git-scm.com/'>git 2.39.0</a>) at 2024-12-29 12:00:18 +0000</div>
</div> <!-- id=cgit -->
</body>
</html>
