The NetBSD Project

CVS log for src/tests/lib/libutil/t_snprintb.c

[BACK] Up to [cvs.NetBSD.org] / src / tests / lib / libutil

Request diff between arbitrary revisions


Keyword substitution: kv
Default branch: MAIN


Revision 1.36: download - view: text, markup, annotated - select for diffs
Mon Apr 8 21:28:35 2024 UTC (8 months ago) by rillig
Branches: MAIN
CVS tags: perseant-exfatfs-base-20240630, perseant-exfatfs-base, perseant-exfatfs, HEAD
Diff to: previous 1.35: preferred, colored
Changes since revision 1.35: +29 -19 lines
snprintb.3: provide examples for hexadecimal character escapes

Suggested by uwe@, in reaction to the previous commit, which preferred
octal in the examples. Hexadecimal escapes are more familiar to most
programmers, and the chance of mistaking \x14 for decimal 14 is less
than the chance of mistaking octal \014 for decimal 14.

Revision 1.35: download - view: text, markup, annotated - select for diffs
Sun Apr 7 15:20:17 2024 UTC (8 months ago) by rillig
Branches: MAIN
Diff to: previous 1.34: preferred, colored
Changes since revision 1.34: +38 -29 lines
snprintb: reject empty bit descriptions and wrongly placed defaults

Revision 1.34: download - view: text, markup, annotated - select for diffs
Sun Apr 7 12:05:23 2024 UTC (8 months ago) by rillig
Branches: MAIN
Diff to: previous 1.33: preferred, colored
Changes since revision 1.33: +50 -67 lines
snprintb: reject combinations of 'f' with ':' as well as 'F' with '='

These combinations would lead to garbled output.

Revision 1.33: download - view: text, markup, annotated - select for diffs
Sun Apr 7 10:10:54 2024 UTC (8 months ago) by rillig
Branches: MAIN
Diff to: previous 1.32: preferred, colored
Changes since revision 1.32: +38 -25 lines
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.

Revision 1.32: download - view: text, markup, annotated - select for diffs
Mon Apr 1 09:15:51 2024 UTC (8 months, 1 week ago) by rillig
Branches: MAIN
Diff to: previous 1.31: preferred, colored
Changes since revision 1.31: +23 -16 lines
tests/snprintb_m: test null-terminated output in error case

While here, clean up the buffer handling for the visualized array
content in case of a failed test.

Revision 1.31: download - view: text, markup, annotated - select for diffs
Mon Mar 25 20:39:27 2024 UTC (8 months, 2 weeks ago) by rillig
Branches: MAIN
Diff to: previous 1.30: preferred, colored
Changes since revision 1.30: +24 -22 lines
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.

Revision 1.30: download - view: text, markup, annotated - select for diffs
Mon Mar 4 21:35:28 2024 UTC (9 months, 1 week ago) by rillig
Branches: MAIN
Diff to: previous 1.29: preferred, colored
Changes since revision 1.29: +18 -12 lines
snprintb: error out on unknown new-style formatting directive

Revision 1.29: download - view: text, markup, annotated - select for diffs
Sat Feb 24 13:00:00 2024 UTC (9 months, 2 weeks ago) by rillig
Branches: MAIN
Diff to: previous 1.28: preferred, colored
Changes since revision 1.28: +150 -153 lines
tests/snprintb: clean up tests

Always write the value to be formatted in hexadecimal, to make it easily
distinguishable from the buffer size and maximum line length.

Use consistent wording in the comments of the test cases. Be stricter
about mistakes in a format.

Fix some wrong numbers in the snprintb_m tests for limited line length.

Revision 1.28: download - view: text, markup, annotated - select for diffs
Sat Feb 24 12:40:00 2024 UTC (9 months, 2 weeks ago) by rillig
Branches: MAIN
Diff to: previous 1.27: preferred, colored
Changes since revision 1.27: +5 -4 lines
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.

Revision 1.27: download - view: text, markup, annotated - select for diffs
Thu Feb 22 21:04:24 2024 UTC (9 months, 2 weeks ago) by rillig
Branches: MAIN
Diff to: previous 1.26: preferred, colored
Changes since revision 1.26: +96 -125 lines
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.

Revision 1.26: download - view: text, markup, annotated - select for diffs
Thu Feb 22 18:26:16 2024 UTC (9 months, 2 weeks ago) by rillig
Branches: MAIN
Diff to: previous 1.25: preferred, colored
Changes since revision 1.25: +3 -17 lines
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.

Revision 1.25: download - view: text, markup, annotated - select for diffs
Tue Feb 20 21:45:36 2024 UTC (9 months, 3 weeks ago) by rillig
Branches: MAIN
Diff to: previous 1.24: preferred, colored
Changes since revision 1.24: +26 -3 lines
tests/snprintb: test '=' and '*' directives that can never match

Revision 1.24: download - view: text, markup, annotated - select for diffs
Tue Feb 20 20:31:56 2024 UTC (9 months, 3 weeks ago) by rillig
Branches: MAIN
Diff to: previous 1.23: preferred, colored
Changes since revision 1.23: +67 -133 lines
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.

Revision 1.23: download - view: text, markup, annotated - select for diffs
Tue Feb 20 19:49:10 2024 UTC (9 months, 3 weeks ago) by rillig
Branches: MAIN
Diff to: previous 1.22: preferred, colored
Changes since revision 1.22: +13 -5 lines
tests/snprintb: fix out-of-bounds memory read (since 2024-02-16)

Before t_snprintb.c 1.20, the buffer size was required to be greater
than zero. Allowing the buffer size to be zero led to buf[-1] being
checked. On amd64, that byte happened to be 0, on i386 it didn't.

Fixes PR lib/57951.

Revision 1.22: download - view: text, markup, annotated - select for diffs
Mon Feb 19 23:30:56 2024 UTC (9 months, 3 weeks ago) by rillig
Branches: MAIN
Diff to: previous 1.21: preferred, colored
Changes since revision 1.21: +4 -7 lines
snprintb: fix how named bit-fields are split into multiple lines

Revision 1.21: download - view: text, markup, annotated - select for diffs
Mon Feb 19 23:22:03 2024 UTC (9 months, 3 weeks ago) by rillig
Branches: MAIN
Diff to: previous 1.20: preferred, colored
Changes since revision 1.20: +1209 -483 lines
tests/snprintb: add more tests, especially for snprintb_m

Revision 1.20: download - view: text, markup, annotated - select for diffs
Fri Feb 16 19:53:40 2024 UTC (9 months, 3 weeks ago) by rillig
Branches: MAIN
Diff to: previous 1.19: preferred, colored
Changes since revision 1.19: +9 -17 lines
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.

Revision 1.19: download - view: text, markup, annotated - select for diffs
Fri Feb 16 19:20:38 2024 UTC (9 months, 3 weeks ago) by rillig
Branches: MAIN
Diff to: previous 1.18: preferred, colored
Changes since revision 1.18: +28 -2 lines
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.

Revision 1.18: download - view: text, markup, annotated - select for diffs
Fri Feb 16 18:13:47 2024 UTC (9 months, 3 weeks ago) by rillig
Branches: MAIN
Diff to: previous 1.17: preferred, colored
Changes since revision 1.17: +3 -3 lines
tests/snprintb: fix test for 8-bit field value

The previous version tested the behavior on a platform with signed
'char' before the portability fix.

Revision 1.17: download - view: text, markup, annotated - select for diffs
Fri Feb 16 18:09:16 2024 UTC (9 months, 3 weeks ago) by rillig
Branches: MAIN
Diff to: previous 1.16: preferred, colored
Changes since revision 1.16: +11 -2 lines
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.

Revision 1.16: download - view: text, markup, annotated - select for diffs
Fri Feb 16 01:19:53 2024 UTC (9 months, 3 weeks ago) by rillig
Branches: MAIN
Diff to: previous 1.15: preferred, colored
Changes since revision 1.15: +200 -69 lines
tests/snprintb: clean up existing tests, add more tests

Due to the check that any bytes beyond the expected output must be
unmodified, there's no need anymore to explicitly write the "ZZZ" at the
end of the expected output. While here, remove the redundant trailing
"\0".

Add more tests to cover possible situations where an out-of-bounds write
may have occurred. In some cases, the line length specified in
snprintb_m is exceeded.

Revision 1.15: download - view: text, markup, annotated - select for diffs
Thu Feb 15 23:48:51 2024 UTC (9 months, 3 weeks ago) by rillig
Branches: MAIN
Diff to: previous 1.14: preferred, colored
Changes since revision 1.14: +84 -5 lines
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.

