History log of /src/common/lib/libutil/snprintb.c |
Revision | | Date | Author | Comments |
1.49 |
| 16-Jun-2024 |
rillig | libutil/snprintb: factor out common subexpression
GCC 10 was not able to optimize the code size on its own, so offer a little help.
|
1.48 |
| 07-Apr-2024 |
rillig | snprintb: reject empty bit descriptions and wrongly placed defaults
|
1.47 |
| 07-Apr-2024 |
rillig | snprintb: reject combinations of 'f' with ':' as well as 'F' with '='
These combinations would lead to garbled output.
|
1.46 |
| 07-Apr-2024 |
rillig | snprintb: reject empty descriptions
In cases where the snprintb output is garbled, it is not trustworthy, so make sure the mistakes in the bitfmt are fixed early.
|
1.45 |
| 01-Apr-2024 |
rillig | snprintb: remove redundant memset in kernel mode
The provided buffer is already null-terminated by finish_buffer, even in error cases, there is no need to repeat the same work.
|
1.44 |
| 25-Mar-2024 |
rillig | snprintb: mark the end of the buffer if the buffer is too small
This avoids confusion in case the buffer ends with an incomplete number.
|
1.43 |
| 05-Mar-2024 |
rillig | snprintb: shrink code size, both in source and binary
|
1.42 |
| 04-Mar-2024 |
rillig | snprintb: error out on unknown new-style formatting directive
|
1.41 |
| 24-Feb-2024 |
rillig | snprintb: clean up
Use consistent data types for buffer positions and lengths, to avoid type casts.
|
1.40 |
| 24-Feb-2024 |
rillig | snprintb: allow non-ASCII descriptions on all platforms
Previously, these descriptions were only allowed on platforms where plain 'char' is unsigned. On platforms where plain 'char' is signed, they invoked undefined behavior or terminated the output early.
|
1.39 |
| 22-Feb-2024 |
rillig | snprintb: always null-terminate output
Always null-terminate the output in the buffer, even in error cases. The wording in the manual page has been promising this since 2008. For snprintb_m, ensure that the output is terminated with two null characters, to gracefully handle situations in which the caller does not check whether snprintb returned an error.
If the buffer size is zero, allow the buffer to be a null pointer, analogous to snprintf.
Fix an out-of-bounds memory read if the bitfmt ends with a '*' directive (since today).
In the tests, merge the helper functions for snprintb, snprintb_m, as they were similar enough.
Fix a few 'line_max exceeded' tests, ensuring that they output a '#' marker, and that the 'complete' tests don't.
|
1.38 |
| 22-Feb-2024 |
rillig | snprintb: error out on out-of-bounds bit shifts
Previously, these invoked undefined behavior, now they lead to an early return. An example of out-of-bounds bit number is in SCZ_PCICTRL_BITS. Bit fields that extend beyond the msb are still allowed.
Allow 'f' and 'F' to have fields that are 64 bits wide. This only makes sense when the field starts at bit 0.
Remove the unused 'val_len', it was only needed before snprintb.c 1.20.
|
1.37 |
| 20-Feb-2024 |
rillig | snprintb_m: limit length of generated strings
The manual page promises that the 'max' argument limits the length of the generated strings, so don't generate any strings that are longer than that limit. Mark incomplete strings with a trailing '#' to make them easily recognizable.
|
1.36 |
| 19-Feb-2024 |
rillig | snprintb: fix how named bit-fields are split into multiple lines
|
1.35 |
| 17-Feb-2024 |
rillig | snprintb: convert macros to local functions
Let the compiler decide whether to inline the functions; allow stepping through the code in a debugger.
|
1.34 |
| 16-Feb-2024 |
rillig | snprintb: do not modify bufsize when producing multiple lines
|
1.33 |
| 16-Feb-2024 |
rillig | snprintb: eliminate two local variables, allow zero-size buffer
Like snprintf, the buffer size may be zero. Unlike snprintf, the buffer must not be NULL.
|
1.32 |
| 16-Feb-2024 |
rillig | snprintb: use size_t for buffer sizes and positions
|
1.31 |
| 16-Feb-2024 |
rillig | snprintb: fix integer overflow when writing past a small buffer
Previously, snprintb returned -1 in this case, assuming that the snprintf used in FMTSTR validates against an overly large buffer size.
|
1.30 |
| 16-Feb-2024 |
rillig | snprintb: use unsigned integers for parsing the bitfmt
|
1.29 |
| 16-Feb-2024 |
rillig | snprintb: fix '=' and ':' for 8-bit values on platforms with signed char
Previously, '=' and ':' worked only on platforms where plain 'char' is unsigned. On platforms where plain 'char' is signed, only 7-bit values worked.
|
1.28 |
| 16-Feb-2024 |
rillig | snprintb: eliminate a few local variables
|
1.27 |
| 16-Feb-2024 |
rillig | snprintb: rename local variables
The single-letter variables 't', 's', 'l' and 'c' were too hard to decipher.
The variable 'f_len' was used for two independent purposes.
Use a narrow scope for some variables, to avoid having to keep track of 22 individual variables at the same time.
No binary change.
|
1.26 |
| 16-Feb-2024 |
rillig | snprintb: clean up
Remove redundant parentheses and casts.
Indent statement-like macros consistently, use separate lines for each statement, add parentheses to macro definitions.
Remove CONSTCOND comments as lint doesn't need them anymore.
No binary change.
|
1.25 |
| 15-Feb-2024 |
rillig | snprintb: fix string termination (since today)
In the previous commit, I had accidentally only run the tests for snprintb_m but not those for snprintb, thereby missing a newly introduced bug that would not null-terminate the resulting strings.
Add more tests to cover similar situations in which the buffer is too small to contain the complete output.
|
1.24 |
| 15-Feb-2024 |
rillig | snprintb: rename buflen to bufsize, following the wording in snprintf
|
1.23 |
| 15-Feb-2024 |
rillig | snprintb: fix out-of-bounds write
|
1.22 |
| 06-Dec-2019 |
christos | Formalize that the printf formats should be uintmax_t so we can uniformly use 'j' in the user-provided formatting strings instead of depending on _LP64 to use 'll' or 'l' (and the PRI macros). The alternative is to parse the printf format manually to determine which modifier to apply which would make this transparent to the user (they could still always use '%u' or '%x'), but that's too painful.
|
1.21 |
| 17-Jun-2019 |
christos | PR/54300: Andreas Gustafsson: Remove useless case. should fix lib/libutil/t_snprintb test regression on sparc
|
1.20 |
| 29-Apr-2019 |
kre | snprintb(3) says that, in the new(?) Torek format, all fields specs end with \0 The F spec is one of those, it should be terminated with \0 just like all the others (irrelevant that it has no extra data to delimit).
Fix <sys/mman.h> to define the snprintb() format string correctly (include the missing \0's). Fix the copy of that definition included into snprintb(3) to match the updated mman.h version (ride the date bump from the day before yesterday .. this is the same change, just corrected).
Undo the previous snprintb.c change ("off by one" fix) which was an attempt to make the broken mman.h usage work (and did, but not the way it should be done). Also, after using the new * format (instead of only when something has already matched) skip the associated data so we don't attempt to interpret it as more field specifiers. This func needs lots of TLC!
Fix the ATF tests for snprintb() to not assume that F format is really exactly like f format, and has data after the field specifier. It doesn't. Add several more tests (including testing the '*' field operator recently added).
|
1.19 |
| 27-Apr-2019 |
christos | Fix an off-by-one in the F modifier that ended up skipping the first : or = entry, and add a * specifier for a "default case".
|
1.18 |
| 26-Jul-2018 |
kamil | Avoid undefined behavior in snprintb.c
Do not change the signedness bit with a left shift operation. Switch to unsigned integer to prevent this.
snprintb.c:178:17, left shift of 1 by 31 places cannot be represented in type 'int'
Detected with micro-UBSan in the user mode.
|
1.17 |
| 14-Oct-2017 |
ryo | branches: 1.17.2; 1.17.4; doesn't work new format 'F' with a strings of length 1, or a string beginning with 'F'
|
1.16 |
| 02-Aug-2014 |
ryo | fix lack of '>' pointed out in PR/48517
|
1.15 |
| 06-Jun-2014 |
shm | PR/48517 do not add extra '>' to string-converted value when nothing matches
|
1.14 |
| 08-Aug-2013 |
pgoyette | branches: 1.14.2; Now that all of the macros are enclosed in "do { ... } while 0" we can remove unneded parenthesization of their invocations.
OK mrg@
|
1.13 |
| 08-Aug-2013 |
agc | Get the correct inttypes.h header, so this can build on !NetBSD.
|
1.12 |
| 08-Aug-2013 |
mrg | apply some do { ... } while (0) so that macros aren't broken, completing the previous change.
|
1.11 |
| 07-Aug-2013 |
pgoyette | The PUT* things are macros. Use { ... } to make sure they expand correctly.
|
1.10 |
| 07-Aug-2013 |
pgoyette | Fix boundary condition in multi-line format. When the '=' following a field name exactly filled a line, the back-up logic failed and really messed up the formatting!
|
1.9 |
| 06-Aug-2013 |
apb | If HAVE_SNPRINTB_M is defined, then do not define the snprintb() and snprintb_m() functions. This should allow this file to be compiled from a tools build regardless of whether or not the host defines these functions.
|
1.8 |
| 09-Jul-2013 |
uwe | Use "unsigned int" instead of "u_int" to make it easier to steal. u_int is out of fashion anyway...
|
1.7 |
| 23-Jan-2012 |
christos | branches: 1.7.6; also handle the separator after the F field.
|
1.6 |
| 23-Jan-2012 |
christos | In the new format F did not print a separator as required.
|
1.5 |
| 13-May-2009 |
pgoyette | branches: 1.5.6; Implement snprintb_m(3) to provide multi-line bit/bit-field decode. Discussed on tech-kern.
|
1.4 |
| 18-Jan-2009 |
lukem | branches: 1.4.2; fix -Wsign-compare issues
|
1.3 |
| 14-Jan-2009 |
pooka | Include sys/param.h in the kernel to make the vax properly pick up memset. Otherwise vax/macros.h doesn't get included and the usual lossage ensues. (I bet you saw that one coming)
|
1.2 |
| 17-Dec-2008 |
christos | We don't need this for _STANDALONE, and it needs snprintf to work.
|
1.1 |
| 16-Dec-2008 |
christos | share with kernel; replaces bitmask_snprintf which was very broken: - subtracted one from len without checking if len was 0 - checked for a minimum buffer size - arguments order was inconsistent with other printf like functions - no way to tell if it overflowed
|
1.4.2.1 |
| 13-May-2009 |
jym | Sync with HEAD.
Commit is split, to avoid a "too many arguments" protocol error.
|
1.5.6.2 |
| 22-May-2014 |
yamt | sync with head.
for a reference, the tree before this commit was tagged as yamt-pagecache-tag8.
this commit was splitted into small chunks to avoid a limitation of cvs. ("Protocol error: too many arguments")
|
1.5.6.1 |
| 17-Apr-2012 |
yamt | sync with head
|
1.7.6.1 |
| 19-Aug-2014 |
tls | Rebase to HEAD as of a few days ago.
|
1.14.2.1 |
| 10-Aug-2014 |
tls | Rebase.
|
1.17.4.4 |
| 21-Apr-2020 |
martin | Ooops, restore accidently removed files from merge mishap
|
1.17.4.3 |
| 21-Apr-2020 |
martin | Sync with HEAD
|
1.17.4.2 |
| 13-Apr-2020 |
martin | Mostly merge changes from HEAD upto 20200411
|
1.17.4.1 |
| 10-Jun-2019 |
christos | Sync with HEAD
|
1.17.2.1 |
| 28-Jul-2018 |
pgoyette | Sync with HEAD
|