diff options
Diffstat (limited to 'src/nvim/memory.c')
| -rw-r--r-- | src/nvim/memory.c | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/src/nvim/memory.c b/src/nvim/memory.c index b4fdd86a6d..bfc2f208dd 100644 --- a/src/nvim/memory.c +++ b/src/nvim/memory.c @@ -1,3 +1,6 @@ +// This is an open source non-commercial project. Dear PVS-Studio, please check +// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com + // Various routines dealing with allocation and deallocation of memory. #include <assert.h> @@ -342,10 +345,6 @@ char *xstpcpy(char *restrict dst, const char *restrict src) /// WARNING: xstpncpy will ALWAYS write maxlen bytes. If src is shorter than /// maxlen, zeroes will be written to the remaining bytes. /// -/// TODO(aktau): I don't see a good reason to have this last behaviour, and -/// it is potentially wasteful. Could we perhaps deviate from the standard -/// and not zero the rest of the buffer? -/// /// @param dst /// @param src /// @param maxlen @@ -370,10 +369,12 @@ char *xstpncpy(char *restrict dst, const char *restrict src, size_t maxlen) /// string that fits in the buffer (unless, of course, the buffer size is /// zero). It does not pad out the result like strncpy() does. /// -/// @param dst Buffer to store the result -/// @param src String to be copied -/// @param dsize Size of `dst` -/// @return strlen(src). If retval >= dstsize, truncation occurs. +/// @param[out] dst Buffer to store the result. +/// @param[in] src String to be copied. +/// @param[in] dsize Size of `dst`. +/// +/// @return Length of `src`. May be greater than `dsize - 1`, which would mean +/// that string was truncated. size_t xstrlcpy(char *restrict dst, const char *restrict src, size_t dsize) FUNC_ATTR_NONNULL_ALL { @@ -395,11 +396,13 @@ size_t xstrlcpy(char *restrict dst, const char *restrict src, size_t dsize) /// @see vim_strcat from Vim. /// @see strlcat from OpenBSD. /// -/// @param dst Buffer to be appended-to. Must have a NUL byte. -/// @param src String to put at the end of `dst` -/// @param dsize Size of `dst` including NUL byte. Must be greater than 0. -/// @return strlen(src) + strlen(initial dst) -/// If retval >= dsize, truncation occurs. +/// @param[in,out] dst Buffer to be appended-to. Must have a NUL byte. +/// @param[in] src String to put at the end of `dst`. +/// @param[in] dsize Size of `dst` including NUL byte. Must be greater than 0. +/// +/// @return Length of the resulting string as if destination size was #SIZE_MAX. +/// May be greater than `dsize - 1`, which would mean that string was +/// truncated. size_t xstrlcat(char *const dst, const char *const src, const size_t dsize) FUNC_ATTR_NONNULL_ALL { @@ -495,6 +498,13 @@ bool strequal(const char *a, const char *b) return (a == NULL && b == NULL) || (a && b && strcmp(a, b) == 0); } +/// Case-insensitive `strequal`. +bool striequal(const char *a, const char *b) + FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT +{ + return (a == NULL && b == NULL) || (a && b && STRICMP(a, b) == 0); +} + /* * Avoid repeating the error message many times (they take 1 second each). * Did_outofmem_msg is reset when a character is read. @@ -553,6 +563,7 @@ void time_to_bytes(time_t time_, uint8_t buf[8]) #include "nvim/tag.h" #include "nvim/window.h" #include "nvim/os/os.h" +#include "nvim/eval/typval.h" /* * Free everything that we allocated. @@ -579,7 +590,7 @@ void free_all_mem(void) p_ea = false; if (first_tabpage->tp_next != NULL) do_cmdline_cmd("tabonly!"); - if (firstwin != lastwin) + if (!ONE_WINDOW) do_cmdline_cmd("only!"); /* Free all spell info. */ @@ -686,6 +697,7 @@ void free_all_mem(void) free_screenlines(); clear_hl_tables(); + list_free_log(); } #endif |
