Commit Graph

20931 Commits

Author SHA1 Message Date
rillig 0ec48ab17e lint: condense code for strict bool mode 2024-05-12 12:32:39 +00:00
rillig 681c37d9da lint: in strict bool mode, allow do-while-0
Even though 0 is not a boolean constant, allow this common idiom, to
help in those cases where the C preprocessor used by lint does not mark
tokens as coming from system headers (Clang).
2024-05-12 12:28:34 +00:00
rillig 88d3a49009 lint: don't call memcpy with null pointer
Even copying 0 bytes from a null pointer invokes undefined behavior.
2024-05-12 09:07:41 +00:00
rillig 922b235ff9 lint: move code for parsing balanced token sequences to lex.c
To access yytext from lex.c, the lexer needs to be in %pointer mode,
which was specified in IEEE Std 1003.1, 2004 Edition and thus should be
old enough to be available on platforms other than NetBSD, for use in
tools/lint1 where lint1 is built before yacc and lex.
2024-05-12 08:48:36 +00:00
christos a3cbce7519 Only mark the terminfo entry promoted if actually was. 2024-05-11 22:06:57 +00:00
rillig 7eb83dabf6 lint: clean up grammar rule name for 'type_specifier' 2024-05-11 16:58:59 +00:00
rillig 4bd7e6e13f lint: parse but otherwise ignore C23 attributes
The C23 attributes are only parsed before an expression in an expression
statement, as a proof of concept.  Other places will follow later.
2024-05-11 16:12:28 +00:00
rillig 9cfc443f88 lint: warn when comparing an integer to a floating point constant 2024-05-11 15:53:38 +00:00
rillig fd614d9435 lint: clean up conversion from floating point constant 2024-05-10 21:43:40 +00:00
rillig d5c41e0169 error: disable lint's strict bool mode when building with Clang
The Clang preprocessor does not mark sections from system headers.
Lint's strict bool mode relies on these markers to allow the functions
from <ctype.h> to be used as 'bool', even though their declared return
type is 'int'. Without these markers, lint complains that the "right
operand of '&&' must be bool, not 'int'". Until this is fixed in lint,
disable strict bool mode.
2024-05-10 09:27:27 +00:00
wiz 30bb22f9da nstall(1): add support for -v
Reviewed by rillig@ and thorpej@, thanks!
2024-05-10 09:14:52 +00:00
rillig 64ab641533 lint: in C23 mode, allow storage classes in compound literals 2024-05-09 20:56:41 +00:00
rillig 2d37fed27b lint: add details to message about too many initializers 2024-05-09 20:53:13 +00:00
rillig 98b1d3b32e lint: sync grammar rule names with C11 and C23 2024-05-09 20:22:20 +00:00
rillig 2389db7096 lint: sort grammar rules according to the order they appear in C23 2024-05-09 20:15:05 +00:00
rillig 151775b8cf lint: in C23 mode, support the nullptr constant 2024-05-09 11:08:07 +00:00
rillig 1cdc580354 lint: in C23 mode, support the keywords 'bool', 'false' and 'true' 2024-05-07 21:13:26 +00:00
sjg 696821dd99 make: all command line overrides go in .MAKEOVERRIDES
Not all variables that start with '.' are internals,
and unless they are explicitly flagged as internal should go
into .MAKEOVERRIDES

Update varname-dot-makeoverrides to check this.

Also avoid using SCOPE_CMDLINE when ReadOnly will do.
2024-05-07 18:26:22 +00:00
reed b3ebb17e10 Install the mkcsmapper.1 and mkesdb.1 manpages. 2024-05-04 19:10:04 +00:00
mlelstv c2c241e6a6 Bail if increment is too small for the precision to avoid an infinite loop. 2024-05-04 13:29:41 +00:00
christos 5b4135cd6f PR/58233: RVP: Fix lzip dictionary size calculation 2024-05-04 13:18:06 +00:00
christos f57e938466 PR/58223: RVP: Don't write to stdout when testing. 2024-05-04 13:17:03 +00:00
rillig 1772ff8ac7 lint: increase debug logging for declarations
All changes to the global variable 'dcs' are tracked now, to help
identify the cause of the failing tests in expr_sizeof and
gcc_attribute_aligned.

