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

Replace fgetsx() by fgets(3) and fputsx() by fputs(3) #1056

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from

Commits on Oct 15, 2024

  1. lib/, src/: Use strsep(3) instead of strtok(3)

    Signed-off-by: Alejandro Colomar <[email protected]>
    alejandro-colomar committed Oct 15, 2024
    Configuration menu
    Copy the full SHA
    b87f79c View commit details
    Browse the repository at this point in the history
  2. lib/, src/: Use str[n]cmp(3) instead of explicit byte comparisons

    This is simpler to read, IMO.
    
    Signed-off-by: Alejandro Colomar <[email protected]>
    alejandro-colomar committed Oct 15, 2024
    Configuration menu
    Copy the full SHA
    ee5bceb View commit details
    Browse the repository at this point in the history
  3. contrib/, lib/, src/: Use consistent style using strchr(3) in conditi…

    …onals
    
    For negative matches, use
    	if (strchr(...) == NULL)
    
    For positive matches, use the cast-to-bool operator:
    	if (!!strchr(...))
    
    For positive matches, when a variable is also set, use
    	while (NULL != (p = strchr(...)))
    
    Signed-off-by: Alejandro Colomar <[email protected]>
    alejandro-colomar committed Oct 15, 2024
    Configuration menu
    Copy the full SHA
    2f753cf View commit details
    Browse the repository at this point in the history
  4. lib/fields.c: Remove dead code

    A few lines above, we've removed the '\n' already.
    
    Signed-off-by: Alejandro Colomar <[email protected]>
    alejandro-colomar committed Oct 15, 2024
    Configuration menu
    Copy the full SHA
    aa3f0f9 View commit details
    Browse the repository at this point in the history
  5. lib/gshadow.c: endsgent(): Invert logic to reduce indentation

    Signed-off-by: Alejandro Colomar <[email protected]>
    alejandro-colomar committed Oct 15, 2024
    Configuration menu
    Copy the full SHA
    2b6a141 View commit details
    Browse the repository at this point in the history
  6. contrib/, lib/, src/: Consistently use sizeof() as if it were a function

    sizeof(foo)
    
    -  No spaces.
    	Not:  sizeof (foo)
    -  Parentheses.
    	Not:  sizeof foo
    -  No parentheses wrapping sizeof itself
    	Not:  (sizeof foo)
    
    This patch can be approximated with the following semantic patch:
    
    	$ cat ~/tmp/spatch/sizeof.sp
    	@@
    	identifier a, b;
    	@@
    
    	- sizeof a->b
    	+ sizeof(a->b)
    
    	@@
    	identifier a, b;
    	@@
    
    	- sizeof a.b
    	+ sizeof(a.b)
    
    	@@
    	identifier x;
    	@@
    
    	- sizeof x
    	+ sizeof(x)
    
    	@@
    	identifier x;
    	@@
    
    	- sizeof *x
    	+ sizeof(*x)
    
    	@@
    	identifier x;
    	@@
    
    	- (sizeof(x))
    	+ sizeof(x)
    
    	@@
    	identifier x;
    	@@
    
    	- (sizeof(*x))
    	+ sizeof(*x)
    
    Applied as
    
    	$ find contrib/ lib* src/ -type f \
    	| xargs spatch --sp-file ~/tmp/spatch/sizeof.sp --in-place;
    
    The differences between the actual patch and the approximation via the
    semantic patch from above are whitespace only.  When reviewing, it'll
    be useful to diff with '-w'.
    
    Link: <https://lkml.org/lkml/2012/7/11/103>
    Signed-off-by: Alejandro Colomar <[email protected]>
    alejandro-colomar committed Oct 15, 2024
    Configuration menu
    Copy the full SHA
    61bc9a0 View commit details
    Browse the repository at this point in the history
  7. lib/, src/: Remove useless casts in fgets(3)

    This patch can be replicated with the following semantic patch:
    
    	$ cat fgets_cast.sp
    	@@
    	expression a, b, c;
    	@@
    
    	- fgets(a, (int) (b), c)
    	+ fgets(a, b, c)
    
    	@@
    	expression a, b, c;
    	@@
    
    	- fgets(a, (int) b, c)
    	+ fgets(a, b, c)
    
    	@@
    	expression a, b, c;
    	@@
    
    	- fgetsx(a, (int) (b), c)
    	+ fgetsx(a, b, c)
    
    	@@
    	expression a, b, c;
    	@@
    
    	- fgetsx(a, (int) b, c)
    	+ fgetsx(a, b, c)
    
    	@@
    	expression a, b, c, p;
    	@@
    
    	- p->fgets(a, (int) (b), c)
    	+ p->fgets(a, b, c)
    
    	@@
    	expression a, b, c, p;
    	@@
    
    	- p->fgets(a, (int) b, c)
    	+ p->fgets(a, b, c)
    
    which is applied as:
    
    	$ find lib* src/ -type f \
    	| xargs spatch --sp-file ~/tmp/spatch/fgets_cast.sp --in-place;
    
    Signed-off-by: Alejandro Colomar <[email protected]>
    alejandro-colomar committed Oct 15, 2024
    Configuration menu
    Copy the full SHA
    ca165cc View commit details
    Browse the repository at this point in the history
  8. lib/, src/: Consistently use NULL with fgets(3)

    fgets(3) returns either NULL or the input pointer.  Checking for NULL is
    more explicit, and simpler.
    
    <stddef.h> is the header that provides NULL; add it where appropriate.
    
    The meat of this patch can be approximated with the following semantic
    patch:
    
    	$ cat ~/tmp/spatch/fgets_null.sp
    	@@
    	expression a, b, c;
    	@@
    
    	- fgets(a, b, c) == a
    	+ fgets(a, b, c) != NULL
    
    	@@
    	expression a, b, c;
    	@@
    
    	- fgetsx(a, b, c) == a
    	+ fgetsx(a, b, c) != NULL
    
    	@@
    	expression a, b, c, p;
    	@@
    
    	- p->fgets(a, b, c) == a
    	+ p->fgets(a, b, c) != NULL
    
    	@@
    	expression a, b, c;
    	@@
    
    	- fgets(a, b, c) != a
    	+ fgets(a, b, c) == NULL
    
    	@@
    	expression a, b, c;
    	@@
    
    	- fgetsx(a, b, c) != a
    	+ fgetsx(a, b, c) == NULL
    
    	@@
    	expression a, b, c, p;
    	@@
    
    	- p->fgets(a, b, c) != a
    	+ p->fgets(a, b, c) == NUL
    
    Applied as
    
    	$ find contrib/ lib* src/ -type f \
    	| xargs spatch --sp-file ~/tmp/spatch/fgets_null.sp --in-place;
    
    The differences between the actual patch and the approximation via the
    semantic patch from above are includes, whitespace, braces, and a case
    where there was an implicit pointer-to-bool comparison which I made
    explicit.  When reviewing, it'll be useful to use git-diff(1) with '-w'
    and '--color-words=.'.
    
    Signed-off-by: Alejandro Colomar <[email protected]>
    alejandro-colomar committed Oct 15, 2024
    Configuration menu
    Copy the full SHA
    8929e11 View commit details
    Browse the repository at this point in the history
  9. lib/, po/: Remove fgetsx() and fputsx()

    It seems they never worked correctly.  Let's keep it simple and remove
    support for escaped newlines.
    
    Closes: <shadow-maint#1055>
    Reported-by: Chris Hofstaedtler <[email protected]>
    Signed-off-by: Alejandro Colomar <[email protected]>
    alejandro-colomar committed Oct 15, 2024
    Configuration menu
    Copy the full SHA
    fee111c View commit details
    Browse the repository at this point in the history
  10. lib/: Use getline(3) instead of its pattern

    Signed-off-by: Alejandro Colomar <[email protected]>
    alejandro-colomar committed Oct 15, 2024
    Configuration menu
    Copy the full SHA
    08d1534 View commit details
    Browse the repository at this point in the history
  11. lib/gshadow.c: fgetsgent(): Don't use static variables

    Reported-by: Chris Hofstaedtler <[email protected]>
    Signed-off-by: Alejandro Colomar <[email protected]>
    alejandro-colomar committed Oct 15, 2024
    Configuration menu
    Copy the full SHA
    b6b6a6b View commit details
    Browse the repository at this point in the history