Skip to content

Commit

Permalink
lib/: Use ATTR_STRING() on stpecpy() and strtcpy()
Browse files Browse the repository at this point in the history
These functions consume a source string.  Document that.  There's no way
to mark that they also produce a string in dst, though.  That will be up
to the static analyzer to guess.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
  • Loading branch information
alejandro-colomar authored and ikerexxe committed Dec 4, 2023
1 parent a61cf00 commit 93a5c47
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/string/stpecpy.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@
#include <stddef.h>
#include <string.h>

#include "attr.h"


ATTR_STRING(3)
inline char *stpecpy(char *dst, char *end, const char *restrict src);


/*
* SYNOPSIS
* [[gnu::null_terminated_string_arg(3)]]
* char *_Nullable stpecpy(char *_Nullable dst, char end[0],
* const char *restrict src);
*
Expand Down
4 changes: 4 additions & 0 deletions lib/string/strtcpy.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@
#include <string.h>
#include <sys/types.h>

#include "attr.h"
#include "defines.h"
#include "sizeof.h"


/*
* SYNOPSIS
* [[gnu::null_terminated_string_arg(2)]]
* int STRTCPY(char dst[restrict], const char *restrict src);
*
* ARGUMENTS
Expand Down Expand Up @@ -47,6 +50,7 @@
#define STRTCPY(dst, src) strtcpy(dst, src, NITEMS(dst))


ATTR_STRING(2)
inline ssize_t strtcpy(char *restrict dst, const char *restrict src,
size_t dsize);

Expand Down

0 comments on commit 93a5c47

Please sign in to comment.