Skip to content

fix(search): use wxUIntPtr for m_currentSearch to fix Windows EC search - #39

Merged
got3nks merged 1 commit into
amule-org:masterfrom
got3nks:fix/windows-search-currentSearch-type
Jun 9, 2026
Merged

fix(search): use wxUIntPtr for m_currentSearch to fix Windows EC search#39
got3nks merged 1 commit into
amule-org:masterfrom
got3nks:fix/windows-search-currentSearch-type

Conversation

@got3nks

@got3nks got3nks commented Jun 9, 2026

Copy link
Copy Markdown

Summary

Fixes the Windows-specific 0-results bug @ngosang reported on #31 — EC clients (amuleweb / amulecmd) returned 0 ed2k Local/Global results on Windows even though the daemon side correctly received the server's reply.

Root cause: LLP64 vs LP64

CSearchList::m_currentSearch is declared long (SearchList.h:217) but every other place this value flows uses wxUIntPtr (CSearchFile::m_searchID, std::map<wxUIntPtr, CSearchResultList> m_results, GetSearchResults/RemoveResults parameters).

On Windows (LLP64), long is signed 32-bit and wxUIntPtr is unsigned 64-bit. The EC search-start path does:

  1. m_currentSearch = *searchID where *searchID = 0xffffffff (uint32). Assignment to signed long overflows to -1.
  2. AddToList(new CSearchFile(..., m_currentSearch, ...))m_currentSearch (long = int32 = -1) implicitly converts to wxUIntPtr (uint64) via sign extension to 0xFFFFFFFFFFFFFFFF.
  3. So server-reply items end up in m_results[0xFFFFFFFFFFFFFFFF].

But Get_EC_Response_Search_Results looks up GetSearchResults(0xffffffff) — the literal is unsigned int, which zero-extends to wxUIntPtr 0x00000000FFFFFFFF. Different key. m_results.find(...) returns empty. amuleweb / amulecmd see 0 results.

Linux x64 (LP64): long is 64-bit, no overflow, the bit pattern matches the lookup. Bug invisible.

Why Kad searches still worked on Windows

Kad results path bypasses m_currentSearch: KademliaSearchKeyword(uint32_t searchID, ...) writes the result via CSearchFile's wxUIntPtr searchID ctor parameter directly, so the uint32_t -> wxUIntPtr zero-extension matches the lookup. The corrupted value of m_currentSearch is never read for Kad.

Fix

One line — declare m_currentSearch as wxUIntPtr instead of long:

-    long        m_currentSearch;
+    wxUIntPtr   m_currentSearch;

This matches the type of every other place the value flows, eliminating the signed-vs-unsigned width mismatch.

Verification on Windows ARM64 VM

Pre-fix amulecmd search local ubunturesults reports 0 hits despite the daemon having received and parsed 153 results from the server (confirmed via diagnostic logging in ProcessSearchAnswer).

Post-fix: search local ubuntu → 151 results returned. search global ubuntu → 272 results. Both Local and Global now work via EC on Windows.

Backward compat

Linux x64: unchanged. long was already 64-bit, the bit pattern was already correct. New type is the same bit width.

Windows: fixes the bug, no behavior change for any non-buggy case.

No protocol change, no client-side change.

On Windows (LLP64), `long` is signed 32-bit but `wxUIntPtr`
(the type of CSearchList::m_results keys and CSearchFile::m_searchID)
is unsigned 64-bit. When an EC client starts a Local or Global ed2k
search, `m_currentSearch = *searchID` stores 0xffffffff into a signed
32-bit long, overflowing to -1. The subsequent conversion to
`wxUIntPtr` for `m_results[m_currentSearch]` (via `CSearchFile`'s
ctor) sign-extends -1 to 0xFFFFFFFFFFFFFFFF, so the server reply
lands in `m_results[0xFFFFFFFFFFFFFFFF]`.

Lookups in `Get_EC_Response_Search_Results` use the literal
`0xffffffff` which is unsigned int -> wxUIntPtr zero-extension to
0x00000000FFFFFFFF. Different key. Items are unreachable.

Net effect: EC-driven ed2k searches return 0 results on Windows
even though the daemon-side server response was received and the
items were added to the searchlist (amule-project#31).

Linux x64 (LP64) is unaffected: `long` is 64-bit there, so the
overflow doesn't happen and the bit pattern matches the lookup
key.

Kad searches were also unaffected: Kad results go through
`KademliaSearchKeyword(uint32_t searchID, ...)` which writes the
result via `CSearchFile`'s `wxUIntPtr searchID` ctor parameter
directly -- uint32_t zero-extends to wxUIntPtr cleanly, no signed
long detour.

Fix: change `m_currentSearch` to `wxUIntPtr`, matching the type
of every other place the value flows (CSearchFile::m_searchID,
ResultMap keys, GetSearchResults/RemoveResults parameters). The
existing `-1` sentinel assignments still work (unsigned -1 wraps
to 0xFFFFFFFFFFFFFFFF on both platforms, no code paths compare
against -1 explicitly).
@got3nks
got3nks merged commit 6c748aa into amule-org:master Jun 9, 2026
10 checks passed
@got3nks
got3nks deleted the fix/windows-search-currentSearch-type branch June 9, 2026 17:55
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.

1 participant