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

fix(DiskIO): fix readlink #664

Merged
merged 1 commit into from
Dec 18, 2023
Merged

Conversation

apocelipes
Copy link
Contributor

No description provided.

@CarterLi
Copy link
Member

You fix what?

@apocelipes
Copy link
Contributor Author

apocelipes commented Dec 18, 2023

char pathSysDeviceReal[PATH_MAX] = "";

equals to

char pathSysDeviceReal[PATH_MAX];
pathSysDeviceReal = 0;

and the manpages said:

readlink() does not append a null byte to buf.

So, if readlink success, we got a invalid Null-terminated string.

@apocelipes
Copy link
Contributor Author

Or, if use this:

char pathSysDeviceReal[PATH_MAX] = { '\0' };

It will zero-filled by memset or other functions. Since PATH_MAX on some Linux distros are set to 4096, it could be a noticeable cost.

@CarterLi
Copy link
Member

@apocelipes
Copy link
Contributor Author

image

In https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf, Page 127

This since C11, this project using C11, so, it will be zero-filled, and in most cases it's unnecessary.

@CarterLi
Copy link
Member

This since C11

Citation needed

@CarterLi
Copy link
Member

And even if you want to "fix" this, the same code in physical_linux.c (committed today) should be fixed too.

@CarterLi CarterLi merged commit 70160d3 into fastfetch-cli:dev Dec 18, 2023
16 checks passed
@CarterLi
Copy link
Member

Please be cautious when using words like "bug" and "fix"

@apocelipes
Copy link
Contributor Author

This since C11

Citation needed

It's my miss, C99 said the same thing at 6.7.8-21, some old unix's CCs confuse me with their implement behaviors.

@apocelipes
Copy link
Contributor Author

Please be cautious when using words like "bug" and "fix"

Thank u, I see.

@apocelipes apocelipes deleted the minor-fixes branch December 18, 2023 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants