Commit graph

21 commits

Author SHA1 Message Date
Igor Ryzhov 7d67b9ff28 build: add -Wimplicit-fallthrough
Also:
- replace all /* fallthrough */ comments with portable fallthrough;
pseudo keyword to accomodate both gcc and clang
- add missing break; statements as required by older versions of gcc
- cleanup some code to remove unnecessary fallthrough

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2023-10-12 21:23:18 +03:00
Dag-Erling Smørgrav 3ca2253b13 lib/printf: Implement N2630.
This adds formatted input/output of binary integer numbers to the
printf(), scanf(), and strtol() families, including their wide-character
counterparts.

Reviewed by:	imp, emaste
Differential Revision:	https://reviews.freebsd.org/D41511

FRR changes only include printf(), scanf/strtol are not locally
implemented in FRR.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
(cherry picked from FreeBSD commit d9dc1603d6e48cca84cad3ebe859129131b8387c)
2023-09-03 23:32:55 +02:00
Ed Maste b62dbddfda lib/printf: drop "All rights reserved" from Foundation copyrights
This has already been done for most files that have the Foundation as
the only listed copyright holder.  Do it now for files that list
multiple copyright holders, but have the Foundation copyright in its own
section.

Sponsored by:	The FreeBSD Foundation

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
(cherry picked from FreeBSD commit 5b5fa75acff11d871d0c90045f8c1a58fed85365)
2023-09-03 23:32:46 +02:00
David Lamparter c84e518709 *: no-warn pragmas for non-const format strings
We do use non-constant/literal format strings in a few places for more
or less valid reasons;  put `ignored "-Wformat-nonliteral"` around those
so we can have the warning enabled for everywhere else.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
2023-01-27 12:01:20 +01:00
Mark Stapp e2efe13327
Merge pull request #8350 from opensourcerouting/printfrr-revamp
lib: `printfrr()` care package
2021-03-31 09:10:30 -04:00
David Lamparter 2d9a4e2931 lib: allow discerning unspec width in printfrr ext
With 0 currently the default value for the width specifier, it's not
possible to discern that from a %*p where 0 was passed as the length
parameter.  Use -1 to allow for that.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-03-30 22:32:59 +02:00
David Lamparter 3ea7943059 lib: put printfrr extension args into struct
... for easier extensibility.  Add width, # and - flags while at it.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-03-30 22:32:55 +02:00
David Lamparter 487eefcfbe lib: record output positions in printfrr
This replaces `%n` with a safe, out-of-band option that simply records
the start and end offset of the output produced for each `%...`
specifier.

The old `%n` code is removed.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-03-27 17:01:29 +01:00
David Lamparter 212e04e5a7 lib: rework printfrr extensions to output directly
Allowing printfrr extensions to directly write to the output buffer has
a few advantages:
- there is no arbitrary length limit imposed (previously 64)
- the output doesn't need to be copied another time
- the extension can directly use bprintfrr() to put together pieces

The downside is that the theoretical length (regardless of available
buffer space) must be computed correctly.

Extended unit tests to test these paths a bit more thoroughly.

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-03-27 16:56:55 +01:00
Mark Stapp ff7c213c65 lib: enlarge the local buffer for printfrr extension tokens
Make the local buffer offered to printfrr extension tokens
bigger; existing size wasn't quite enough for some of the
more elaborate struct prefix types.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
2021-03-23 14:48:58 -04:00
David Lamparter 738cca0ab4 lib/printf: disable %n specifier
We don't use `%n` anywhere, so the only purpose it serves is enabling
exploits.

(I thought about this initially when adding printfrr, but I wasn't sure
we don't use `%n` anywhere, and thought I'll check later, and then just
forgot it...)

Signed-off-by: David Lamparter <equinox@diac24.net>
2021-02-01 18:33:18 +01:00
Donatas Abraitis 95f7965d09 *: Remove parenthesis on return for constants
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
2020-02-09 14:21:56 +02:00
David Lamparter bf4d3d8021 lib/printf: add extension support
Inspired by the Linux kernel, this allows us to do %pI4 and similar
things.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-06-03 16:45:01 +02:00
David Lamparter 60f1101d29 lib/printf: fix some random warnings
Signed-off-by: David Lamparter <equinox@diac24.net>
2019-06-03 16:44:58 +02:00
David Lamparter 5c25bd87b5 lib/printf: integrate
Signed-off-by: David Lamparter <equinox@diac24.net>
2019-06-03 16:44:51 +02:00
David Lamparter 8be3678a23 lib/printf: rename & private __find_arguments
These are internal to printf(), and symbols starting with __ are
reserved for the compiler/libc.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-06-03 16:44:32 +02:00
David Lamparter e8c672ea81 lib/printf: disable wchar_t support
... we just don't use wchar_t in FRR, no point in having this enabled.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-06-03 16:44:29 +02:00
David Lamparter 32b67a0aeb lib/printf: add %Ld/%Lu for int64_t/uint64_t
[u]int64_t is the only type in the intX_t family that needs
special-casing for printf since the calling convention may differ
between 32-bit and 64-bit systems.

Adding the L specifier allows us to eschew the gnarly-looking PRIu64.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-06-03 16:44:24 +02:00
David Lamparter 7fa480984e lib/printf: use system printf for floats
We're not libc, we can just fall back to snprintf() to avoid all this
low-level float mangling.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-06-03 16:44:18 +02:00
David Lamparter 86bfbddf6e lib/printf: cut down to size
remove various FreeBSD specific bits, as well as the entirety of locale
support.

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-06-03 16:44:05 +02:00
David Lamparter ea0b6afe2b lib: import FreeBSD's printf
... from current SVN HEAD (not that it has been touched in the past 2
years ...)

Signed-off-by: David Lamparter <equinox@diac24.net>
2019-06-03 16:43:11 +02:00