Open Bug 1280750 Opened 4 years ago Updated 4 years ago

(coverity) uninitialized scalar variable: mailnews/imap/src/nsAutoSyncState.cpp: |rv| is not set always before returned as function value.

Categories

(MailNews Core :: Networking: IMAP, defect)

defect
Not set

Tracking

(Not tracked)

People

(Reporter: ishikawa, Unassigned)

References

(Blocks 1 open bug, )

Details

(Keywords: coverity, Whiteboard: CID 1137538)

Coverity found this:

|rv| is not initialized always.


 99 nsresult nsAutoSyncState::PlaceIntoDownloadQ(const nsTArray<nsMsgKey> &aMsgKeyList)
100 {
   1. var_decl: Declaring variable rv without initializer.
101  nsresult rv;
   2. Condition !aMsgKeyList->IsEmpty(), taking false branch
102  if (!aMsgKeyList.IsEmpty())
103  {
104    nsCOMPtr <nsIMsgFolder> folder = do_QueryReferent(mOwnerFolder, &rv);
105    NS_ENSURE_SUCCESS(rv, rv);
106        
107    nsCOMPtr<nsIMsgDatabase> database;
108    rv = folder->GetMsgDatabase(getter_AddRefs(database));
109    if (!database)
110      return NS_ERROR_FAILURE;
111    
112    nsCOMPtr<nsIAutoSyncManager> autoSyncMgr = do_GetService(NS_AUTOSYNCMANAGER_CONTRACTID, &rv);
113    NS_ENSURE_SUCCESS(rv,rv);
114    
115    nsCOMPtr<nsIAutoSyncMsgStrategy> msgStrategy;
116    autoSyncMgr->GetMsgStrategy(getter_AddRefs(msgStrategy));
117    
118    // increase the array size
119    mDownloadQ.SetCapacity(mDownloadQ.Length() + aMsgKeyList.Length());
120    
121    // remove excluded messages
122    int32_t elemCount = aMsgKeyList.Length();
123    for (int32_t idx = 0; idx < elemCount; idx++)
124    {
125      nsCOMPtr<nsIMsgDBHdr> hdr;
126      bool containsKey;
127      database->ContainsKey(aMsgKeyList[idx], &containsKey);
128      if (!containsKey)
129        continue;
130      rv = database->GetMsgHdrForKey(aMsgKeyList[idx], getter_AddRefs(hdr));
131      if(!hdr)
132        continue; // can't get message header, continue with the next one
133      
134      bool doesFit = true;
135      rv = autoSyncMgr->DoesMsgFitDownloadCriteria(hdr, &doesFit);
136      if (NS_SUCCEEDED(rv) && !mDownloadSet.Contains(aMsgKeyList[idx]) && doesFit)
137      {
138        bool excluded = false;
139        if (msgStrategy)
140        {
141          rv = msgStrategy->IsExcluded(folder, hdr, &excluded);
142          
143          if (NS_SUCCEEDED(rv) && !excluded)
144          {
145            mIsDownloadQChanged = true;
146            mDownloadSet.PutEntry(aMsgKeyList[idx]);
147            mDownloadQ.AppendElement(aMsgKeyList[idx]);
148          }
149        }
150      }
151    }//endfor
152
153    if (mIsDownloadQChanged)
154    {
155      LogOwnerFolderName("Download Q is created for ");
156      LogQWithSize(mDownloadQ, 0);
157      rv = autoSyncMgr->OnDownloadQChanged(this);
158    }
159    
160  }
   CID 1137538 (#1 of 1): Uninitialized scalar variable (UNINIT)3. uninit_use: Using uninitialized value rv.
161  return rv;
162}
163

Observation:

We need to figure out what value we should return if
aMsgKeyList.IsEmpty() is true.

Also, we may need to figure out what value of |rv| should be returned in case !aMsgKeyListEmpty(). There are obviously
|rv| not set in the code path.
Component: Backend → Networking: IMAP
You need to log in before you can comment on or make changes to this bug.