Skip to content
Open
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
2 changes: 2 additions & 0 deletions lib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ libshadow_la_SOURCES = \
string/strcmp/strneq.h \
string/strcmp/strprefix.c \
string/strcmp/strprefix.h \
string/strcpy/memcpy.c \
string/strcpy/memcpy.h \
string/strcpy/stpecpy.c \
string/strcpy/stpecpy.h \
string/strcpy/strncat.c \
Expand Down
7 changes: 7 additions & 0 deletions lib/string/strcpy/memcpy.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// SPDX-FileCopyrightText: 2025, Alejandro Colomar <[email protected]>
// SPDX-License-Identifier: BSD-3-Clause


#include "config.h"

#include "string/strcpy/memcpy.h"
26 changes: 26 additions & 0 deletions lib/string/strcpy/memcpy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-FileCopyrightText: 2025, Alejandro Colomar <[email protected]>
// SPDX-License-Identifier: BSD-3-Clause


#ifndef SHADOW_INCLUDE_LIB_STRING_STRCPY_MEMCPY_H_
#define SHADOW_INCLUDE_LIB_STRING_STRCPY_MEMCPY_H_


#include "config.h"

#include <string.h>

#include "sizeof.h"

#include <assert.h>


#define MEMCPY(dst, src) \
({ \
static_assert(SIZEOF_ARRAY(dst) == SIZEOF_ARRAY(src), ""); \
\
memcpy(dst, src, SIZEOF_ARRAY(dst)); \
})


#endif // include guard
6 changes: 2 additions & 4 deletions lib/utmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "string/strcmp/streq.h"
#include "string/strcmp/strneq.h"
#include "string/strcmp/strprefix.h"
#include "string/strcpy/memcpy.h"
#include "string/strcpy/strncpy.h"
#include "string/strcpy/strtcpy.h"
#include "string/strdup/strdup.h"
Expand Down Expand Up @@ -335,10 +336,7 @@ prepare_utmp(const char *name, const char *line, const char *host,
} else if (info->ai_family == AF_INET6) {
struct sockaddr_in6 *sa =
(struct sockaddr_in6 *) info->ai_addr;
memcpy (utent->ut_addr_v6,
&(sa->sin6_addr),
MIN (sizeof (utent->ut_addr_v6),
sizeof (sa->sin6_addr)));
MEMCPY(utent->ut_addr_v6, sa->sin6_addr.s6_addr);
# endif
}
freeaddrinfo (info);
Expand Down
Loading