Skip to content

verify if some objects are null - #212

Merged
mrjimenez merged 2 commits into
amule-project:masterfrom
sc0w:PR_pointernull
Jun 7, 2026
Merged

verify if some objects are null#212
mrjimenez merged 2 commits into
amule-project:masterfrom
sc0w:PR_pointernull

Conversation

@sc0w

@sc0w sc0w commented Aug 15, 2020

Copy link
Copy Markdown
Member

No description provided.

Comment thread src/ExternalConnector.cpp Outdated

wxString test(wxString(text, *wxConvCurrent).Lower());
while (nextCommand != curCommands->end()) {
while (curCommands && (nextCommand != curCommands->end())) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation for rl_completion_matches says that entry_func (i.e. command_completion() in this case) will first be called with state being zero on the first call, and non-zero on subsequent calls. Thus curCommands (and nextCommand, too) will always be initialized and non-zero on calls where state is non-zero.

Comment thread src/KnownFile.cpp Outdated
}
} else {
if (!pClient->SupportsLargeFiles()) {
if (pClient && (!pClient->SupportsLargeFiles())) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wxASSERT call on line 1093 properly checks for both pClient and pServer being non-null. However, only in debug builds (wxDEBUG enabled). That should be changed to something that works also in release builds (like wxCHECK_RET) and further checks can be omitted.

Comment thread src/SharedFileList.cpp Outdated
// - if the compressed size is still >= the original size, we send the uncompressed packet
// therefor we always try to compress the packet
if (server->GetTCPFlags() & SRV_TCPFLG_COMPRESSION){
if (server && (server->GetTCPFlags() & SRV_TCPFLG_COMPRESSION)){

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First of all, this function should only be called when we're connected to a server. But just in case, if we are not connected (i.e. GetCurrentServer() returns NULL on line 707) we could bail out immediately, because SendPacket() will fail anyway at the end of the function. Of course that would render all further checks for server being non-null obsolete.

@mrjimenez
mrjimenez marked this pull request as draft June 1, 2026 23:14
@mrjimenez

Copy link
Copy Markdown
Contributor

I pushed a follow-up commit (5cc30c24) that addresses @gonosztopi's three inline review comments.

ExternalConnector.cpp — The curCommands && guard added by this PR is redundant. The else branch in the state == 0 block already returns NULL immediately when GetSubCommandsFor() returns null, so the while loop is only reachable with a valid curCommands pointer. The guard has been removed.

KnownFile.cpp — Instead of the inline pClient && guard, the existing wxASSERT at the top of CreateOfferedFilePacket has been promoted to wxCHECK_RET. This enforces the mutual-exclusion contract on pClient/pServer in release builds as well as debug, which is what the reviewer asked for. The redundant null guard is removed.

SharedFileList.cpp — An early return has been added immediately after GetCurrentServer() returns null, as suggested. This is cleaner than guarding individual uses of server inline, and it also simplifies the limit calculation (the ternary is no longer needed). The inline guard added by this PR is removed since it is now covered by the early return.

sc0w and others added 2 commits June 7, 2026 14:57
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.
@mrjimenez

Copy link
Copy Markdown
Contributor

The branch has been rebased onto upstream/master to resolve merge conflicts. The commit referenced in the previous comment (5cc30c24) no longer exists; the equivalent rebased commit is 5417d081.

@mrjimenez
mrjimenez dismissed gonosztopi’s stale review June 7, 2026 18:01

All three review points have been addressed in the rebased commits.

@mrjimenez
mrjimenez marked this pull request as ready for review June 7, 2026 18:07
@mrjimenez

Copy link
Copy Markdown
Contributor

@got3nks , I'd appreciate your review, in case I missed something.

@got3nks

got3nks commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

@mrjimenez — LGTM in spirit, one trailing cleanup. gonosztopi's review said the early return "would render all further checks for server being non-null obsolete." The ternary at line 1027 was simplified accordingly, but there's still one stale server && left a few lines down at line 1059:

if (!file->IsLargeFile() || (server && server->SupportsLargeFilesTCP())) {

After the early return, server is guaranteed non-null, so this collapses to:

if (!file->IsLargeFile() || server->SupportsLargeFilesTCP()) {

Defensive but redundant. Otherwise LGTM — happy to approve once this is in.

@mrjimenez
mrjimenez merged commit 0b2e936 into amule-project:master Jun 7, 2026
7 checks passed
@mrjimenez

Copy link
Copy Markdown
Contributor

Oops, misread the last line. I will open a new PR for the issue you raised.

mrjimenez added a commit that referenced this pull request Jun 7, 2026
SendListToServer() already returns early when GetCurrentServer()
yields NULL (added in the previous commit), so the `server &&`
guard in the SupportsLargeFilesTCP() check is now unreachable with
a null pointer and can be removed.

Follows up on review feedback from got3nks on PR #212.
ngosang added a commit to ngosang/amule that referenced this pull request Jun 20, 2026
…mplate (amule-project#212)

Add a master checkbox in the table header of the Downloads, Search and
Shared pages that toggles every row checkbox at once, instead of having
to tick files one by one.

- Add a JS selectAll(check) helper to each page that walks all
  input[type=checkbox] in the document and sets them to check.checked.
- Replace the empty header cell with <th class="al-left"> containing the
  master checkbox (onclick="selectAll(this)"). The al-left class matches
  the left alignment of the row checkbox cells, which <th> would
  otherwise center.
- Name the master checkbox selectAllFiles (not a 32-char hash) so the
  command-processing loop, which only acts on 32-char file-hash names,
  ignores it automatically.

No backend changes; all logic is client-side.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants