Skip to content

lib/string/strchr/: strnul(), streq(), strcaseeq(): Simplify implementations#1546

Open
alejandro-colomar wants to merge 2 commits intoshadow-maint:masterfrom
alejandro-colomar:strnul
Open

lib/string/strchr/: strnul(), streq(), strcaseeq(): Simplify implementations#1546
alejandro-colomar wants to merge 2 commits intoshadow-maint:masterfrom
alejandro-colomar:strnul

Conversation

@alejandro-colomar
Copy link
Collaborator

@alejandro-colomar alejandro-colomar commented Feb 19, 2026

Cc: @kees, @bhaible

This avoids an __auto_type local variable, and a GNU statement expression.


Revisions:

v1b
  • Rebase
$ git rd 
1:  35250c4b = 1:  f27656af lib/string/strchr/: strnul(): Simplify implementation
v2
  • Also simplify streq(3).
$ git rd 
1:  f27656af = 1:  f27656af lib/string/strchr/: strnul(): Simplify implementation
-:  -------- > 2:  ff33ecae lib/string/strcmp/: streq(): Simplify implementation
v3
  • Also simplify strcaseeq().
$ git rd 
1:  f27656af = 1:  f27656af lib/string/strchr/: strnul(): Simplify implementation
2:  ff33ecae ! 2:  3ecdb6a1 lib/string/strcmp/: streq(): Simplify implementation
    @@ Metadata
     Author: Alejandro Colomar <[email protected]>
     
      ## Commit message ##
    -    lib/string/strcmp/: streq(): Simplify implementation
    +    lib/string/strcmp/: str{,case}eq(): Simplify implementation
     
         A one-liner macro is simpler, and works just fine.
     
    @@ Commit message
     
         Signed-off-by: Alejandro Colomar <[email protected]>
     
    + ## lib/string/strcmp/strcaseeq.c ##
    +@@
    +-// SPDX-FileCopyrightText: 2024-2025, Alejandro Colomar <[email protected]>
    ++// SPDX-FileCopyrightText: 2024-2026, Alejandro Colomar <[email protected]>
    + // SPDX-License-Identifier: BSD-3-Clause
    + 
    + 
    + #include "config.h"
    + 
    +-#include <stdbool.h>
    +-
    + #include "string/strcmp/strcaseeq.h"
    +-
    +-
    +-extern inline bool strcaseeq(const char *s1, const char *s2);
    +
    + ## lib/string/strcmp/strcaseeq.h ##
    +@@
    +-// SPDX-FileCopyrightText: 2024-2025, Alejandro Colomar <[email protected]>
    ++// SPDX-FileCopyrightText: 2024-2026, Alejandro Colomar <[email protected]>
    + // SPDX-License-Identifier: BSD-3-Clause
    + 
    + 
    +@@
    + 
    + #include "config.h"
    + 
    +-#include <stdbool.h>
    + #include <strings.h>
    + 
    +-#include "attr.h"
    + 
    +-
    +-ATTR_STRING(1) ATTR_STRING(2)
    +-inline bool strcaseeq(const char *s1, const char *s2);
    +-
    +-
    +-// strings case-insensitive equal
    +-// streq(), but case-insensitive.
    +-inline bool
    +-strcaseeq(const char *s1, const char *s2)
    +-{
    +-  return strcasecmp(s1, s2) == 0;
    +-}
    ++// strcaseeq - strings case-insensitive equal
    ++#define strcaseeq(s1, s2)  (!strcasecmp(s1, s2))
    + 
    + 
    + #endif  // include guard
    +
      ## lib/string/strcmp/streq.c ##
     @@
     -// SPDX-FileCopyrightText: 2024, Alejandro Colomar <[email protected]>
v3b
  • Reviewed-by: @kees (I interpret this from his message and approval)
$ git rd 
1:  f27656af ! 1:  cd359d6c lib/string/strchr/: strnul(): Simplify implementation
    @@ Commit message
         This avoids an __auto_type local variable, and a GNU statement
         expression.
     
    +    Reviewed-by: Kees Cook <[email protected]>
         Signed-off-by: Alejandro Colomar <[email protected]>
     
      ## lib/string/strchr/strnul.h ##
2:  3ecdb6a1 ! 2:  a861778f lib/string/strcmp/: str{,case}eq(): Simplify implementation
    @@ Commit message
         detail; we could cast it to bool, but we don't really need that, so keep
         it simple.
     
    +    Reviewed-by: Kees Cook <[email protected]>
         Signed-off-by: Alejandro Colomar <[email protected]>
     
      ## lib/string/strcmp/strcaseeq.c ##

@alejandro-colomar alejandro-colomar self-assigned this Feb 19, 2026
@alejandro-colomar alejandro-colomar changed the title lib/string/strchr/: strnul(): Simplify implementation lib/string/strchr/: strnul(), streq(): Simplify implementation Feb 26, 2026
@alejandro-colomar alejandro-colomar changed the title lib/string/strchr/: strnul(), streq(): Simplify implementation lib/string/strchr/: strnul(), streq(), strcaseeq(): Simplify implementations Feb 26, 2026
Copy link

@kees kees left a comment

Choose a reason for hiding this comment

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

Looks like a nice cleanup to me.

@alejandro-colomar
Copy link
Collaborator Author

alejandro-colomar commented Feb 26, 2026

Looks like a nice cleanup to me.

@kees

Thanks! Should I interpret that as an Acked-by or Reviewed-by?

This avoids an __auto_type local variable, and a GNU statement
expression.

Reviewed-by: Kees Cook <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
A one-liner macro is simpler, and works just fine.

We don't need the function at all, since we don't use it as a callback.
The macro changes the return type, but we don't really care about that
detail; we could cast it to bool, but we don't really need that, so keep
it simple.

Reviewed-by: Kees Cook <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
@alejandro-colomar
Copy link
Collaborator Author

alejandro-colomar commented Feb 27, 2026

@hallyn , would you mind merging? This is approved by @kees .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants