| 1 | /* Copyright (C) 2018-2019 Björn Esser <[email protected]> |
| 2 | * |
| 3 | * Redistribution and use in source and binary forms, with or without |
| 4 | * modification, are permitted. |
| 5 | * |
| 6 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
| 7 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 8 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 9 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
| 10 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 11 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 12 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 13 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 14 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 15 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 16 | * SUCH DAMAGE. |
| 17 | */ |
| 18 | |
| 19 | /* Simple commonly used helper functions. */ |
| 20 | |
| 21 | #include "crypt-port.h"cxx . . $ `<file>/lib/crypt-port.h`/ |
| 22 | |
| 23 | #include <stdlib.h> |
| 24 | |
| 25 | /* Provide a safe way to copy strings with the guarantee src, |
| 26 | including its terminating '\0', will fit d_size bytes. |
| 27 | The trailing bytes of d_size will be filled with '\0'. |
| 28 | dst and src must not be NULL. Returns strlen (src). */ |
| 29 | size_tcxx . . $ size_t# |
| 30 | strcpy_or_abortcxx . . $ `lib/crypt-port.h:188:9`! (void *dst, size_tcxx . . $ size_t# d_size, const void *src) |
| 31 | { |
| 32 | assertcxx . . $ `<external>/4398592474888995393/assert.h:156:12`! (dst != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); |
| 33 | assertcxx . . $ `<external>/4398592474888995393/assert.h:156:12`! (src != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); |
| 34 | size_tcxx . . $ size_t# s_size = strlencxx . . $ strlen(751346f8406fd082). ((const char *)src); |
| 35 | assertcxx . . $ `<external>/4398592474888995393/assert.h:156:12`! (d_size > s_size); |
| 36 | if (!(d_size > s_size)) /* for NDEBUG builds */ |
| 37 | abortcxx . . $ abort(8df32a62017fbbf6).(); |
| 38 | |
| 39 | memcpycxx . . $ memcpy(cc817cb175f282d). (dst, src, s_size); |
| 40 | memsetcxx . . $ memset(d1de1e4fb215f1c6). (((char *)dst) + s_size, 0, d_size - s_size); |
| 41 | return s_size; |
| 42 | } |