Skip to content

Item totals overflow past 2,147,483,647 (gil total wraps around with many characters/retainers) #381

Open

Description

@pipipi314159

Describe the bug
When the combined amount of an item across all characters, retainers and free company chests exceeds int.MaxValue (2,147,483,647), the "Total Quantity Available" / "Quantity" columns show a wrapped-around value. This is easy to hit with gil, since each character and retainer can hold up to 999,999,999.

To Reproduce
Steps to reproduce the behavior:

  1. Have characters/retainers whose combined gil is above 2,147,483,647 (each location must have been scanned by the plugin).
  2. Create a Curated List and add Gil to it.
  3. Look at the Available column.
  4. The value is wrong. For illustration: a true total of 3,000,000,000 would wrap to 3,000,000,000 − 2^32 = −1,294,967,296. Larger totals wrap around again and can come out as a plausible-looking but much smaller positive number, which is how I noticed it.

Expected behavior
The Available column shows the actual combined total.

Screenshots
N/A

Dalamud Information:
Allagan Tools v1.15.0.13
Testing enabled: No

Filter Issues
N/A. Not specific to a filter configuration; the totals themselves overflow.

Additional context

Cause: the totals are accumulated and returned as 32-bit integers (unchecked, so they silently wrap):

  • CriticalCommonLib/Services/InventoryMonitor.cs: _itemCounts / _characterItemCounts are Dictionary<..., int> (L23–24), filled with += (int)item.Quantity (L177, L185); IInventoryMonitor exposes them as int as well.
  • InventoryTools/Logic/Columns/QuantityAvailableColumn.cs (L25–29) and QuantityColumn.cs (L34, L61) derive from IntegerColumn (Column<int?>) and sum into an int.
  • InventoryTools/Logic/Editors/CharacterScopePicker.cs: CharacterScopeCalculator.Count returns uint and casts the summed value (L249–254, L334). Enumerable.Sum over int is checked, so a scoped Quantity column may throw an OverflowException instead of wrapping.
  • InventoryTools/Logic/Filters/QuantityFilter.cs (L47) sums into an int.
  • InventoryTools/Tooltips/AmountOwnedTooltip.cs (L114) uses uint storageCount.

Per-character/per-retainer counts are fine, because a single location can't exceed ~1 billion. Only the cross-character totals overflow.

Suggested fix: use long for the totals.

  • Change ItemCounts (and optionally CharacterItemCounts) to Dictionary<..., long>, or re-sum CharacterItemCounts into a long where totals are needed.
  • Add a LongColumn : Column<long?> (same as IntegerColumn; filtering can go through the existing decimal PassesFilter overload) and use it for QuantityColumn / QuantityAvailableColumn.
  • Return long from CharacterScopeCalculator.Count, and use long in QuantityFilter and the amount-owned tooltip.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Projects

  • Status
    Needs investigation/analysis

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions