Skip to content

Conversation

Dennis40816
Copy link
Contributor

@Dennis40816 Dennis40816 commented Mar 6, 2025

This change corrects a bug in the do_size function and reformats qtest.c to comply with the updated clang-format configuration introduced in commit c9f7b87. The formatting update is required because clang-format will reject commits that do not conform to the enforced style.

In do_size, the error message incorrectly referenced argv[2], which is always NULL when argc is 2:

"The value of argv[argc] shall be a null pointer."
(ISO/IEC 9899:2011, Section 5.1.2.2.1)

Additionally, according to the C11 standard, passing a NULL pointer to '%s' results in undefined behavior:

"If an argument to a function has an invalid value (such as a value outside the domain of the function, or a pointer outside the address space of the program, or a null pointer, or a pointer to non-modifiable storage when the corresponding parameter is not const-qualified) or a type (after promotion) not expected by a function with variable number of arguments, the behavior is undefined."
(ISO/IEC 9899:2011, Section 7.1.4 - 1)

This update changes the argument to argv[1], ensuring the accuracy of the error message's meaning and that a valid pointer is always used.

Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebase the latest master branch.

Previously, the error message in 'do_size' referenced 'argv[2]' instead
of 'argv[1]'. Since 'argc' is at most 2 in this context, 'argv[2]' is
always null, as defined in Section 5.1.2.2.1 of the C11 standard. While
GCC prints "(null)" for a null pointer in '%s' formatting, this behavior
is implementation-defined. Other compilers may cause undefined behavior,
potentially leading to a segmentation fault.

This change ensures the correct argument is used, avoiding reliance on
implementation-specific behavior and preventing potential crashes.

Change-Id: I27748efd7c3d533659a6eda78f7c68ced2e78366
@jserv jserv merged commit 1cdb288 into sysprog21:master Mar 6, 2025
1 of 2 checks passed
@jserv
Copy link
Contributor

jserv commented Mar 6, 2025

Thank @Dennis40816 for contributing!

@Dennis40816 Dennis40816 deleted the pr branch March 19, 2025 00:45
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