xoofx / xoofx/LibObjectFile

public bool TryFindByCode(ulong code, out DwarfAbbreviationItem item) failed

Open
#28 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Help Welcome
Dominant language
C#
Stars
184
Forks
17
Avg merge
1d 3h
Merged PRs (30d)
1

Description

in DwarfAbbreviation.cs line 87;

   `public bool TryFindByCode(ulong code, out DwarfAbbreviationItem item)
    {
        item = null;
        if (code == 0)
        {
            return `false;
        }

        code--;

        if (_mapItems.Count > 0)
        {
            return _mapItems.TryGetValue(code, out item);
        }

        if (code < int.MaxValue && (int)code < _items.Count)
        {
            item = _items[(int) code];
            return true;
        }

        item = null;
        return false;
    }`

I found sometimes it failed at return _mapItems.TryGetValue(code, out item);
Then I fixed below; I do not konw if you have the same problem;

    `public` bool TryFindByCode(ulong code, out DwarfAbbreviationItem item)
    {
        item = null;
        if (code == 0)
        {
            return false;
        }

        //no need to minus 1
        //code--;

        if (_mapItems.Count > 0)
        {
            return _mapItems.TryGetValue(code, out item);
        }

        //if _mapItems is empty, try _items;
        if (code < int.MaxValue && (int)code <= _items.Count)
        {
            item = _items[(int) code - 1];
            return true;
        }

        item = null;
        return false;
    }

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with DwarfAbbreviation.cs around line 87 and inspect TryFindByCode, including how the map and list are used. Reproduce the reported failure and determine which code-to-item indexing behavior is expected; done means the method consistently returns the correct item or false, with a regression test covering the failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
reverse-engineering
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.