Skip to content

Fixed <stdio.h> file and dereferencing bugs#807

Merged
mateoconlechuga merged 1 commit into
masterfrom
stdio_patch
Jun 27, 2026
Merged

Fixed <stdio.h> file and dereferencing bugs#807
mateoconlechuga merged 1 commit into
masterfrom
stdio_patch

Conversation

@ZERICO2005

@ZERICO2005 ZERICO2005 commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Fixed the following issues:

[P2] clearerr indexes file streams off by one: src/libc/clearerr.c:13. fopen stores slot 1 at _file_streams[0], but clearerr uses _file_streams[stream->slot]; slot 5 writes past FOPEN_MAX.
[P2] fread(stdin, ...) reports full success after EOF/partial reads: src/libc/fread.c:20. The loop stops on EOF but returns count unconditionally instead of completed elements.
[P2] fwrite(stdout, size=0, ...) divides by zero: src/libc/fwrite.c:17. For zero-sized writes, the loop does nothing, then returns num / size.

Also fixed:

  • Dereferencing FILE * stream when it is NULL, stdin, stdout, or stderr.
  • return value for fseek and ftell

Comment thread src/libc/include/stdio.h
Comment thread src/libc/clearerr.c
Comment thread src/libc/fclose.c
Comment thread src/libc/feof.c
Comment thread src/libc/fgetc.c
Comment thread src/libc/fread.c Outdated
Comment thread src/libc/fseek.c
Comment thread src/libc/ftell.c
Comment thread test/standalone/asprintf_fprintf/src/main.c
@ZERICO2005 ZERICO2005 marked this pull request as ready for review June 21, 2026 20:45
@mateoconlechuga mateoconlechuga merged commit d093e1b into master Jun 27, 2026
9 checks passed
@mateoconlechuga mateoconlechuga deleted the stdio_patch branch June 27, 2026 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

2 participants