While here, test more invalid type combinations in typedefs.
2024-05-04 06:52:16 +00:00
rillig 3e0eea9ed1 lint: measure the alignment in bytes, not bits
While measuring the alignment in bits makes sense when building a struct
type with bit-fields, in all other places it is more confusing than
helpful.

The only visible change is that in debug mode, the format of type sizes
and alignment changed.  Since the size of all complete types is a
multiple of a byte (as defined in the C standard), sizes and alignments
are reported in bytes as well.  Only while a struct is being built, the
type size may include an additional '+x' for the bits of a bit-field.
2024-05-03 04:04:17 +00:00
christos 35564cfd71 comment out strict boolean lint check because isspace() returns int and lint
complains.
2024-05-02 15:45:36 +00:00
rillig 571b49008c lint: make 'offsetof(t, array-member)' a constant expression
The macro 'offsetof(t, m)' already expanded to a constant expression for
scalar members but not for arrays.  This was because the macro expanded
to '(size_t)(((t *)0)->m)', which lint internally represents as
'addr(indir(ptr(0) + offset(m)))', and build_address simplifies
'addr(indir(x))' to 'x' if the types match.  The types only match for
scalar types though, but not for arrays.

When build_address happens, the type information is incomplete,
therefore 'offsetof(t, array)' has to be simplified at a later point.
2024-05-01 17:42:57 +00:00
rillig d69057212d lint: fix size of struct with large alignment
Lint now successfully passes all compile-time assertions in the amd64
kernel that deal with struct sizes.
2024-05-01 10:30:56 +00:00
rillig 313458bc0b lint: support _Alignas and __attribute__((__aligned(4))) 2024-05-01 07:40:11 +00:00
rillig de44edfce0 lint: fix warning about out-of-bounds bit-field value 2024-05-01 05:49:33 +00:00
sjg 820ce66425 Subst DEFSYSPATH in deptgt-phony 2024-04-30 16:41:32 +00:00
sjg 7e10b2067b make: ensure '.include <makefile>' respects MAKESYSPATH
Since Dir_FindFile is used by '.include' and its variants,
and will first search .CURDIR unless the give path starts with
".DOTLAST".

Update unit-tests/opt-m-include-dir to test this.
2024-04-30 16:13:33 +00:00
rillig adc3ee3bfc make: don't reallocate memory after evaluating an expression
When an expression is evaluated, the resulting text is short-lived in
almost all cases.  In particular, the compaction neither affects the
target names nor the global variable values, which are the prime
candidates for permanent memory usage.
2024-04-28 15:10:19 +00:00
rillig c63a9c06a9 make: fix comment about forcing a use-after-free
The previous expression didn't cause any bug, as the modifier
':@VAR@loop@' changed the value of the expression, thus making the
expression independent from the variable value.

Instead, the variable needs to be deleted from within an indirect
modifier, and that modifier needs to evaluate to an empty string, thus
doing nothing and preserving the original expression value.
2024-04-27 21:26:23 +00:00
rillig c453a669e3 make: clean up, test .NOPATH
Trim down the comments in the archive module, as they mainly repeated
the code.  Trim down the binary code size in the archive module, as it
is rarely used.

