Repository: neovim/neovim
File: src/nvim/memline.c (C)

Code before:
              && swap_exists_action != SEA_NONE
              && has_autocmd(EVENT_SWAPEXISTS, buf_fname, buf)) {
            choice = do_swapexists(buf, fname);
          }

          if (choice == SEA_CHOICE_NONE && swap_exists_action == SEA_READONLY) {
            // always open readonly.
            choice = SEA_CHOICE_READONLY;
          }

          proc_running = 0;  // Set by attention_message..swapfile_info.
          if (choice == SEA_CHOICE_NONE) {
            // Show info about the existing swapfile.
            attention_message(buf, fname);

            // We don't want a 'q' typed at the more-prompt
            // interrupt loading a file.
            got_int = false;

            // If vimrc has "simalt ~x" we don't want it to
            // interfere with the prompt here.
            flush_buffers(FLUSH_TYPEAHEAD);
          }

          if (swap_exists_action != SEA_NONE && choice == SEA_CHOICE_NONE) {
            const char *const sw_msg_1 = _("Swap file \"");
            const char *const sw_msg_2 = _("\" already exists!");

            const size_t fname_len = strlen(fname);
            const size_t sw_msg_1_len = strlen(sw_msg_1);
            const size_t sw_msg_2_len = strlen(sw_msg_2);

            const size_t name_len = sw_msg_1_len + fname_len + sw_msg_2_len + 5;

            char *const name = xmalloc(name_len);
            memcpy(name, sw_msg_1, sw_msg_1_len + 1);
            home_replace(NULL, fname, name + sw_msg_1_len, fname_len, true);
            xstrlcat(name, sw_msg_2, name_len);
            int dialog_result
              = do_dialog(VIM_WARNING,
                          _("VIM - ATTENTION"),
                          name,
                          proc_running
                          ? _("&Open Read-Only\n&Edit anyway\n&Recover\n&Quit\n&Abort")
                          : _("&Open Read-Only\n&Edit anyway\n&Recover\n&Delete it\n&Quit\n&Abort"),
                          1, NULL, false);

            if (proc_running && dialog_result >= 4) {
              // compensate for missing "Delete it" button
              dialog_result++;
            }

Review comment (bug):
coverity:

```
*** CID 554963:           (FORWARD_NULL)
/src/nvim/memline.c: 3484             in findswapname()
3478                 if (swap_exists_action != SEA_NONE) {
3479                   kv_printf(msg, _("Swap file \""));
3480                   kv_printf(msg, "%s", fhname);
3481                   kv_printf(msg, _("\" already exists!"));
3482                   char *run_but = _("&Open Read-Only\n&Edit anyway\n&Recover\n&Quit\n&Abort");
3483                   char *but = _("&Open Read-Only\n&Edit anyway\n&Recover\n&Delete it\n&Quit\n&Abort");
>>>     CID 554963:           (FORWARD_NULL)
>>>     Passing null pointer "msg.items" to "do_dialog", which dereferences it.
3484                   choice = (sea_choice_T)do_dialog(VIM_WARNING, _("VIM - ATTENTION"), msg.items,
3485                                                    proc_running ? run_but : but, 1, NULL, false);
3486     
3487                   // compensate for missing "Delete it" button
3488                   choice += proc_running && choice >= 4;
3489                   // pretend screen didn't scroll, need redraw anyway
/src/nvim/memline.c: 3492             in findswapname()
3486     
3487                   // compensate for missing "Delete it" button
3488                   choice += proc_running && choice >= 4;
3489                   // pretend screen didn't scroll, need redraw anyway
3490                   msg_reset_scroll();
3491                 } else {
>>>     CID 554963:           (FORWARD_NULL)
>>>     Passing null pointer "msg.items" to "msg_outtrans", which dereferences it.
3492                   msg_outtrans(msg.items, 0, false);
3493                 }
3494                 no_wait_return--;
3495                 kv_destroy(msg);
3496                 xfree(fhname);
3497               }
```

Code after:
              && has_autocmd(EVENT_SWAPEXISTS, buf_fname, buf)) {
            choice = do_swapexists(buf, fname);
          }

          if (choice == SEA_CHOICE_NONE && swap_exists_action == SEA_READONLY) {
            // always open readonly.
            choice = SEA_CHOICE_READONLY;
          }

          proc_running = 0;  // Set by attention_message..swapfile_info.
          if (choice == SEA_CHOICE_NONE) {
            no_wait_return++;
            // Show info about the existing swapfile.
            StringBuilder msg = KV_INITIAL_VALUE;
            char *fhname = home_replace_save(NULL, fname);
            attention_message(buf, fname, fhname, &msg);

            // We don't want a 'q' typed at the more-prompt
            // interrupt loading a file.
            got_int = false;

            // If vimrc has "simalt ~x" we don't want it to
            // interfere with the prompt here.
            flush_buffers(FLUSH_TYPEAHEAD);

            if (swap_exists_action != SEA_NONE) {
              kv_printf(msg, _("Swap file \""));
              kv_printf(msg, "%s", fhname);
              kv_printf(msg, _("\" already exists!"));
              char *run_but = _("&Open Read-Only\n&Edit anyway\n&Recover\n&Quit\n&Abort");
              char *but = _("&Open Read-Only\n&Edit anyway\n&Recover\n&Delete it\n&Quit\n&Abort");
              choice = (sea_choice_T)do_dialog(VIM_WARNING, _("VIM - ATTENTION"), msg.items,
                                               proc_running ? run_but : but, 1, NULL, false);

              // compensate for missing "Delete it" button
              choice += proc_running && choice >= 4;
              // pretend screen didn't scroll, need redraw anyway
              msg_reset_scroll();
            } else {
              msg_outtrans(msg.items, 0, false);
            }
            no_wait_return--;
            kv_destroy(msg);
            xfree(fhname);
          }

          switch (choice) {
          case SEA_CHOICE_READONLY:  // "Open Read-Only"
            buf->b_p_ro = true;
            break;
          case SEA_CHOICE_EDIT:  // "Edit anyway"