Revision 1.14: download - view: text, markup, annotated - select for diffs
Thu Feb 15 22:37:10 2024 UTC (9 months, 3 weeks ago) by rillig
Branches: MAIN
Diff to: previous 1.13: preferred, colored
Changes since revision 1.13: +6 -12 lines
snprintb: fix out-of-bounds write

Revision 1.13: download - view: text, markup, annotated - select for diffs
Wed Feb 14 20:51:17 2024 UTC (9 months, 4 weeks ago) by rillig
Branches: MAIN
Diff to: previous 1.12: preferred, colored
Changes since revision 1.12: +83 -13 lines
tests/libutil/snprintb_m: add tests for small line length

Revision 1.12: download - view: text, markup, annotated - select for diffs
Sat Jan 27 21:42:29 2024 UTC (10 months, 2 weeks ago) by rillig
Branches: MAIN
Diff to: previous 1.11: preferred, colored
Changes since revision 1.11: +8 -8 lines
tests/libutil/snprintb: remove redundant integer constant suffixes

I added these because lint told me so. Lint was wrong though, as it had
not implemented the C99 rules for integer constants.

Revision 1.11: download - view: text, markup, annotated - select for diffs
Sat Jan 27 10:32:03 2024 UTC (10 months, 2 weeks ago) by rillig
Branches: MAIN
Diff to: previous 1.10: preferred, colored
Changes since revision 1.10: +8 -6 lines
tests/libutil/snprintb: fix test for 32-bit platforms

Revision 1.10: download - view: text, markup, annotated - select for diffs
Sat Jan 27 08:54:15 2024 UTC (10 months, 2 weeks ago) by rillig
Branches: MAIN
Diff to: previous 1.9: preferred, colored
Changes since revision 1.9: +423 -96 lines
tests/libutil/snprintb: add more tests

Test all number bases (octal, decimal, hexadecimal), in both old-style
and new-style formats, as well as small buffer sizes.

Document working edge cases such as empty descriptions or descriptions
containing spaces, as well as situations that invoke undefined behavior.

Add comments to the individual test cases, as reading the actual format
strings takes more time.

Revision 1.9: download - view: text, markup, annotated - select for diffs
Thu Jan 25 18:13:14 2024 UTC (10 months, 2 weeks ago) by rillig
Branches: MAIN
Diff to: previous 1.8: preferred, colored
Changes since revision 1.8: +231 -71 lines
tests/libutil/snprintb: clean up and extend tests

In case of a failure, print the details of the test case, including file
and line number of the actual test data. Do not write the format strings
directly to the output, as they contain non-printable bytes and embedded
null bytes.

After a failed test case, continue with the others.

Lay out the format strings according to their structure, to make them
more readable. Remove redundant "\0" at the end of the new-style format
strings.

Fix an off-by-one error in the test data: 0xf is FIFTEEN, not SIXTEEN.

Add a test for performing a restricted subset of rot13 in the format
string, to explore the limits of snprintb formatting.

What's still missing are tests for edge cases and error cases.

Revision 1.5.4.2: download - view: text, markup, annotated - select for diffs
Wed Apr 8 14:09:10 2020 UTC (4 years, 8 months ago) by martin
Branches: phil-wifi
Diff to: previous 1.5.4.1: preferred, colored; branchpoint 1.5: preferred, colored; next MAIN 1.6: preferred, colored
Changes since revision 1.5.4.1: +33 -20 lines
Merge changes from current as of 20200406

Revision 1.8: download - view: text, markup, annotated - select for diffs
Sun Dec 8 17:37:16 2019 UTC (5 years ago) by christos
Branches: MAIN
CVS tags: phil-wifi-20200421, phil-wifi-20200411, phil-wifi-20200406, netbsd-10-base, netbsd-10-0-RELEASE, netbsd-10-0-RC6, netbsd-10-0-RC5, netbsd-10-0-RC4, netbsd-10-0-RC3, netbsd-10-0-RC2, netbsd-10-0-RC1, netbsd-10, is-mlppp-base, is-mlppp, cjep_sun2x-base1, cjep_sun2x-base, cjep_sun2x, cjep_staticlib_x-base1, cjep_staticlib_x-base, cjep_staticlib_x
Diff to: previous 1.7: preferred, colored
Changes since revision 1.7: +30 -17 lines
Adjust tests for 0 hex values printing 0 instead of 0x0

Revision 1.7: download - view: text, markup, annotated - select for diffs
Fri Dec 6 19:28:11 2019 UTC (5 years ago) by christos
Branches: MAIN
Diff to: previous 1.6: preferred, colored
Changes since revision 1.6: +5 -5 lines
Fix broken tests in big endian machines. Internally field values are
stored as uint64_t/uintmax_t so printing them with %d on big endian
ends up being 0.

Revision 1.5.4.1: download - view: text, markup, annotated - select for diffs
Mon Jun 10 22:10:07 2019 UTC (5 years, 6 months ago) by christos
Branches: phil-wifi
Diff to: previous 1.5: preferred, colored
Changes since revision 1.5: +28 -6 lines
Sync with HEAD

Revision 1.6: download - view: text, markup, annotated - select for diffs
Mon Apr 29 07:55:38 2019 UTC (5 years, 7 months ago) by kre
Branches: MAIN
CVS tags: phil-wifi-20191119, phil-wifi-20190609, netbsd-9-base, netbsd-9-4-RELEASE, netbsd-9-3-RELEASE, netbsd-9-2-RELEASE, netbsd-9-1-RELEASE, netbsd-9-0-RELEASE, netbsd-9-0-RC2, netbsd-9-0-RC1, netbsd-9
Diff to: previous 1.5: preferred, colored
Changes since revision 1.5: +28 -6 lines
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).

Revision 1.5: download - view: text, markup, annotated - select for diffs
Sat Oct 14 18:41:44 2017 UTC (7 years, 2 months ago) by ryo
Branches: MAIN
CVS tags: phil-wifi-base, pgoyette-compat-merge-20190127, pgoyette-compat-base, pgoyette-compat-20190127, pgoyette-compat-20190118, pgoyette-compat-1226, pgoyette-compat-1126, pgoyette-compat-1020, pgoyette-compat-0930, pgoyette-compat-0906, pgoyette-compat-0728, pgoyette-compat-0625, pgoyette-compat-0521, pgoyette-compat-0502, pgoyette-compat-0422, pgoyette-compat-0415, pgoyette-compat-0407, pgoyette-compat-0330, pgoyette-compat-0322, pgoyette-compat-0315, pgoyette-compat
Branch point for: phil-wifi
Diff to: previous 1.4: preferred, colored
Changes since revision 1.4: +13 -3 lines
add test case for new format 'f' and 'F'

Revision 1.1.12.1: download - view: text, markup, annotated - select for diffs
Wed Aug 20 00:04:51 2014 UTC (10 years, 3 months ago) by tls
Branches: tls-maxphys
Diff to: previous 1.1: preferred, colored; next MAIN 1.2: preferred, colored
Changes since revision 1.1: +43 -1 lines
Rebase to HEAD as of a few days ago.

Revision 1.3.2.1: download - view: text, markup, annotated - select for diffs
Sun Aug 10 06:57:22 2014 UTC (10 years, 4 months ago) by tls
Branches: tls-earlyentropy
Diff to: previous 1.3: preferred, colored; next MAIN 1.4: preferred, colored
Changes since revision 1.3: +3 -2 lines
Rebase.

Revision 1.4: download - view: text, markup, annotated - select for diffs
Fri Jun 6 06:59:21 2014 UTC (10 years, 6 months ago) by shm
Branches: MAIN
CVS tags: tls-maxphys-base, tls-earlyentropy-base, prg-localcount2-base3, prg-localcount2-base2, prg-localcount2-base1, prg-localcount2-base, prg-localcount2, pgoyette-localcount-base, pgoyette-localcount-20170426, pgoyette-localcount-20170320, pgoyette-localcount-20170107, pgoyette-localcount-20161104, pgoyette-localcount-20160806, pgoyette-localcount-20160726, pgoyette-localcount, perseant-stdc-iso10646-base, perseant-stdc-iso10646, netbsd-8-base, netbsd-8-3-RELEASE, netbsd-8-2-RELEASE, netbsd-8-1-RELEASE, netbsd-8-1-RC1, netbsd-8-0-RELEASE, netbsd-8-0-RC2, netbsd-8-0-RC1, netbsd-8, netbsd-7-nhusb-base-20170116, netbsd-7-nhusb-base, netbsd-7-nhusb, netbsd-7-base, netbsd-7-2-RELEASE, netbsd-7-1-RELEASE, netbsd-7-1-RC2, netbsd-7-1-RC1, netbsd-7-1-2-RELEASE, netbsd-7-1-1-RELEASE, netbsd-7-1, netbsd-7-0-RELEASE, netbsd-7-0-RC3, netbsd-7-0-RC2, netbsd-7-0-RC1, netbsd-7-0-2-RELEASE, netbsd-7-0-1-RELEASE, netbsd-7-0, netbsd-7, matt-nb8-mediatek-base, matt-nb8-mediatek, localcount-20160914, bouyer-socketcan-base1, bouyer-socketcan-base, bouyer-socketcan
Diff to: previous 1.3: preferred, colored
Changes since revision 1.3: +3 -2 lines
PR/48517 testcase provided by Felix Deichmann

Revision 1.1.6.1: download - view: text, markup, annotated - select for diffs
Thu May 22 11:42:22 2014 UTC (10 years, 6 months ago) by yamt
Branches: yamt-pagecache
Diff to: previous 1.1: preferred, colored; next MAIN 1.2: preferred, colored
Changes since revision 1.1: +44 -3 lines
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")

Revision 1.3: download - view: text, markup, annotated - select for diffs
Thu Aug 8 05:10:07 2013 UTC (11 years, 4 months ago) by pgoyette
Branches: MAIN
CVS tags: yamt-pagecache-base9, riastradh-xf86-video-intel-2-7-1-pre-2-21-15, riastradh-drm2-base3
Branch point for: tls-earlyentropy
Diff to: previous 1.2: preferred, colored
Changes since revision 1.2: +3 -3 lines
Arghhh!  Typo.

Revision 1.2: download - view: text, markup, annotated - select for diffs
Thu Aug 8 04:52:10 2013 UTC (11 years, 4 months ago) by pgoyette
Branches: MAIN
Diff to: previous 1.1: preferred, colored
Changes since revision 1.1: +44 -3 lines
Add a new test case for snprintb_m(3) to catch previous boundary bug.

Revision 1.1: download - view: text, markup, annotated - select for diffs
Fri Jul 16 13:56:32 2010 UTC (14 years, 5 months ago) by jmmv
Branches: MAIN
CVS tags: yamt-pagecache-tag8, yamt-pagecache-base8, yamt-pagecache-base7, yamt-pagecache-base6, yamt-pagecache-base5, yamt-pagecache-base4, yamt-pagecache-base3, yamt-pagecache-base2, yamt-pagecache-base, riastradh-drm2-base2, riastradh-drm2-base1, riastradh-drm2-base, riastradh-drm2, netbsd-6-base, netbsd-6-1-RELEASE, netbsd-6-1-RC4, netbsd-6-1-RC3, netbsd-6-1-RC2, netbsd-6-1-RC1, netbsd-6-1-5-RELEASE, netbsd-6-1-4-RELEASE, netbsd-6-1-3-RELEASE, netbsd-6-1-2-RELEASE, netbsd-6-1-1-RELEASE, netbsd-6-1, netbsd-6-0-RELEASE, netbsd-6-0-RC2, netbsd-6-0-RC1, netbsd-6-0-6-RELEASE, netbsd-6-0-5-RELEASE, netbsd-6-0-4-RELEASE, netbsd-6-0-3-RELEASE, netbsd-6-0-2-RELEASE, netbsd-6-0-1-RELEASE, netbsd-6-0, netbsd-6, matt-nb6-plus-nbase, matt-nb6-plus-base, matt-nb6-plus, matt-mips64-premerge-20101231, cherry-xenmp-base, cherry-xenmp, bouyer-quota2-nbase, bouyer-quota2-base, bouyer-quota2, agc-symver-base, agc-symver
Branch point for: yamt-pagecache, tls-maxphys
Convert the libposix, libprop, librt, libskey and libutil tests to ATF.
Initial work from the GSoC 2008 project by Lukasz Strzygowski.

Diff request

This form allows you to request diffs between any two revisions of a file. You may select a symbolic revision name using the selection box or you may type in a numeric name using the type-in text box.

Log view options

CVSweb <webmaster@jp.NetBSD.org>