From: john at keeping.me.uk (John Keeping)
Subject: [PATCH] ui-shared: fix return type of cgit_self_link
Date: Wed, 6 Mar 2013 20:51:54 +0000 [thread overview]
Message-ID: <7d76674884011bba57c0ce0b7d55849b6cb9dbc7.1362603018.git.john@keeping.me.uk> (raw)
cgit_self_link() is a void function but implements each case it handles
by doing "return <another_void_function>" which is not valid C; section
6.8.6.4 of C11 says:
A return statement with an expression shall not appear in a
function whose return type is void.
Fix this by removing the return keywords and converting the final code
block into an "else".
Signed-off-by: John Keeping <john at keeping.me.uk>
---
Interestingly, while checking for a reference to confirm that this
really is an issue, Microsoft's compiler says this:
If the function was declared with return type void, a return
statement containing an expression generates a warning and the
expression is not evaluated.
I assume that GCC just converts "return expresion;" in a void function
into "expression; return;" which is why this hasn't been noticed.
ui-shared.c | 83 +++++++++++++++++++++++++++++++------------------------------
1 file changed, 42 insertions(+), 41 deletions(-)
diff --git a/ui-shared.c b/ui-shared.c
index af5310b..80f4aee 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -437,58 +437,59 @@ void cgit_self_link(char *name, const char *title, const char *class,
struct cgit_context *ctx)
{
if (!strcmp(ctx->qry.page, "repolist"))
- return cgit_index_link(name, title, class, ctx->qry.search, ctx->qry.sort,
- ctx->qry.ofs);
+ cgit_index_link(name, title, class, ctx->qry.search, ctx->qry.sort,
+ ctx->qry.ofs);
else if (!strcmp(ctx->qry.page, "summary"))
- return cgit_summary_link(name, title, class, ctx->qry.head);
+ cgit_summary_link(name, title, class, ctx->qry.head);
else if (!strcmp(ctx->qry.page, "tag"))
- return cgit_tag_link(name, title, class, ctx->qry.head,
- ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL);
+ cgit_tag_link(name, title, class, ctx->qry.head,
+ ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL);
else if (!strcmp(ctx->qry.page, "tree"))
- return cgit_tree_link(name, title, class, ctx->qry.head,
- ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL,
- ctx->qry.path);
+ cgit_tree_link(name, title, class, ctx->qry.head,
+ ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL,
+ ctx->qry.path);
else if (!strcmp(ctx->qry.page, "plain"))
- return cgit_plain_link(name, title, class, ctx->qry.head,
- ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL,
- ctx->qry.path);
+ cgit_plain_link(name, title, class, ctx->qry.head,
+ ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL,
+ ctx->qry.path);
else if (!strcmp(ctx->qry.page, "log"))
- return cgit_log_link(name, title, class, ctx->qry.head,
- ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL,
- ctx->qry.path, ctx->qry.ofs,
- ctx->qry.grep, ctx->qry.search,
- ctx->qry.showmsg);
+ cgit_log_link(name, title, class, ctx->qry.head,
+ ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL,
+ ctx->qry.path, ctx->qry.ofs,
+ ctx->qry.grep, ctx->qry.search,
+ ctx->qry.showmsg);
else if (!strcmp(ctx->qry.page, "commit"))
- return cgit_commit_link(name, title, class, ctx->qry.head,
- ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL,
- ctx->qry.path, 0);
+ cgit_commit_link(name, title, class, ctx->qry.head,
+ ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL,
+ ctx->qry.path, 0);
else if (!strcmp(ctx->qry.page, "patch"))
- return cgit_patch_link(name, title, class, ctx->qry.head,
- ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL,
- ctx->qry.path);
+ cgit_patch_link(name, title, class, ctx->qry.head,
+ ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL,
+ ctx->qry.path);
else if (!strcmp(ctx->qry.page, "refs"))
- return cgit_refs_link(name, title, class, ctx->qry.head,
- ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL,
- ctx->qry.path);
+ cgit_refs_link(name, title, class, ctx->qry.head,
+ ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL,
+ ctx->qry.path);
else if (!strcmp(ctx->qry.page, "snapshot"))
- return cgit_snapshot_link(name, title, class, ctx->qry.head,
- ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL,
- ctx->qry.path);
+ cgit_snapshot_link(name, title, class, ctx->qry.head,
+ ctx->qry.has_sha1 ? ctx->qry.sha1 : NULL,
+ ctx->qry.path);
else if (!strcmp(ctx->qry.page, "diff"))
- return cgit_diff_link(name, title, class, ctx->qry.head,
- ctx->qry.sha1, ctx->qry.sha2,
- ctx->qry.path, 0);
+ cgit_diff_link(name, title, class, ctx->qry.head,
+ ctx->qry.sha1, ctx->qry.sha2,
+ ctx->qry.path, 0);
else if (!strcmp(ctx->qry.page, "stats"))
- return cgit_stats_link(name, title, class, ctx->qry.head,
- ctx->qry.path);
-
- /* Don't known how to make link for this page */
- repolink(title, class, ctx->qry.page, ctx->qry.head, ctx->qry.path);
- html("><!-- cgit_self_link() doesn't know how to make link for page '");
- html_txt(ctx->qry.page);
- html("' -->");
- html_txt(name);
- html("</a>");
+ cgit_stats_link(name, title, class, ctx->qry.head,
+ ctx->qry.path);
+ else {
+ /* Don't known how to make link for this page */
+ repolink(title, class, ctx->qry.page, ctx->qry.head, ctx->qry.path);
+ html("><!-- cgit_self_link() doesn't know how to make link for page '");
+ html_txt(ctx->qry.page);
+ html("' -->");
+ html_txt(name);
+ html("</a>");
+ }
}
void cgit_object_link(struct object *obj)
--
1.8.2.rc2.4.g7799588
next reply other threads:[~2013-03-06 20:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-06 20:51 john [this message]
2013-03-20 20:04 ` Jason
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=7d76674884011bba57c0ce0b7d55849b6cb9dbc7.1362603018.git.john@keeping.me.uk \
--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).