Commit Graph

613 Commits

Author SHA1 Message Date
rillig a15b6e013d snprintb.3: fix typo 2024-02-29 21:08:54 +00:00
rillig 4cf4169998 parsedate.y: remove outdated comment
The number of shift/reduce conflicts has grown to 16.
2024-02-29 20:55:35 +00:00
rillig 69c5b3b0c1 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.
2024-02-22 21:04:23 +00:00
rillig d101133e9b 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.
2024-02-22 18:26:15 +00:00
rillig aafc9e1277 snprintb.3: sync examples with reality 2024-02-20 20:38:54 +00:00
rillig fd2741deca mman.h: fix snprintb description for alignment 2^60 2024-02-18 16:55:02 +00:00
rillig 6f937561f5 snprintb: rename buflen to bufsize, following the wording in snprintf 2024-02-15 22:48:58 +00:00
uwe 641a20f456 getrawpartition(3): reword to clarify return value, use .Pq
"'a' == 0" is, stricly speaking false, and since 'a' is an int, it's
not immediately clear if it's 'a' or 0 that is returned.  Try to
clarify this.
2024-02-04 18:44:54 +00:00
rillig d4c87e8aca snprintb.3: fix examples, clean up wording
In the examples using hex escape sequences, there must be a delimiter
between the escape sequence and the following description if the
description starts with [A-Fa-f], as hex escape sequences are not
limited in length.

Distinguish between a 'directive' (bit + length + description) and a
'description' (only the text).

The fmt parameter is not a string, as strings only reach to the first
'\0' byte, but the new-style format may include additional '\0' as bit
numbers.
2024-02-01 22:18:34 +00:00
uwe af45bdc82c snprintb(3): restore empty string in snprintb_m example
Restore the empty string at the end of snprintb_m output that was
accidentally removed along with empty string placeholders in the
format strings.  While here, move that example to be next to its
snprintb counterpart.
2024-01-22 00:11:21 +00:00
uwe 635b447434 snprintb(3): update mmap example
Bring over the prettier version of the mmap format string that we have
in the header file for some time now.  Clarify that the final NUL of
the new format string is supplied by the compiler, g/c explicit final
\0 from the example that had it.
2024-01-21 23:57:49 +00:00
uwe 56fe87ce20 snprintb(3): try to improve narration
Try to make the narration more coherent.  Make the old and new
syntaxes easy to distinguish and go out of our way to highlight that
the old syntax uses 1-based bit positions.
2024-01-21 23:44:30 +00:00
rillig cebd2029a2 snprintb.3: remove empty string literals from examples
Suggested by uwe@, as gaps in bitmasks are quite common and thus
shouldn't clutter the code.
2024-01-21 22:06:46 +00:00
rillig 1d4fa4e59b snprintb.3: fix examples
The first example broke the format string at boundaries that didn't
highlight the structure of the format string and also didn't make it
clear that a few bits were omitted from having descriptions.

The second example contained an off-by-one error for SIXTEEN, which was
actually FIFTEEN.

The snprintb_m example repeated the above off-by-one error, and its
output was shown wrong, due to concatenated escape sequences.
2024-01-21 21:31:23 +00:00
lukem c4b7a9e794 bsd.own.mk: rename GCC_NO_* to CC_WNO_*
Rename compiler-warning-disable variables from
	GCC_NO_warning
to
	CC_WNO_warning
where warning is the full warning name as used by the compiler.

GCC_NO_IMPLICIT_FALLTHRU is CC_WNO_IMPLICIT_FALLTHROUGH

