Skip to content
Snippets Groups Projects
  • Dr. David Alan Gilbert's avatar
    da16f4b8
    qemu-io-cmds: Simplify help_oneline · da16f4b8
    Dr. David Alan Gilbert authored
    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: default avatarDr. David Alan Gilbert <dgilbert@redhat.com>
    Message-Id: <20200824102914.105619-1-dgilbert@redhat.com>
    Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
    da16f4b8
    History
    qemu-io-cmds: Simplify help_oneline
    Dr. David Alan Gilbert authored
    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: default avatarDr. David Alan Gilbert <dgilbert@redhat.com>
    Message-Id: <20200824102914.105619-1-dgilbert@redhat.com>
    Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>