Skip to content

Commit 5cc30c2

Browse files
committed
Address reviewer feedback on null-pointer guards
ExternalConnector.cpp: remove redundant curCommands null guard; the else branch already returns NULL when curCommands is NULL, so the while loop is unreachable with a null pointer. KnownFile.cpp: replace wxASSERT with wxCHECK_RET so the mutual- exclusion check on pClient/pServer fires in release builds too, not only in debug. Drop the redundant pClient null guard added by the PR; the contract enforced at the function entry is sufficient. SharedFileList.cpp: bail out early when GetCurrentServer() returns NULL instead of guarding individual uses of server inline. The inline null guard added by the PR is removed since it is now covered by the early return.
1 parent 4b21c56 commit 5cc30c2

3 files changed

Lines changed: 8 additions & 5 deletions

File tree

src/ExternalConnector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ char *command_completion(const char *text, int state)
244244
}
245245

246246
wxString test(wxString(text, *wxConvCurrent).Lower());
247-
while (curCommands && (nextCommand != curCommands->end())) {
247+
while (nextCommand != curCommands->end()) {
248248
wxString curTest = (*nextCommand)->GetCommand();
249249
++nextCommand;
250250
if (curTest.Lower().StartsWith(test)) {

src/KnownFile.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,7 @@ void CKnownFile::CreateOfferedFilePacket(
10901090
// shared files to some other client. In each case we send our IP+Port only, if
10911091
// we have a HighID.
10921092

1093-
wxASSERT(!(pClient && pServer));
1093+
wxCHECK_RET(!(pClient && pServer), "pClient and pServer cannot both be non-null");
10941094

10951095
SetPublishedED2K(true);
10961096
files->WriteHash(GetFileHash());
@@ -1153,7 +1153,7 @@ void CKnownFile::CreateOfferedFilePacket(
11531153
tags.push_back(new CTagInt32(FT_FILESIZE_HI, (uint32)(GetFileSize() >> 32)));
11541154
}
11551155
} else {
1156-
if (pClient && (!pClient->SupportsLargeFiles())) {
1156+
if (!pClient->SupportsLargeFiles()) {
11571157
wxFAIL;
11581158
tags.push_back(new CTagInt32(FT_FILESIZE, 0));
11591159
} else {

src/SharedFileList.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -705,8 +705,11 @@ void CSharedFileList::SendListToServer(){
705705
// Limits for the server.
706706

707707
CServer* server = theApp->serverconnect->GetCurrentServer();
708+
if (!server) {
709+
return;
710+
}
708711

709-
uint32 limit = server ? server->GetSoftFiles() : 0;
712+
uint32 limit = server->GetSoftFiles();
710713
if( limit == 0 || limit > 200 ) {
711714
limit = 200;
712715
}
@@ -745,7 +748,7 @@ void CSharedFileList::SendListToServer(){
745748
// - this function is called once when connecting to a server and when a file becomes shareable - so, it's called rarely.
746749
// - if the compressed size is still >= the original size, we send the uncompressed packet
747750
// therefor we always try to compress the packet
748-
if (server && (server->GetTCPFlags() & SRV_TCPFLG_COMPRESSION)){
751+
if (server->GetTCPFlags() & SRV_TCPFLG_COMPRESSION){
749752
packet->PackPacket();
750753
}
751754

0 commit comments

Comments
 (0)