Using the convention CC_compilerflag, where compilerflag
is based on the full compiler flag name.
2023-06-03 09:09:01 +00:00
uwe 71118f0693 stat_flags(3): try to improve the descriptions
List all alternative forms recognized by string_to_flags(3).
Both "dump" and "nonodump" are the negative of "nodump".
string_to_flags does not recognize "snap".
Provide xrefs for flag descriptions where applicable.
2023-05-31 21:49:39 +00:00
rillig b2baa50111 lint: warn about extern declarations outside headers
https://mail-index.netbsd.org/tech-userlevel/2023/03/15/msg013727.html
2023-03-28 14:44:34 +00:00
uwe cfe198168b login_cap(3): Markup fixes 2022-12-04 22:51:43 +00:00
uwe 49e10846a6 lib: Mark up error names in man pages with .Er 2022-12-04 11:25:08 +00:00
uwe 4562d402f9 pw_init(3): Use .Ev for EDITOR 2022-12-04 11:16:39 +00:00
uwe e6fc3c59c2 Sections 2 and 3 have RETURN VALUES, not DIAGNOSTICS 2022-12-04 01:29:31 +00:00
christos 020fb940f4 fix date -d 12/01/2022, found by Anon Ymous 2022-04-23 13:02:04 +00:00
rillig 388550b026 lib: remove CONSTCOND comment
Since 2021-01-31, lint doesn't need it anymore for the common pattern of
'do ... while (0)'.
2022-04-19 20:32:14 +00:00
andvar 4b2769fe52 fix typos in word "otherwise". 2021-08-01 15:29:29 +00:00
kre 53e5e3df7a PR bin/56042
Fix typos (2nd acst should have been acdt), 0550 for ist should be 0530
(5.5 hours is not 5 hours and 50 minutes...).

Comment out the zp4 zp5 and zp6 zone names.   They are supposedly supported
by the source (they're in the table) but cannot work, as the parsedate
lexer doesn't allow a "word" to start with an alpha and also contain
digits.   Maybe (just maybe) that could be fixed sometime, but since these
have never worked, and no-one has ever seemed to miss them, and they're the
only words which are of that form, for now, just stop pretending they work.
2021-05-16 19:42:35 +00:00
mrg f96996de73 note that ttyaction.[35] first appeared in netbsd 1.3. 2021-03-21 23:29:36 +00:00
kre 84c54a935f PR lib/46542
Add checks to detect overflow, and also detect other invalid
(out of range) inputs for parsedate().

There could be more, and some of what is being added is not
perfect, but many calculation overflows will be detected now
(and cause an error return) and some of the most bizarre
inputs that were previously accepted no longer will be.
2020-10-30 22:03:11 +00:00
kre dbbe561cbe Check the year field of a tentative ISO-8601 date format for overflow
before committing to it being an 8601 format date, rather than after
(or the fall back grammar parser doesn't start with a clean slate).

This isn't likely to ever bother anyone, the chances of encountering
something that looks just like an 8601 format date, but with a year
field so large it overflows a long are kind of slim.   If it did happen
the chances that the string could be correctly parsed (into something
different) by the grammar are even slimmer. But better to do it properly.
2020-10-19 17:47:45 +00:00
kre 0c44d33848 Catch the parsedate man page up with recent updates, ans also include
some general improvements I've had kicking around for a long time, but
never got around to committing.
2020-10-19 15:08:39 +00:00
kre 569a03414c For touch -d (which uses parsedate()) POSIX specifies that the
ISO-8601 format yyyy-mm-ddTHH:MM:SS[radix_and+frac][Z]
be accepted.

We didn't handle that, as in parsedate(), 'T' represents the
military timezone designator, not a padding separator between
date & time as POSIX specified it.

The way parsedate() is written, fixing this in the grammar/lexer
would be hard without deleting support for T as a zone indicator
(it is *my* timezone!).

So, instead of doing that, parse an ISO-8901 string which occurs
right at the start of the input (not even any preceding white space)
by hand, before invoking the grammar, and so not involving the lexer.
This is sufficient to make touch -d conform.

After doing that, we still need to allow earlier valid inputs,
where an ISO-8601 format (using space as the separator, but without
the 'Z' (Zulu, or UTC) suffix) followed by an arbitrary timezone
designation, and other modifiers (eg: "+5 minutes" work.  So we
call the grammar on whatever is left of the input after the 8601
string has been consumed.   This all "just works" with one exception,
a format like "yyyy-mm-dd hh:mm:ss +0700" would have the grammar parse
just "+0700" which by itself would be meaningless, and so wasn't
handled.    Add a grammar rule & processing to Handle it.

Also note that while POSIX specifies "at least 4" digits in the YYYY
field, we implement "at least one" so years from 0-999 continue to be
parsed as they always have (nb: these were, and continue to be, treated
as absolute year numbers, year 10 is year 10, not 2010).  Years > 2 billion
(give or take) cannot be represented in the tm_year field of a struct tm,
so there's a limit on the max number of digits as well.
2020-10-19 15:08:17 +00:00
kre 28d278e3ae POSIX requires that when converting 2 digit year representations to
actual specific years, values from 69-99 be treated as 20th century,
and values from 0-68 be treated as 21st century.  This allows for those
unfortunate enough to reside in a timezone west of Greenwich to convert
the epoch (or a time very close to it) to text, write that with just two
digits, and correctly convert it back to a time near the epoch, rather
than to something in 2069.

We used to split things so 0-69 were 21st century, and 70-99 were 20th.
Change that (this requires a change in the parsedate ATF tests which
test this specific boundary).

While here, add support for another POSIX requirement, that the radix
char before fractional seconds can be either a ',' or a '.'.  We used
to allow only '.', add support for ','.   This is something of a meaningless
change, as parsedate() returns a time_t in which there is no way to
represent fractional seconds, so there's little point in ever specifying
them regardless of what char is used for the "decimal point" - they will
be ignored anyway.    But at least fractional seconds using a ',' as the
radix char will no longer cause the conversion to fail (or do something else
bizarre).
2020-10-19 15:05:53 +00:00
uwe 172da20a8e Fix grammar. 2020-07-30 21:23:36 +00:00
ryo b061283a45 fail to create a pidfile if hostname contains '/' 2020-03-30 08:24:36 +00:00
msaitoh ba5c90c4a4 s/sucess/success/ in comment. 2019-12-27 09:45:26 +00:00
wiz ec6e765cf3 Remove trailing whitespace. 2019-12-07 12:47:07 +00:00
christos 95fb71b3fc Correct the man page, and say that the printf(3) format characters need
to be uintmax_t.
2019-12-06 19:31:52 +00:00
mrg de11d87641 introduce some common variables for use in GCC warning disables:
GCC_NO_FORMAT_TRUNCATION    -Wno-format-truncation (GCC 7/8)
GCC_NO_STRINGOP_TRUNCATION  -Wno-stringop-truncation (GCC 8)
GCC_NO_STRINGOP_OVERFLOW    -Wno-stringop-overflow (GCC 8)
GCC_NO_CAST_FUNCTION_TYPE   -Wno-cast-function-type (GCC 8)

use these to turn off warnings for most GCC-8 complaints.  many
of these are false positives, most of the real bugs are already
commited, or are yet to come.


we plan to introduce versions of (some?) of these that use the
"-Wno-error=" form, which still displays the warnings but does
not make it an error, and all of the above will be re-considered
as either being "fix me" (warning still displayed) or "warning
is wrong."
2019-10-13 07:28:04 +00:00
christos bfdd69f658 -Wstringop-truncation is only gcc. 2019-10-08 18:50:34 +00:00
christos 573d865676 Ignore strncpy(foo, bar, sizeof(foo)) for the wtmp fields where we don't
want NUL termination. We can't use pragma's because the old gcc complains
about the new warnings it does not understand.
2019-10-04 00:03:56 +00:00
tnn 00bf802c59 annotate __dead 2019-10-03 20:29:19 +00:00
christos 5c84fc8d45 provide a default error function instead of trying to cast exit(3). 2019-10-03 18:12:44 +00:00
brad c59f01cb01 Teach getdiskrawname and getdiskcookedname about zvols.
Reviewed by Christos
2019-08-22 20:23:43 +00:00
kre 63e182f423 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).
2019-04-29 07:55:38 +00:00
wiz fa9ca235d8 Remove trailing whitespace. 2019-04-27 17:58:51 +00:00
christos 1d8a803c77 remove dup line 2019-04-27 17:48:13 +00:00
christos ca3496f0f1 Document the '*' field and give a more complex example with F and *. 2019-04-27 17:46:08 +00:00
msaitoh c2f2b1bf58 s/ the the / the / 2019-03-08 08:12:39 +00:00
alnsn f4bc8af01c Document "ROOT." syntax before documenting a generic . 2018-12-28 18:44:11 +00:00
alnsn a2fe1bd34b No need to quadruple a buffer because strunvis(3) doesn't expand. 2018-12-27 21:35:48 +00:00
christos e0a9077d02 use the right type. 2018-10-06 23:48:00 +00:00