(coverity) uninitialized scalar value: /mailnews/imap/src/nsImapMailFolder.cpp: |rv| is not set a value before being returned in |return rv|

NEW
Unassigned

Status

2 years ago
2 years ago

People

(Reporter: ishikawa, Unassigned)

Tracking

(Blocks: 1 bug, {coverity})

Trunk
coverity

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: CID 1137537, URL)

(Reporter)

Description

2 years ago
Coverity found this:

|rv| is not initialized in an execution path before being returned as the function value.

4131nsresult nsImapMailFolder::MoveIncorporatedMessage(nsIMsgDBHdr *mailHdr,
4132                                                   nsIMsgDatabase *sourceDB,
4133                                                   const nsACString& destFolderUri,
4134                                                   nsIMsgFilter *filter,
4135                                                   nsIMsgWindow *msgWindow)
4136{
    1. var_decl: Declaring variable rv without initializer.
4137  nsresult rv;
    2. Condition this->m_moveCoalescer, taking false branch
4138  if (m_moveCoalescer)
4139  {
4140    nsCOMPtr<nsIRDFService> rdf(do_GetService(kRDFServiceCID, &rv));
4141    NS_ENSURE_SUCCESS(rv, rv);
4142    nsCOMPtr<nsIRDFResource> res;
4143    rv = rdf->GetResource(destFolderUri, getter_AddRefs(res));
4144    if (NS_FAILED(rv))
4145      return rv;
4146
4147    nsCOMPtr<nsIMsgFolder> destIFolder(do_QueryInterface(res, &rv));
4148    if (NS_FAILED(rv))
4149      return rv;
4150
4151    if (destIFolder)
4152    {
4153      // check if the destination is a real folder (by checking for null parent)
4154      // and if it can file messages (e.g., servers or news folders can't file messages).
4155      // Or read only imap folders...
4156      bool canFileMessages = true;
4157      nsCOMPtr<nsIMsgFolder> parentFolder;
4158      destIFolder->GetParent(getter_AddRefs(parentFolder));
4159      if (parentFolder)
4160        destIFolder->GetCanFileMessages(&canFileMessages);
4161      if (filter && (!parentFolder || !canFileMessages))
4162      {
4163        filter->SetEnabled(false);
4164        m_filterList->SaveToDefaultFile();
4165        destIFolder->ThrowAlertMsg("filterDisabled",msgWindow);
4166        return NS_MSG_NOT_A_MAIL_FOLDER;
4167      }
4168      // put the header into the source db, since it needs to be there when we copy it
4169      // and we need a valid header to pass to StartAsyncCopyMessagesInto
4170      nsMsgKey keyToFilter;
4171      mailHdr->GetMessageKey(&keyToFilter);
4172
4173      if (sourceDB && destIFolder)
4174      {
4175        bool imapDeleteIsMoveToTrash = DeleteIsMoveToTrash();
4176        m_moveCoalescer->AddMove (destIFolder, keyToFilter);
4177        // For each folder, we need to keep track of the ids we want to move to that
4178        // folder - we used to store them in the MSG_FolderInfo and then when we'd finished
4179        // downloading headers, we'd iterate through all the folders looking for the ones
4180        // that needed messages moved into them - perhaps instead we could
4181        // keep track of nsIMsgFolder, nsTArray<nsMsgKey> pairs here in the imap code.
4182        // nsTArray<nsMsgKey> *idsToMoveFromInbox = msgFolder->GetImapIdsToMoveFromInbox();
4183        // idsToMoveFromInbox->AppendElement(keyToFilter);
4184        if (imapDeleteIsMoveToTrash)
4185        {
4186        }
4187        bool isRead = false;
4188        mailHdr->GetIsRead(&isRead);
4189        if (imapDeleteIsMoveToTrash)
4190          rv = NS_OK;
4191      }
4192    }
4193  }
4194
4195  // we have to return an error because we do not actually move the message
4196  // it is done async and that can fail
    CID 1137537 (#1 of 1): Uninitialized scalar variable (UNINIT)3. uninit_use: Using uninitialized value rv.
4197  return rv;
4198}

Observation:

I am not sure what the comment on 4195 and 4196 means.
Especially, the comment on 4196.
Does that mean we can't return an error value reliably???

4195  // we have to return an error because we do not actually move the message
4196  // it is done async and that can fail
You need to log in before you can comment on or make changes to this bug.