I was looking at the comment documenting these functions and noticed they don't use these attributes, despite both of them dereferencing their arguments unconditionally and last_component always returning a pointer into the given string. I suppose it is pretty obvious for humans, but this should hopefully help the compiler.
-- 8< -- * lib/basename-lgpl.h: Document the new attributes used by the file. (last_component): Declare function with _GL_ATTRIBUTE_NONNULL and _GL_ATTRIBUTE_RETURNS_NONNULL. (base_len): Declare function with _GL_ATTRIBUTE_NONNULL. --- ChangeLog | 8 ++++++++ lib/basename-lgpl.h | 9 ++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7ff0c48872..350e90b2c8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2026-10-31 Collin Funk <[email protected]> + + basename-lgpl: Declare functions with nonnull attributes. + * lib/basename-lgpl.h: Document the new attributes used by the file. + (last_component): Declare function with _GL_ATTRIBUTE_NONNULL and + _GL_ATTRIBUTE_RETURNS_NONNULL. + (base_len): Declare function with _GL_ATTRIBUTE_NONNULL. + 2026-10-30 Pádraig Brady <[email protected]> strftime: fix stale errno upon field width overflow diff --git a/lib/basename-lgpl.h b/lib/basename-lgpl.h index fa43cffb9c..b5abbebbc2 100644 --- a/lib/basename-lgpl.h +++ b/lib/basename-lgpl.h @@ -19,7 +19,8 @@ #ifndef _BASENAME_LGPL_H #define _BASENAME_LGPL_H -/* This file uses _GL_ATTRIBUTE_PURE. */ +/* This file uses _GL_ATTRIBUTE_PURE, _GL_ATTRIBUTE_NONNULL, + and _GL_ATTRIBUTE_RETURNS_NONNULL. */ #if !_GL_CONFIG_H_INCLUDED #error "Please include config.h first." #endif @@ -68,12 +69,14 @@ extern "C" { "/" "/" "//" "/" */ -extern char *last_component (char const *filename) _GL_ATTRIBUTE_PURE; +extern char *last_component (char const *filename) _GL_ATTRIBUTE_PURE + _GL_ATTRIBUTE_NONNULL () _GL_ATTRIBUTE_RETURNS_NONNULL; /* Return the length of the basename FILENAME. Typically FILENAME is the value returned by base_name or last_component. Act like strlen (FILENAME), except omit all trailing slashes. */ -extern size_t base_len (char const *filename) _GL_ATTRIBUTE_PURE; +extern size_t base_len (char const *filename) _GL_ATTRIBUTE_PURE + _GL_ATTRIBUTE_NONNULL (); #ifdef __cplusplus -- 2.56.0