In Var_Parse, delay two variable assignments until they are actually
needed.
2024-04-27 20:41:32 +00:00
rillig c639dd27e0 tests/make: test detection of static library files 2024-04-27 20:23:22 +00:00
rillig 1bf9200945 make: simplify freeing of lists 2024-04-27 17:33:46 +00:00
rillig fc7f5da782 lint: converting a null pointer to another pointer type is not narrowing 2024-04-27 12:46:37 +00:00
rillig 96381692fe lint: add query for conversion from void pointer to other pointer 2024-04-27 10:08:54 +00:00
rillig 4da1077ff7 make: in parallel mode, print the directory in which a job failed
When multiple targets run in parallel, the "stopped in" line may be
several lines away from the "Failed target" line, making them hard to
correlate.
2024-04-26 17:11:22 +00:00
rillig 3f936286b0 make: clean up comments, code and tests 2024-04-23 22:51:28 +00:00
rillig 9799297d00 make: trim down code for parsing the :gmtime and :localtime modifiers
The :gmtime and :localtime modifiers are not used often and thus are not
time-critical. Exchange the custom code that parses an integer from a
substring for an additional memory allocation.

Thanks sjg@ for suggesting to avoid the custom parsing code.
2024-04-21 21:59:48 +00:00
rillig 7541e76b18 make: fix out-of-bounds read when evaluating :gmtime and :localtime
The function TryParseTime takes a pointer to a string, but the LazyBuf
returns a Substring, which is not guaranteed to be null-terminated or
delimited.  In TryParseTime, calling strtoul on the Substring read past
the end of the substring.

Noticed in the NetBSD build in libntp, where the :gmtime modifier is
used in two places with the same timestamp value, of which the first was
evaluated correctly and the second wasn't.

The bug was introduced in var.c 1.1050 from 2023-05-09, when the
argument of the :gmtime and :localtime modifiers was allowed to be an
expression instead of an integer constant.
2024-04-21 08:56:49 +00:00
rillig f56f0d26c4 {usr.,}{s,}bin: replace LINT_SUPPORTED with the standard NOLINT
While here, re-enable lint in those cases where lint was skipped due to
a bug in interpreting abstract types, which was fixed in cgram.y 1.469
from 2023-08-02.
2024-04-20 13:24:48 +00:00
rillig 873c42efc3 make: provide more context information for parse/evaluate errors 2024-04-20 10:18:55 +00:00
gutteridge f9cbc07bc5 ftp.1: drop a sentence that's no longer accurate 2024-04-17 02:46:03 +00:00
rillig 9c7f0367c1 make: make string matching platform-independent
Previously, whether the character range '[a-ä]' matched, depended on the
signedness of the plain 'char' type.  Since make operates on byte
strings and does not support UTF-8 or other multi-byte character
encodings, this edge case is not expected to occur in practice.

No change in the unit tests as this edge case is not covered by tests.
2024-04-14 15:21:20 +00:00
rillig 141cc6832d make: add debug logging for .if and .for lines in -dp mode
This helps track down in which line a condition is evaluated.
2024-04-14 12:30:47 +00:00
rillig f5fb6d1056 lint: clean up and speed up the check for snprintb 2024-04-12 05:44:38 +00:00
rillig dae6022bba lint: in snprintb, warn about all escaped characters in descriptions 2024-04-12 05:17:48 +00:00
riastradh 6dc5a3c0cc config(1): Make sort order deterministic.
Ensure we break ties in every case.  This way, even though we use the
unstable qsort(3) library routine, the output is reproducible, no
matter what algorithm is behind qsort(3).

It would be nice if we could just use a stable sort function here,
but mergesort(3) is nonstandard, so we'd have to add it to
tools/compat, which is a big pain.

Instead, put a tie-breaking rule in every comparison function we use
with qsort, and abort() in the event of ties -- that way, we noisily
refuse to rely on unstable sort order.

While here, dispense with any question of integer overflow, and
sprinkle comments.

PR bin/58115
2024-04-05 00:43:42 +00:00
rillig 3b221c13be tests/make: pass PATH onto child processes
This fixes the tests on some Cygwin variant where the shell does not
initialize the PATH environment variable when it's missing.
2024-04-02 15:05:15 +00:00
christos 01d7b23489 oops the #endif was too far down. 2024-04-02 12:42:35 +00:00
rillig fac77563b5 tests/make: remove test for overly long chdir argument
On Cygwin, the path '/././..././' is normalized before being passed to
the child 'make' process. Since overly long pathnames are not required
to be supported on all platforms, remove the test.
2024-04-02 11:11:00 +00:00
christos d3697da1f3 Handle not having SIGINFO (Jan-Benedict Glaw) 2024-04-01 22:20:58 +00:00
riastradh ad49149131 elftoolchain: Be consistent about which ELF header files we use.
1. For tools that use elftoolchain: always use elftoolchain's
   elfdefinitions.h.  Don't even think about looking at the host's
   sys/exec_elf.h, which makes no sense and should never happen.

   (ELF tools that don't use elftoolchain, like m68k-elf2coff,
   continue to use nbincludes/sys/exec_elf.h.  But no more nbincludes
   hacks in elftoolchain.)

2. For kernel components (solaris, zfs, dtrace): always use
   sys/exec_elf.h, even in Solaris components via sys/elf.h.
   elfdefinitions.h is not wired up in the kernel build at all.

3. For most userland components that involve libelf: use
   elfdefinitions.h via libelf header files (libelf.h, gelf.h).

   libdtrace in particular requires _all_ R_* reloc type definitions,
   but sys/exec_elf.h brings in only the _current machine's_ R_*
   reloc type definitions.  (While here: Use uintptr_t instead of
   Elf_Addr for pointer-to-integer cast, since Elf_Addr is MD and
   provided only by sys/exec_elf.h, not by elfdefinitions.h.)

   And most userland components using libelf don't rely on any
   properties of the current machine from sys/exec_elf.h, so they can
   use libelf's elfdefinition.h.

   Exceptions:

   - dtrace drti.c relies on link.h -> link_elf.h -> sys/exec_elf.h,
     but it also relies on sys/dtrace.h -> sys/elf.h ->
     elfdefinitions.h like other userland components using sys/elf.h.

   - kdump-ioctl.c uses sys/exec_elf.h directly and sys/dtrace.h ->
     sys/elf.h -> elfdefinitions like other userland components using
     sys/elf.h.

   - t_ptrace_wait.c (via t_ptrace_core_wait.h) uses libelf to parse
     core files, but relies on sys/exec_elf.h for struct
     netbsd_elfcore_procinfo.

   None of these exceptions needs all R_* reloc type definitions, so
   as a workaround, we can just suppress libelf's elfdefinitions.h by
   defining _SYS_ELFDEFINITIONS_H_ and use sys/exec_elf.h in these
   exceptions.

And undo the whole BUILTIN_ELF_HEADERS mistake.  This was:

- half bogus workarounds for missing build_install dependencies in
  tools/Makefile, which are no longer missing now, and
- half futile attempt to use src/sys/sys/exec_elf.h via nbincludes in
  tools involving libelf instead of libelf's elfdefinitions.h, which
  collides.

Longer-term, we may wish to unify sys/exec_elf.h and libelf's
elfdefinitions.h, so we don't have to play these games.

But at least now the games are limited to three .c files (one of
which is generated by Makefile.ioctl-c), rather than haphazardly
applied tree-wide by monstrous kludges in widely used .h files with
broken hackarounds to get the tools build lurching to completion.
2024-04-01 18:33:22 +00:00
rillig 9b0e4f6f67 make: remove unreachable code in handling .for loops 2024-04-01 12:33:27 +00:00
rillig 311476f316 make: exit immediately after reading a null byte from a makefile
The chance of other garbage bytes in such a file is just too high.
2024-04-01 12:26:02 +00:00
christos ce9d65703d make it work as a tool 2024-04-01 02:21:39 +00:00
christos d8b33778ce - -n is the default on SMALL, so accept the flag silently.
- conditionalize TIMESPEC_TO_TIMEVAL
- add nbtool_config.h
2024-04-01 02:20:52 +00:00
rillig 05808a2230 lint: merge function call operators 'CALL' and 'ICALL' 2024-03-31 20:28:45 +00:00
rillig 0d863cbdf8 lint: document which fields are not reset when starting a new type
Setting all visible fields to their null value seemed as if the whole
object were reset.
2024-03-30 19:51:00 +00:00
martin 48ac458e6d Note NetBSD 10.0 2024-03-30 19:33:05 +00:00
rillig 0382e641fc lint: in the query about implicit conversions, ignore casts 2024-03-30 19:12:37 +00:00
rillig 370056d3b9 lint: add query for implicit integer-to-floating conversion 2024-03-30 17:23:13 +00:00
rillig def8e1797a lint: do not convert array subscripts from size_t to ptrdiff_t
The C standards do not specify a fixed type for an array subscript, it
just has to be an integer type.  Previously, query 4 fired for the
ubiquitous expression 'ptr[sz]' when sz had type 'size_t'.

The test platform_ilp32_long is unaffected by this change, as the
integer constant 0x80000000 has type 'unsigned int', while size_t is
'unsigned long' on those platforms, and even though the types 'unsigned
int' and 'unsigned long' have the same value space, there's still a
conversion, at least for now.
2024-03-30 17:12:26 +00:00
rillig c6466ed0f7 lint: reword messages about array subscripts to sound more natural 2024-03-30 16:47:44 +00:00
rillig 1219592417 lint: clean up 2024-03-29 08:35:31 +00:00
rillig 55398a9a51 lint: fix wording of warning about bit-field initializer 2024-03-29 07:35:45 +00:00
rillig 134116ce30 lint: clean up 2024-03-28 21:04:48 +00:00
rillig 30c6c279e2 lint: add missing assignment to $$ in grammar
Byacc and Bison both provide this assignment for all actions, whether
default or not, but the wording in POSIX doesn't guarantee this.
2024-03-27 21:14:09 +00:00
rillig 8910413e27 lint: clean up; extend overflow test 2024-03-27 20:09:43 +00:00
rillig e57698da95 lint: don't use 'long' in diagnostics
The size of 'long' differs between 64-bit and 32-bit platforms.
Eliminate this possible platform-dependency.
2024-03-27 19:28:20 +00:00
rillig 216c89c02b lint: fix warnings about loss of accuracy on bit-field operations 2024-03-25 23:39:13 +00:00
rillig 64230f3217 lint: rename snprintb 'directives' to 'conversions'
This aligns the terminology with the snprintf function.
2024-03-25 22:37:43 +00:00
mrg 707adea339 match message & conversion function name properly.
probably should make this into an array with two members.
2024-03-20 20:19:31 +00:00
mrg eb1fa7eb4a audio_wav_parse_hdr: handle zero-length data files again
the previous clean up turns zero-length data into no data and thus
an error, instead of simply doing nothing.  noted by gson.
2024-03-20 20:18:39 +00:00
rillig d7b3b04319 lint: keep invalid arguments in function calls
Previously, arguments of incomplete type or 'void' cleared all arguments
of the function call expression, requiring extra checks in later checks.

Invalid function calls are now exported to the .ln files, but that's
irrelevant in practice as these invalid function calls make lint1 fail,
after which xlint removes the .ln file.
2024-03-19 23:19:03 +00:00
andvar a5c0af2445 Add missing "e" in few words, in comments and one log message. 2024-03-17 21:48:01 +00:00
andvar bb2336b065 s/argumment/argument/ in documentation. 2024-03-17 21:37:53 +00:00
ryoon 5970d5082c Remove debug print 2024-03-16 23:40:25 +00:00
rillig 083828859c stat: don't allow numeric formatting flags on strings
Calling snprintf with "%+s" invokes undefined behavior.
2024-03-14 21:17:54 +00:00
kre cdaa157c5b While the change in 1.51 certainly retained binary compat with
what was in 1.50 (while silencing LINT) - it was clearly not the
correct change to make.   The code used !FLAG_POUND where it
clearly meant ~FLAG_POUND ... the former is 0, so &= 0 could
be replaced by =0 changing nothing.   But that's not what it
should have been doing, other flags should not have been
removed here, just FLAG_POUND.

This problem seems to have existed since support for %#s
was first added in 2011, which kind of suggests how rarely
that format, particularly with other flags (like %#-s)
has ever been used (with no other flags, the bug would not
be noticed).
2024-03-14 19:38:56 +00:00
rillig 45a5eb6da3 stat: fix lint warning about constant argument to '!'
No binary change.
2024-03-14 00:07:20 +00:00
mrg 21fadbc4fc fix some sizeof() confusion.
using "const char search[4]" as a function parameter means that
"search" is actually a pointer type so "sizeof search" returns
8 on 64-bit platforms.  i mis-read this and used "sizeof *search"
which is always 1, noted by rillig.

instead of trying to avoid writing "4" twice, put it in a define
and use that in various places instead.  annoying.
2024-03-14 00:00:31 +00:00
rillig a1988d862f lint: trim down the check for snprintb formats 2024-03-13 06:48:49 +00:00
rillig 9b239cc71c lint: fix warning about loss of conversion for unsigned bit-fields
Since decl.c 1.180 from 2021-05-02.
2024-03-12 07:56:08 +00:00
mrg c783de976f audioplay(1): handle mis-aligned RIFF chunks.
put the code to find RIFF chunks into a new find_riff_chunk() function,
and handle mis-aligned chunk lengths.  can now play files with chunks
that say they are 7 bytes long, and have 1 byte padding.

add some -V -V extra-verbose for the wav parser.
2024-03-12 00:34:38 +00:00
mrg cfa155a807 minor clean up in the RIFF/WAVE header checking.
use memcmp() not strncmp() to check for "RIFF" and "WAVE".
avoid endian convesion on part.len 3 times.
2024-03-11 23:12:29 +00:00
mrg c62cdc0d11 be sure to byte swap ext.len when checking/printing it.
noted by rillig@.
2024-03-11 19:17:52 +00:00
rillig dd848dec1a lint: add details to the message about integer overflow
Having only the operator was too unspecific to be actionable, so add the
actual numbers and the data type.
2024-03-10 19:45:14 +00:00
rillig 13c8c0a7de kdump: keep the comment with its corresponding code
No binary change.
2024-03-10 18:54:41 +00:00
christos b0c85e5803 decode some {g,s}etsockopt*. 2024-03-10 17:08:31 +00:00
rillig 7be18902ad lint: clean up tree matcher for snprintb calls 2024-03-10 16:27:16 +00:00
rillig bd9743d3db lint: saturate signed integer overflow
In array address calculations, this prevents a 'array subscript cannot
be negative' for large array subscripts.
2024-03-10 16:06:13 +00:00
rillig 08d1bd5c72 lint: fix integer overflow detection
Previously, an unsigned operation that had a negative result went
undetected in a few cases. Now, all results that are not representable
by their type are considered overflows.

The implementation of signed shift-right had been wrong for a few
commits.
2024-03-10 15:49:12 +00:00
rillig ee7b09445f lint: clean up check for overflow in integer constants 2024-03-10 14:42:04 +00:00
rillig 51858eeb3e lint: detect more cases of integer overflow in constant expressions
For unsigned integers, detect when 'a + b' wraps around.
2024-03-10 14:32:30 +00:00
rillig ee9f134f18 lint: split integer overflow check into separate functions
The checks for unsigned and signed integers differ for each operator, so
there's no point having both parts in the same function.
2024-03-10 12:50:45 +00:00
rillig 25f6e58591 lint: remove wrong warning about overflow in unary '-' for unsigned 2024-03-10 10:31:29 +00:00
rillig 34885a599d lint: fix integer overflow in integer overflow check 2024-03-10 10:15:51 +00:00