diff options
author | lurchi <lurchi@strangeplace.net> | 2019-06-27 11:37:34 +0200 |
---|---|---|
committer | lurchi <lurchi@strangeplace.net> | 2019-06-27 11:41:40 +0200 |
commit | 62fccf2d984f8e0d537fe919d095f3776bd3369c (patch) | |
tree | 8e66e89e32ab8b98debcb6eb87489f2a4f3f30aa /src/exit | |
parent | f54e8c82dc843aee294e61882d049b3870b458f0 (diff) | |
download | gnunet-62fccf2d984f8e0d537fe919d095f3776bd3369c.tar.gz gnunet-62fccf2d984f8e0d537fe919d095f3776bd3369c.zip |
make GNUNET_strlcpy more flexible by using strnlen instead of strlen
Diffstat (limited to 'src/exit')
-rw-r--r-- | src/exit/gnunet-helper-exit-windows.c | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/src/exit/gnunet-helper-exit-windows.c b/src/exit/gnunet-helper-exit-windows.c index 85a06c539..2e4b5f4a2 100644 --- a/src/exit/gnunet-helper-exit-windows.c +++ b/src/exit/gnunet-helper-exit-windows.c | |||
@@ -252,15 +252,12 @@ typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL); | |||
252 | 252 | ||
253 | 253 | ||
254 | /** | 254 | /** |
255 | * Like strlcpy but portable. The given string @a src is copied in full length | 255 | * Like strlcpy but portable. The given string @a src is copied until its null |
256 | * (until its null byte). The destination buffer is guaranteed to be | 256 | * byte or until @a n - 1 bytes have been read. The destination buffer is |
257 | * null-terminated. | 257 | * guaranteed to be null-terminated. |
258 | * | 258 | * |
259 | * to a destination buffer | 259 | * @param dst destination of the copy (must be @a n bytes long) |
260 | * and ensures that the destination string is null-terminated. | 260 | * @param src source of the copy (at most @a n - 1 bytes will be read) |
261 | * | ||
262 | * @param dst destination of the copy | ||
263 | * @param src source of the copy, must be null-terminated | ||
264 | * @param n the length of the string to copy, including its terminating null | 261 | * @param n the length of the string to copy, including its terminating null |
265 | * byte | 262 | * byte |
266 | * @return the length of the string that was copied, excluding the terminating | 263 | * @return the length of the string that was copied, excluding the terminating |
@@ -273,11 +270,10 @@ GNUNET_strlcpy(char *dst, const char *src, size_t n) | |||
273 | size_t slen; | 270 | size_t slen; |
274 | 271 | ||
275 | GNUNET_assert (0 != n); | 272 | GNUNET_assert (0 != n); |
276 | ret = strlen (src); | 273 | slen = strnlen (src, n - 1); |
277 | slen = GNUNET_MIN (ret, n - 1); | ||
278 | memcpy (dst, src, slen); | 274 | memcpy (dst, src, slen); |
279 | dst[slen] = '\0'; | 275 | dst[slen] = '\0'; |
280 | return ret; | 276 | return slen; |
281 | } | 277 | } |
282 | 278 | ||
283 | 279 | ||