Skip to content

linux: fix calculating size incorrectly and handle read errors while reading environment - #2134

Closed
dasha-uwu wants to merge 1 commit into
htop-dev:mainfrom
dasha-uwu:environ-size
Closed

dasha-uwu wants to merge 1 commit into
htop-dev:mainfrom
dasha-uwu:environ-size

Conversation

@dasha-uwu

Copy link
Copy Markdown
  1. Extra size += bytes statement at line 548 advanced size past valid data, because the last do-while loop body already did size += bytes for the same bytes value

  2. The if (bytes < 0) block was unreachable because fread can't return < 0, replaced with detecting errors with ferror

  3. Rewrite the read loop for clarity

@coderabbitai

coderabbitai Bot commented Oct 13, 2026

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 1898fd34-3087-41f2-bb5f-37b610e1fbdb
📥 Commits

Reviewing files that changed from the base of the PR and between 44a59cf and 0220cbf.

📒 Files selected for processing (1)
  • linux/Platform.c

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

📝 Walkthrough

Platform_getProcessEnv now reads the process environment in chunks until fread returns fewer bytes than requested. It checks ferror after the loop. On a read error, it closes the file, frees the buffer, and returns NULL.

Suggested reviewers: germanaizek

Priority: ⬇️ Low

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 0220c

The environment reader preserves its data at chunk boundaries and handles read errors; no actionable merge risk was identified in the reviewed change.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Chunks pass through the reading stream
Each byte count updates the buffer
A short read brings the loop to rest
Read errors close the file
The buffer is freed, and NULL returns

Comment @coderabbitai help to get the list of available commands.

@BenBE BenBE added bug 🐛 Something isn't working Linux 🐧 Linux related issues labels Oct 13, 2026
@BenBE

BenBE commented Oct 16, 2026

Copy link
Copy Markdown
Member

Superseeded by cb613e6.

@BenBE BenBE closed this Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 🐛 Something isn't working Linux 🐧 Linux related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants