Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dont set errno = 0 #129

Open
rurban opened this issue Feb 20, 2023 · 2 comments
Open

dont set errno = 0 #129

rurban opened this issue Feb 20, 2023 · 2 comments
Assignees
Labels

Comments

@rurban
Copy link
Owner

rurban commented Feb 20, 2023

According to the C Standard (e.g., C99:7.5p3),

"The value of errno is zero at program startup, but is never set to zero by any library function."

$ git grep -n 'errno = 0' src

src/io/fopen_s.c:100:    errno = 0;
src/io/fprintf_s.c:95:    errno = 0;
src/io/freopen_s.c:104:    errno = 0;
src/io/fscanf_s.c:136:    errno = 0;
src/io/gets_s.c:148:    errno = 0;
src/io/scanf_s.c:136:    errno = 0;
src/io/sscanf_s.c:130:    errno = 0;
src/io/tmpfile_s.c:98:    errno = 0;
src/io/vfprintf_s.c:101:    errno = 0;
src/io/vfscanf_s.c:131:    errno = 0;
src/io/vprintf_s.c:87:    errno = 0;
src/io/vscanf_s.c:123:    errno = 0;
src/io/vsscanf_s.c:130:    errno = 0;
src/misc/bsearch_s.c:156:    errno = 0;
src/os/getenv_s.c:142:    errno = 0;
src/os/gmtime_s.c:124:    errno = 0;
src/os/localtime_s.c:126:    errno = 0;
src/str/strtok_s.c:259:    errno = 0;
src/str/vsnprintf_s.c:1186:    errno = 0;
src/str/vsprintf_s.c:115:        errno = 0;
src/wchar/fwprintf_s.c:112:    errno = 0;
src/wchar/fwscanf_s.c:108:        errno = 0;
src/wchar/fwscanf_s.c:137:    errno = 0;
src/wchar/mbsrtowcs_s.c:201:            errno = 0;
src/wchar/mbstowcs_s.c:183:    errno = 0;
src/wchar/mbstowcs_s.c:199:            errno = 0;
src/wchar/snwprintf_s.c:191:    errno = 0;
src/wchar/swprintf_s.c:192:    errno = 0;
src/wchar/swprintf_s.c:202:        errno = 0;
src/wchar/swprintf_s.c:217:            errno = 0; /* EOVERFLOW */
src/wchar/swscanf_s.c:137:    errno = 0;
src/wchar/vfwprintf_s.c:118:    errno = 0;
src/wchar/vfwscanf_s.c:112:        errno = 0;
src/wchar/vfwscanf_s.c:141:    errno = 0;
src/wchar/vsnwprintf_s.c:190:    errno = 0;
src/wchar/vswprintf_s.c:174:    errno = 0;
src/wchar/vswprintf_s.c:198:            errno = 0;
src/wchar/vswscanf_s.c:135:    errno = 0;
src/wchar/vwprintf_s.c:107:    errno = 0;
src/wchar/vwscanf_s.c:128:    errno = 0;
src/wchar/wcstok_s.c:267:    errno = 0;
src/wchar/wscanf_s.c:124:    errno = 0;

From https://www.bugseng.com/blog/c-standard-library-cannot-be-trusted-blindly

@rurban rurban self-assigned this Feb 20, 2023
@rurban rurban added the bug label Feb 20, 2023
@jleffler
Copy link

jleffler commented Feb 20, 2023 via email

rurban added a commit that referenced this issue Feb 23, 2023
rurban added a commit that referenced this issue Feb 23, 2023
rurban added a commit that referenced this issue Dec 22, 2023
rurban added a commit that referenced this issue Mar 8, 2024
@rurban rurban added this to the 3.9 milestone Mar 8, 2024
rurban added a commit that referenced this issue Mar 8, 2024
@rurban
Copy link
Owner Author

rurban commented Dec 26, 2024

According to the C Standard (e.g., C99:7.5p3),

"The value of errno is zero at program startup, but is never set to zero by any library function."

But this a libc, not just a common library. And the libc mandates to set errno on all cases a syscall fails. And to clear it before each syscall.

@rurban rurban added invalid and removed bug labels Dec 26, 2024
@rurban rurban modified the milestones: 3.9, 3.10 Dec 26, 2024
rurban added a commit that referenced this issue Dec 26, 2024
rurban added a commit that referenced this issue Dec 26, 2024
rurban added a commit that referenced this issue Dec 26, 2024
rurban added a commit that referenced this issue Dec 27, 2024
rurban added a commit that referenced this issue Dec 27, 2024
rurban added a commit that referenced this issue Dec 28, 2024
rurban added a commit that referenced this issue Dec 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants