List for cgit developers and users
 help / color / mirror / Atom feed
From: list at eworm.de (Christian Hesse)
Subject: [PATCH 6/9] ui-shared: ban strcat()
Date: Tue, 28 Aug 2018 20:38:23 +0200	[thread overview]
Message-ID: <20180828183826.25043-6-list@eworm.de> (raw)
In-Reply-To: <20180828183826.25043-1-list@eworm.de>

From: Christian Hesse <mail at eworm.de>

Git upstream bans strcat() with commit:

  banned.h: mark strcat() as banned
  1b11b64b815db62f93a04242e4aed5687a448748

To avoid compiler warnings from gcc 8.1.x we get the hard way.

Signed-off-by: Christian Hesse <mail at eworm.de>
---
 ui-shared.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/ui-shared.c b/ui-shared.c
index 739505a..b53c56d 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -1159,7 +1159,7 @@ void cgit_print_snapshot_links(const struct cgit_repo *repo, const char *ref,
 
 void cgit_set_title_from_path(const char *path)
 {
-	size_t path_len, path_index, path_last_end;
+	size_t path_len, path_index, path_last_end, line_len;
 	char *new_title;
 
 	if (!path)
@@ -1176,14 +1176,18 @@ void cgit_set_title_from_path(const char *path)
 				continue;
 			}
 			strncat(new_title, &path[path_index + 1], path_last_end - path_index - 1);
-			strcat(new_title, "\\");
+			line_len = strlen(new_title);
+			new_title[line_len++] = '\\';
+			new_title[line_len] = '\0';
 			path_last_end = path_index;
 		}
 	}
 	if (path_last_end)
 		strncat(new_title, path, path_last_end);
 
-	strcat(new_title, " - ");
-	strcat(new_title, ctx.page.title);
+	line_len = strlen(new_title);
+	memcpy(&new_title[line_len], " - ", 3);
+	new_title[line_len + 3] = '\0';
+	strncat(new_title, ctx.page.title, sizeof(new_title) - strlen(new_title) - 1);
 	ctx.page.title = new_title;
 }


  parent reply	other threads:[~2018-08-28 18:38 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-28 18:38 [PATCH 1/9] parsing: ban strncpy() list
2018-08-28 18:38 ` [PATCH 2/9] parsing: ban sprintf() list
2018-08-28 18:38 ` [PATCH 3/9] ui-log: ban strcpy() list
2018-08-28 18:38 ` [PATCH 4/9] ui-log: ban strncpy() list
2018-08-28 18:38 ` [PATCH 5/9] ui-patch: ban sprintf() list
2018-08-28 18:38 ` list [this message]
2018-08-28 18:38 ` [PATCH 7/9] ui-ssdiff: ban strncpy() list
2018-08-28 18:38 ` [PATCH 8/9] ui-ssdiff: ban strcat() list
2018-08-28 18:38 ` [PATCH 9/9] RFC: git: update to v2.19.0-rc0 list
2018-08-28 20:13   ` [PATCH 1/1] RFC: git: update to v2.19.0-rc1 list
2018-09-05  6:44     ` [PATCH 1/1] RFC: git: update to v2.19.0-rc2 list
2018-09-10 21:16       ` [PATCH 1/1] git: update to v2.19.0 list
2018-09-11  0:57         ` Jason
2018-09-11  6:48           ` list
2018-10-12 21:08         ` [PATCH 1/1] git: update to v2.19.1 list

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=20180828183826.25043-6-list@eworm.de \
    --to=cgit@lists.zx2c4.com \
    /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).