Ben Pfaff [Mon, 6 Dec 2021 05:18:22 +0000 (21:18 -0800)]
distributions: New module for probability distribution functions.
These functions are currently just used in expressions, but in an upcoming
commit they will also be used in matrices, so this commit makes them more
widely available.
Ben Pfaff [Mon, 6 Dec 2021 17:02:30 +0000 (09:02 -0800)]
lexer: Be consistent across 32/64 bit in lex_force_int_range().
The exact error message that this function reported varied between 32-
and 64-bit platforms for invalid integers that require more than 32 bits
but no more than 64 bits, since "long int" has a different range between
those platforms. This commit fixes the problem.
This issue caused the test "testing lexer crash due to overflow" to fail
on 32-bit platforms.
Thanks to Friedrich Beckmann for reporting the problem.
Ben Pfaff [Wed, 6 Oct 2021 05:15:28 +0000 (22:15 -0700)]
expressions: Parse multiple sets of parentheses for grouping together.
Fuzzers are fond of driving expression parsers to failure by exhausting
the stack in trivial ways. This defeats the simplest attempts by
lining up thousands of left parentheses in a row.
I am a bit curious whether the fuzzer will now invent something more
sophisticated, such as nested function calls or non-empty expressions like
1+(1+(1+(1+(1+....
This fixes bug #61286.
Thanks to Irfan Ariq for reporting the bug.
Ben Pfaff [Tue, 5 Oct 2021 16:19:26 +0000 (09:19 -0700)]
dictionary: Allow dict_set_documents() argument to reference old documents.
merge_dictionary() in combine-file.c includes the old documents in the new
ones by just copying pointers. dict_set_documents() didn't handle this
properly. This fixes the problem.
Fixes bug #61258.
Thanks to Irfan Ariq for reporting the problem.
Ben Pfaff [Sun, 26 Sep 2021 18:06:45 +0000 (11:06 -0700)]
lexer: Fix use-after-free error in lex_source_get_lookahead().
This code used local variable 'out' as if its value stayed the same from
one iteration of the loop to the next, but in fact its scope meant that
it became indeterminate on each new iteration. This commit fixes the
problem by moving its declaration to an outer scope.
Thanks to John Darrington for reporting the problem.
Ben Pfaff [Wed, 1 Sep 2021 17:02:26 +0000 (10:02 -0700)]
macro: Fix crash for !QUOTE of a quoted string.
This revealed that the tests didn't include anything for !QUOTE and
!UNQUOTE, even though the manual had lots of examples. I added a test for
these and for !NULL, which had also been forgotten.
Ben Pfaff [Thu, 26 Aug 2021 16:32:31 +0000 (09:32 -0700)]
DEFINE: Only expand macro functions when the name is followed by '('.
Frans Houweling reported that PSPP was flagging an error for !EVAL(!len)
when !len was the name of a defined macro. This was because !len is short
for the !LENGTH macro function. This commit fixes the problem.
Ben Pfaff [Sun, 18 Jul 2021 21:21:24 +0000 (14:21 -0700)]
lexer: Change the pipeline to allow more flexible use of macros.
Frans Houweling reported that a use of macros in the following way:
DEFINE !dir() "/directory/to/my/work" !ENDDEFINE.
GET FILE=!dir + "/filename.sav".
did not work properly with the newly implemented PSPP macro facility.
Indeed, PSPP has until now implemented string concatenation early in the
lexical pipeline, before macro expansion, so that the above could
not work. This commit reworks it so that string concatenation happens
as the last stage in lexical analysis. It allows the above syntax
to work as expected.
Ben Pfaff [Mon, 5 Jul 2021 20:46:32 +0000 (13:46 -0700)]
configure: Enable GCC warnings to report use of C2x features.
One C2x feature in GCC 11 is the reason that the previous commit afda22462a88 ("Fix broken build due to missing braces") was needed by
some developers.
Ben Pfaff [Sun, 4 Jul 2021 05:00:47 +0000 (22:00 -0700)]
segment: Distinguish snippets from full files.
The comment on segmenter_init() explains what this means:
If IS_SNIPPET is false, then the segmenter will parse as if it's being
given a whole file. This means, for example, that it will interpret -
or + at the beginning of the syntax as a separator between commands
(since - or + at the beginning of a line has this meaning).
If IS_SNIPPET is true, then the segmenter will parse as if it's being
given an isolated piece of syntax. This means that, for example, that
it will interpret - or + at the beginning of the syntax as an operator
token or (if followed by a digit) as part of a number.
Ben Pfaff [Sun, 30 May 2021 20:31:39 +0000 (13:31 -0700)]
segment: Refine treatment of start of macro body.
Previously, if the first line of the macro body (the same line as the
closing parenthesis in the DEFINE) was blank, we reported it as a blank
line to the lexer. The parser for DEFINE could check for that (by seeing
whether the first line of macro body was empty or all-spaces) but it seems
more elegant to do it in the segmenter. This implements that.