diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2023-02-14 08:07:38 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-14 05:07:38 -0800 |
commit | ff3d04b75b4a9314815c37d53ebc4d035a043335 (patch) | |
tree | 435a61efa5c036060b72aa945166e76bee34d7de /src/nvim/api/private/validate.c | |
parent | 3a6a7add57d2ac141f474b54659bbbf596b76059 (diff) | |
download | rneovim-ff3d04b75b4a9314815c37d53ebc4d035a043335.tar.gz rneovim-ff3d04b75b4a9314815c37d53ebc4d035a043335.tar.bz2 rneovim-ff3d04b75b4a9314815c37d53ebc4d035a043335.zip |
refactor(api): VALIDATE macros #22256
- VALIDATE() takes a format string
- deduplicate check_string_array
- VALIDATE_RANGE
- validate UI args
Diffstat (limited to 'src/nvim/api/private/validate.c')
-rw-r--r-- | src/nvim/api/private/validate.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/nvim/api/private/validate.c b/src/nvim/api/private/validate.c new file mode 100644 index 0000000000..41c9472a39 --- /dev/null +++ b/src/nvim/api/private/validate.c @@ -0,0 +1,28 @@ +// 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 + +#include "nvim/api/private/defs.h" +#include "nvim/api/private/helpers.h" +#include "nvim/api/private/validate.h" + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "api/private/validate.c.generated.h" +#endif + +bool check_string_array(Array arr, char *name, bool disallow_nl, Error *err) +{ + snprintf(IObuff, sizeof(IObuff), "'%s' item", name); + for (size_t i = 0; i < arr.size; i++) { + VALIDATE_T(IObuff, kObjectTypeString, arr.items[i].type, { + return false; + }); + // Disallow newlines in the middle of the line. + if (disallow_nl) { + const String l = arr.items[i].data.string; + VALIDATE(!memchr(l.data, NL, l.size), "'%s' item contains newlines", name, { + return false; + }); + } + } + return true; +} |