* [PATCH] qemu-io-cmds: Simplify help_oneline
@ 2020-08-24 10:29 Dr. David Alan Gilbert (git)
2020-09-28 13:18 ` Kevin Wolf
0 siblings, 1 reply; 2+ messages in thread
From: Dr. David Alan Gilbert (git) @ 2020-08-24 10:29 UTC (permalink / raw)
To: qemu-devel, kwolf, philmd; +Cc: richard.henderson
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
help_oneline is declared and starts as:
static void help_oneline(const char *cmd, const cmdinfo_t *ct)
{
if (cmd) {
printf("%s ", cmd);
} else {
printf("%s ", ct->name);
if (ct->altname) {
printf("(or %s) ", ct->altname);
}
}
However, there are only two routes to help_oneline being called:
help_f -> help_all -> help_oneline(ct->name, ct)
help_f -> help_onecmd(argv[1], ct)
In the first case, 'cmd' and 'ct->name' are the same thing,
so it's impossible for the if (cmd) to be false and then validly
print ct->name - this is upsetting gcc
( https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96739 )
In the second case, cmd is argv[1] and we know we've got argv[1]
so again (cmd) is non-NULL.
Simplify help_oneline by just printing cmd.
(Also strengthen argc check just to be pedantic)
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
---
qemu-io-cmds.c | 11 ++---------
1 file changed, 2 insertions(+), 9 deletions(-)
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
index baeae86d8c..4153f1c0b0 100644
--- a/qemu-io-cmds.c
+++ b/qemu-io-cmds.c
@@ -2383,14 +2383,7 @@ static const cmdinfo_t sleep_cmd = {
static void help_oneline(const char *cmd, const cmdinfo_t *ct)
{
- if (cmd) {
- printf("%s ", cmd);
- } else {
- printf("%s ", ct->name);
- if (ct->altname) {
- printf("(or %s) ", ct->altname);
- }
- }
+ printf("%s ", cmd);
if (ct->args) {
printf("%s ", ct->args);
@@ -2420,7 +2413,7 @@ static int help_f(BlockBackend *blk, int argc, char **argv)
{
const cmdinfo_t *ct;
- if (argc == 1) {
+ if (argc < 2) {
help_all();
return 0;
}
--
2.26.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] qemu-io-cmds: Simplify help_oneline
2020-08-24 10:29 [PATCH] qemu-io-cmds: Simplify help_oneline Dr. David Alan Gilbert (git)
@ 2020-09-28 13:18 ` Kevin Wolf
0 siblings, 0 replies; 2+ messages in thread
From: Kevin Wolf @ 2020-09-28 13:18 UTC (permalink / raw)
To: Dr. David Alan Gilbert (git); +Cc: richard.henderson, philmd, qemu-devel
Am 24.08.2020 um 12:29 hat Dr. David Alan Gilbert (git) geschrieben:
> From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
>
> help_oneline is declared and starts as:
>
> static void help_oneline(const char *cmd, const cmdinfo_t *ct)
> {
> if (cmd) {
> printf("%s ", cmd);
> } else {
> printf("%s ", ct->name);
> if (ct->altname) {
> printf("(or %s) ", ct->altname);
> }
> }
>
> However, there are only two routes to help_oneline being called:
>
> help_f -> help_all -> help_oneline(ct->name, ct)
>
> help_f -> help_onecmd(argv[1], ct)
>
> In the first case, 'cmd' and 'ct->name' are the same thing,
> so it's impossible for the if (cmd) to be false and then validly
> print ct->name - this is upsetting gcc
> ( https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96739 )
>
> In the second case, cmd is argv[1] and we know we've got argv[1]
> so again (cmd) is non-NULL.
>
> Simplify help_oneline by just printing cmd.
> (Also strengthen argc check just to be pedantic)
>
> Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Thanks, applied to the block branch.
Kevin
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-09-28 13:42 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-08-24 10:29 [PATCH] qemu-io-cmds: Simplify help_oneline Dr. David Alan Gilbert (git)
2020-09-28 13:18 ` Kevin Wolf
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).