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

Add -Wsign-compare to the project's CFLAGS #118

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Commits on Mar 2, 2018

  1. Add -Wsign-compare to the project's CFLAGS

    The lttng-tools code base has many erroneous comparisons between
    signed and unsigned values.
    
    While some uses are benign, like using a signed integer to loop
    between 0 and sizeof(struct some_structure), there are many
    cases where the "signed integer" result of a syscall
    (e.g. sendmsg, recvmsg, read, write) is compared to an expected
    structure size using sizeof, which returns a result of type
    size_t.
    
    The following pattern:
    
    ret = sendmsg(...);
    if (ret < sizeof(struct some_structure)) {
    	/* Handle error. */
    }
    
    is common and _unsafe_ if the intention is to check for an error
    (-1) and that the operation was completed (ret == sizeof(...)).
    
    Follow-up patches address the various instances of the problem.
    
    The "Clean-up:" prefix is used when the comparison was safe
    and the change is mainly done to silence the warning.
    
    The "Fix:" prefix is used when the commit fixes an unsafe
    comparison and should be backported to previous versions.
    
    Signed-off-by: Jérémie Galarneau <[email protected]>
    jgalar committed Mar 2, 2018
    Configuration menu
    Copy the full SHA
    597cde7 View commit details
    Browse the repository at this point in the history