Skip to content

easy timeouts, shrink expire timer indices - #22591

Closed
icing wants to merge 2 commits into
curl:masterfrom
icing:easy-shrink-expire-index
Closed

icing wants to merge 2 commits into
curl:masterfrom
icing:easy-shrink-expire-index

Conversation

@icing

@icing icing commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

The enum exire_id fits easily into a uint8_t. Use that type for storing expire timeout list indices.

The enum `exire_id` fits easily into a uint8_t. Use that
type for storing expire timeout list indices.
@icing
icing requested a review from bagder August 15, 2026 09:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR reduces the storage size of per-easy-handle timeout list indices by changing expire_timers.next[] and expire_timers.first from expire_id to uint8_t, since EXPIRE_LAST fits in a byte. This helps shrink struct expire_timers and the per-handle timeout bookkeeping footprint in the multi interface.

Changes:

  • Change struct expire_timers list linkage fields (next[], first) to uint8_t.
  • Update timeout list iteration and validation logic in lib/multi.c to use uint8_t indices.
  • Adjust timer tracing iteration in lib/curl_trc.c and parameter naming in lib/multiif.h.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
lib/urldata.h Shrinks timeout list linkage storage to uint8_t.
lib/multiif.h Renames Curl_expire_clear parameter for consistency (ideid).
lib/multi.c Updates timeout list walk/insert/remove code for byte-sized indices.
lib/curl_trc.c Updates verbose timer tracing loop variable to uint8_t.
Suppressed comments (2)

lib/multi.c:3712

  • timeouts->next is now a uint8_t indexed by the expire id, but this code still writes to timeouts->next[eid] (and does it twice). If an out-of-range expire_id is ever passed, the current cast-based check can wrap and this becomes an out-of-bounds write. Use a range check on eid before casting, and index next[] via the validated uint8_t id, with a single assignment.
  }
  timeouts->next[eid] = *anchor;
  timeouts->next[eid] = *anchor;
  *anchor = id;

lib/multi.c:3737

  • Curl_expire() performs its argument validation by first narrowing eid to uint8_t and then comparing. That allows values > 255 to wrap and evade the check. Validate eid before any narrowing (or just validate eid directly here, since the uint8_t copy is otherwise unused).
  uint8_t prev_id = timeouts->first, id = (uint8_t)eid;
  struct curltime set;

  if(id >= EXPIRE_LAST) {
    DEBUGASSERT(0);

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread lib/multi.c
Comment thread lib/urldata.h
@icing
icing requested a review from bagder August 15, 2026 11:18
@bagder bagder closed this in 787cbd2 Aug 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants