Commit graph

11 commits

Author SHA1 Message Date
Christian Hopps 7d2a0ffc69 lib: darr: add string search macros
Add macros to support searching for and finding (perhaps closest) matches
for a key in an array of strings.

Signed-off-by: Christian Hopps <chopps@labn.net>
2025-04-21 09:22:28 +00:00
Christian Hopps 73e54e4168 lib: darr: use the FRR printf formatter
Signed-off-by: Christian Hopps <chopps@labn.net>
2024-12-15 21:51:27 -05:00
Igor Ryzhov cb6032d6b3 lib: fix infinite loop in __darr_in_vsprintf
`darr_avail` returns the available capacity excluding the already
existing terminating NULL byte. Take this into account when using
`darr_avail`. Otherwise, if the error length is a power of 2, the
capacity is never enough and the function stucks in an infinite loop.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-03-05 02:08:30 +02:00
Igor Ryzhov ee0c1cc1e4 lib: fix __darr_in_vsprintf
If the initial darr capacity is not enough for the output, the `ap` is
reused multiple times, which is wrong, because it may be altered by
`vsnprintf`. Make a copy of `ap` each time instead of reusing.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2024-03-04 02:24:26 +02:00
Christian Hopps b7db6b2675 lib: darr: add ability to set MTYPE for dynamic arrays
Signed-off-by: Christian Hopps <chopps@labn.net>
2023-12-28 17:52:57 +00:00
Christian Hopps f3d6edc7ee lib: darr: add new access and str functions
- darr_last(), and darr_strdup_cap().
- strcat, strdup, strlen, strnul equivs.

Signed-off-by: Christian Hopps <chopps@labn.net>
2023-12-28 17:52:57 +00:00
Christian Hopps a6c8e08ecd lib: darr needs to use memory.h for both alloc and free
Was using XREALLOC() and then free(). instant "memleaks".

Signed-off-by: Christian Hopps <chopps@labn.net>
2023-11-11 20:30:02 +01:00
Donatas Abraitis 4d087a71d3
Merge pull request #14508 from LabNConsulting/chopps/darr-use-frrmemfunc
lib: use XREALLOC over realloc avoid coverity warning
2023-10-03 10:34:27 +03:00
Donatas Abraitis 02d8b80ce4 *: Do not cast to the same type as the destination is
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
2023-09-29 10:24:16 +03:00
Christian Hopps 53511f252d lib: use XREALLOC over realloc avoid coverity warning
I believe coverity is complaining that the current code does not handle the
realloc fail case, in which case the original pointer is not freed, but NULL is
returned. The code assert()s it's not failed but that is not strong enough it
needs to abort which XREALLOC does and is a better integration into FRR-inrfa
anyway.

Signed-off-by: Christian Hopps <chopps@labn.net>
2023-09-29 01:19:53 -04:00
Christian Hopps e6e0c5bd25 lib: add dynamic array type
Signed-off-by: Christian Hopps <chopps@labn.net>
2023-06-27 18:00:56 -04:00