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

lib/: Use NITEMS() instead of SIZEOF_ARRAY() where number of elements is meant #849

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/strtcpy.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* at the buffer pointed to by dst. If the destination buffer,
* isn't large enough to hold the copy, the resulting string is
* truncated. The size of the buffer is calculated internally via
* SIZEOF_ARRAY().
* NITEMS().
*
* RETURN VALUE
* -1 If this call truncated the resulting string.
Expand All @@ -44,7 +44,7 @@
*/


#define STRTCPY(dst, src) strtcpy(dst, src, SIZEOF_ARRAY(dst))
#define STRTCPY(dst, src) strtcpy(dst, src, NITEMS(dst))
hallyn marked this conversation as resolved.
Show resolved Hide resolved


inline ssize_t strtcpy(char *restrict dst, const char *restrict src,
Expand Down
2 changes: 1 addition & 1 deletion lib/utmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ static
#ifdef HAVE_STRUCT_UTMP_UT_HOST
} else if ( (NULL != ut)
&& ('\0' != ut->ut_host[0])) {
hostname = XMALLOC(SIZEOF_ARRAY(ut->ut_host) + 1, char);
hostname = XMALLOC(NITEMS(ut->ut_host) + 1, char);
hallyn marked this conversation as resolved.
Show resolved Hide resolved
ZUSTR2STP(hostname, ut->ut_host);
#endif /* HAVE_STRUCT_UTMP_UT_HOST */
}
Expand Down
6 changes: 3 additions & 3 deletions lib/zustr2stp.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
({ \
static_assert(!is_array(dst) || sizeof(dst) > SIZEOF_ARRAY(src), ""); \
\
zustr2stp(dst, src, SIZEOF_ARRAY(src)); \
zustr2stp(dst, src, NITEMS(src)); \
})


Expand Down Expand Up @@ -62,9 +62,9 @@ inline char *zustr2stp(char *restrict dst, const char *restrict src, size_t sz);
*
* EXAMPLES
* char src[13] = "Hello, world!" // No '\0' in this buffer!
* char dst[SIZEOF_ARRAY(src) + 1];
* char dst[NITEMS(src) + 1];
*
* zustr2stp(dst, src, SIZEOF_ARRAY(src));
* zustr2stp(dst, src, NITEMS(src));
* puts(dst);
*/

Expand Down