Skip to content

Fix read_full to handle partial and interrupted reads in OSDHistory#75

Merged
NathanNeurotic merged 8 commits into
mainfrom
codex/refactor-read-call-to-ensure-buffer-safety
Jan 6, 2026
Merged

Fix read_full to handle partial and interrupted reads in OSDHistory#75
NathanNeurotic merged 8 commits into
mainfrom
codex/refactor-read-call-to-ensure-buffer-safety

Conversation

@NathanNeurotic

Copy link
Copy Markdown
Owner

Motivation

  • Codacy reported a potential buffer-bound/partial-read issue at src/OSDHistory.c:51 in the loop that performs read, which can be flagged when partial reads or interrupted syscalls are not explicitly handled.
  • The intent is to ensure the read loop always derives request length from the destination capacity and explicitly handles partial reads and interruptions.
  • Keep behavior equivalent while removing the static analysis warning and avoiding any new high/critical issues.

Description

  • Update read_full in src/OSDHistory.c to compute remaining = nbytes - got and pass that explicit bound to read, ensuring the requested length is always derived from the caller-provided buffer capacity.
  • Retry read when it returns -1 with errno == EINTR, treat zero or other errors as failures, and return -1 on error so callers can handle I/O failures explicitly.
  • No new headers or files were added and only src/OSDHistory.c was modified; existing callers (for example LoadHistoryFile) remain unchanged and continue to call read_full with a computed expected size.
  • The change makes bounds and partial-read handling explicit for static analysis while preserving previous runtime behavior.

Testing

  • No automated tests were executed for this change.

Codex Task

@codacy-production

codacy-production Bot commented Jan 6, 2026

Copy link
Copy Markdown

Codacy's Analysis Summary

0 new issue (≤ 0 issue)
0 new security issue
0 complexity
0 duplications

Review Pull Request in Codacy →

AI Reviewer available: add the codacy-review label to get contextual insights without leaving GitHub.

@NathanNeurotic NathanNeurotic merged commit 195a6db into main Jan 6, 2026
49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant