fix(who): prevent integer overflow in limit calculations

When `--limit` is omitted, the default value is `usize::MAX` to mean
"unlimited". The previous code used `(limit + 1) as i64` to fetch one
extra row for "has more" detection. This caused integer overflow:

  usize::MAX + 1 = 0  (wraps around)

The resulting `LIMIT 0` clause returned zero rows, making the `who`
subcommands appear to find nothing even when data existed.

Fix: Use `saturating_add(1)` to cap at `usize::MAX` instead of wrapping,
then `.min(i64::MAX as usize)` to ensure the value fits in SQLite's
signed 64-bit LIMIT parameter.

Includes regression tests that verify `usize::MAX` limit returns results.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
teernisse
2026-03-02 09:33:01 -05:00
parent 3f38b3fda7
commit b67bb8754c
3 changed files with 41 additions and 2 deletions

View File

@@ -16,7 +16,9 @@ pub(super) fn query_workload(
limit: usize,
include_closed: bool,
) -> Result<WorkloadResult> {
let limit_plus_one = (limit + 1) as i64;
// Prevent overflow: saturating_add caps at usize::MAX instead of wrapping to 0.
// The .min() ensures the value fits in i64 for SQLite's LIMIT clause.
let limit_plus_one = limit.saturating_add(1).min(i64::MAX as usize) as i64;
// Query 1: Open issues assigned to user
let issues_sql = "SELECT i.iid,