Re: [PATCH v2 3/7] url: add str wrapper for end_url_with_slash()

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH v2 3/7] url: add str wrapper for end_url_with_slash()

From: Jonathan Nieder <hidden>
Date: 2016-06-15 22:50:05

Tay Ray Chuan wrote:
quoted hunk
--- a/url.c
+++ b/url.c
@@ -132,3 +132,11 @@ void end_url_with_slash(struct strbuf *buf, const char *url)
 	if (buf->len && buf->buf[buf->len - 1] != '/')
 		strbuf_addstr(buf, "/");
 }
+
+void str_end_url_with_slash(const char *url, char **dest) {
+	struct strbuf buf = STRBUF_INIT;
+	end_url_with_slash(&buf, url);
+	if (dest)
+		free(*dest);
+	*dest = strbuf_detach(&buf, NULL);
I think this should be

	end_url_with_slash(&buf, url);
	free(*dest);
	*dest = strbuf_detach(...

If dest were NULL, the assignment would segfault anyway.  If dest were
non-NULL and *dest NULL, the free() would be a no-op.

Re: [PATCH v2 3/7] url: add str wrapper for end_url_with_slash()

From: Tay Ray Chuan <hidden>
Date: 2016-06-15 22:50:05

Hi,

On Tue, Nov 23, 2010 at 1:14 AM, Jonathan Nieder [off-list ref] wrote:
Tay Ray Chuan wrote:
quoted
--- a/url.c
+++ b/url.c
@@ -132,3 +132,11 @@ void end_url_with_slash(struct strbuf *buf, const char *url)
      if (buf->len && buf->buf[buf->len - 1] != '/')
              strbuf_addstr(buf, "/");
 }
+
+void str_end_url_with_slash(const char *url, char **dest) {
+     struct strbuf buf = STRBUF_INIT;
+     end_url_with_slash(&buf, url);
+     if (dest)
+             free(*dest);
+     *dest = strbuf_detach(&buf, NULL);
I think this should be

       end_url_with_slash(&buf, url);
       free(*dest);
       *dest = strbuf_detach(...

If dest were NULL, the assignment would segfault anyway.  If dest were
non-NULL and *dest NULL, the free() would be a no-op.
Thanks for the tip.

-- 
Cheers,
Ray Chuan
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help