Commit Graph

133 Commits

Author SHA1 Message Date
Arnold D. Robbins
de6284e037 Fix Issue 60; sub/gsub follow POSIX if POSIXLY_CORRECT in the environment. 2020-01-19 20:37:33 +02:00
Arnold D. Robbins
df6ccd2982 Add TODO file. 2020-01-17 14:08:59 +02:00
Arnold D. Robbins
3ed74525f6 Update date in version. 2020-01-17 14:03:52 +02:00
Martijn Dekker
fed1a562c3 Make I/O errors fatal instead of mere warnings (#63)
An input/output error indicates a fatal condition, even if it
occurs when closing a file. Awk should not return success on I/O
error, but treat I/O errors as it already treats write errors.

Test case:

$ (trap '' PIPE; awk 'BEGIN { print "hi"; }'; echo "E $?" >&2) | :
awk: i/o error occurred while closing /dev/stdout
 source line number 1
E 2

The test case pipes a line into a dummy command that reads no
input, with SIGPIPE ignored so we rely on awk's own I/O checking.
No write error is detected, because the pipe is buffered; the
broken pipe is only detected as an I/O error on closing stdout.

Before this commit, "E 0" was printed (indicating status 0/success)
because an I/O error merely produced a warning. A shell script
was unable to detect the I/O error using the exit status.
2020-01-17 14:02:57 +02:00
Martijn Dekker
2976507cc1 rename T.concat to T.csconcat to avoid case-insensitive conflict (#64)
On case-insensitive file systems (i.e.: macOS), T.concat and
t.concat are the same file, so these conflicted. This commit
renames T.concat to avoid the conflict.
2020-01-10 12:13:26 +02:00
Arnold D. Robbins
944989bf68 Minor fixes. 2020-01-06 00:01:46 -07:00
Arnold D. Robbins
c7eeb57210 Fix merging of concatenated string constants. 2020-01-05 21:18:36 +02:00
Arnold D. Robbins
a1aad88728 Correct text in README.md. 2020-01-01 22:45:04 +02:00
Arnold D. Robbins
140802c128 Small formatting cleanups in b.c. 2020-01-01 22:42:50 +02:00
Arnold D. Robbins
3358f3f36b Cleanups from valgrind. 2020-01-01 22:42:20 +02:00
Arnold D. Robbins
7db55ba13f Bug fix in interval expressions. 2019-12-27 12:03:35 +02:00
Arnold D. Robbins
1951e01288 More edits in README.md. 2019-12-11 21:15:38 +02:00
Arnold D. Robbins
eda30ac8c5 Add last updated date to README.md. 2019-12-11 20:53:26 +02:00
Arnold D. Robbins
bab7b07f01 Move README to README.md. 2019-12-11 20:52:54 +02:00
Arnold D. Robbins
0b82bc6eb4 Small edits, update version and FIXES. 2019-12-11 09:24:38 +02:00
zoulasc
a96aebbbd6 Fix printf format conversions. (#59)
Further simplify printf % parsing by eating the length specifiers
during the copy phase, and substitute 'j' when finalizing the format.
Add some more tests for this.
2019-12-11 09:17:34 +02:00
zoulasc
af86dacfad Fix memory corruption manifested on 32 bit binaries (#58)
* Don't update gototab entries for HAT (corrupts memory)
2019-12-09 09:00:45 +02:00
Arnold D. Robbins
416c6db5ee Update version and FIXES. 2019-12-08 21:43:32 +02:00
zoulasc
ff5d67610c Fix printf formats for integers (#57)
* More cleanups:
- sprinkle const
- add a macro (setptr) that cheats const to temporarily NUL terminate strings
  remove casts from allocations
- use strdup instead of strlen+strcpy
- use x = malloc(sizeof(*x)) instead of x = malloc(sizeof(type of *x)))
- add -Wcast-qual (and casts through unitptr_t in the two macros we
  cheat (xfree, setptr)).

* More cleanups:
- add const
- use bounded sscanf
- use snprintf instead of sprintf

* More cleanup:
- use snprintf/strlcat instead of sprintf/strcat
- use %j instead of %l since we are casting to intmax_t/uintmax_t

* Merge the 3 copies of the code that evaluated array strings with separators
and convert them to keep track of lengths and use memcpy instead of strcat.

* Fix formats for 32 bit machines broken by previous commit.
We use intmax_t to provide maximum range for both 32 and 64 bit machines.
2019-12-08 21:41:27 +02:00
Arnold D. Robbins
108224b484 Convert variables to bool and enum. 2019-11-10 21:19:18 +02:00
Arnold D. Robbins
c879fbf013 From Ori Bernstein, ori@eigenstate.org, for FS="" in multibyte locale. 2019-11-08 14:40:18 +02:00
Arnold D. Robbins
0e1bebcc09 Small fixes in the test suite. 2019-11-08 14:36:37 +02:00
Arnold D. Robbins
b73bfabb42 Typo fix in FIXES. 2019-11-08 14:31:05 +02:00
Arnold D. Robbins
2a8f1758b9 Update FIXES and main.c version. 2019-10-25 11:03:02 -04:00
Arnold D. Robbins
938b26cfae Don't use 'j' flag on %x. Remove an unnecessary cast. 2019-10-25 11:01:17 -04:00
zoulasc
0d8778bbbb more cleanups (#55)
* More cleanups:
- sprinkle const
- add a macro (setptr) that cheats const to temporarily NUL terminate strings
  remove casts from allocations
- use strdup instead of strlen+strcpy
- use x = malloc(sizeof(*x)) instead of x = malloc(sizeof(type of *x)))
- add -Wcast-qual (and casts through unitptr_t in the two macros we
  cheat (xfree, setptr)).

* More cleanups:
- add const
- use bounded sscanf
- use snprintf instead of sprintf

* More cleanup:
- use snprintf/strlcat instead of sprintf/strcat
- use %j instead of %l since we are casting to intmax_t/uintmax_t

* Merge the 3 copies of the code that evaluated array strings with separators
and convert them to keep track of lengths and use memcpy instead of strcat.
2019-10-25 10:59:09 -04:00
Arnold D. Robbins
1d6ddfd9c0 Optimize string concatenation. 2019-10-24 10:06:10 -04:00
Arnold D. Robbins
8b92a4abcb Add 'distclean' target to makefile. 2019-10-24 09:44:00 -04:00
Arnold D. Robbins
961eec1fb5 Additional fixes after merge of PR 53. 2019-10-24 09:42:51 -04:00
zoulasc
6589208eaf More cleanups: (#53)
- sprinkle const
- add a macro (setptr) that cheats const to temporarily NUL terminate strings
  remove casts from allocations
- use strdup instead of strlen+strcpy
- use x = malloc(sizeof(*x)) instead of x = malloc(sizeof(type of *x)))
- add -Wcast-qual (and casts through unitptr_t in the two macros we
  cheat (xfree, setptr)).
2019-10-24 09:40:15 -04:00
Arnold D. Robbins
1633ba1c88 Update FIXES and date in main.c. 2019-10-17 13:06:21 -04:00
zoulasc
c16e8696d7 Amended the all pull request. (#51)
* [from NetBSD]
- dynamic state allocation
- centralize vector growth
- centralize int array allocation
- no casts for void * functions

* - add missing allocation
- revert change loop in pmatch
2019-10-17 13:04:45 -04:00
Arnold D. Robbins
0ba1d0391d Small code formatting fix in run.c. 2019-10-08 10:30:09 +03:00
Arnold D. Robbins
5ff28208db Fix compile warnings. 2019-10-07 15:50:53 +03:00
Arnold D. Robbins
7cae39dfa5 Make RS as regexp work without ifdef. Add doc, bump version. 2019-10-06 22:34:20 +03:00
Arnold D. Robbins
643a5a3dad Add RS as regex code, ifdefed-out, from NetBSD. 2019-09-10 12:19:48 +03:00
Arnold D. Robbins
34a6f41cca Update FIXES and version date in main.c. 2019-09-10 09:57:07 +03:00
Alexander Richardson
ad9bd2f40a Avoid creating an out-of-bounds pointer in word() (#48)
As it is never dereferenced in the n == -1 case it shouldn't cause any
problems. However, UBSAN complains about this, so it is required to run
the tests when compiling with -fsanitize=undefined.
2019-09-10 09:54:53 +03:00
Alexander Richardson
cbf924342b Fix out-of-bounds access in gototab array for caret character (#47)
When matching a caret, the expression	`f->gototab[s][c] = f->curstat;` in
cgoto() will index the 2D-array gototab with [s][261]. However, gototab
is declared as being of size [NSTATES][NCHARS], so [32][259]. Therefore,
this assignment will write to the state for character 0x1.
I'm not sure how to create a regression test for this, but increasing the
array size to HAT+1 values fixes the error and the tests still pass.

I found this issue while running awk on a CHERI system with sub-object
protection enabled. On x86, this can be reproduced by compiling awk
with -fsanitize=undefined.
2019-09-10 09:54:11 +03:00
Sevan Janiyan
50e6962495 Drop Mac OS 9 reference (#46)
"buildmac" file is no longer supplied.
2019-08-13 20:27:51 +03:00
Arnold D. Robbins
c95b96020f Grammar optimization from NetBSD: Two adjacent string constants are merged. 2019-07-28 20:09:24 +03:00
Arnold D. Robbins
795a06b58c Remove trailing whitespace on lines in all files. 2019-07-28 05:51:52 -06:00
Arnold D. Robbins
cebda366a9 Improve cleanup of test directory upon 'make clean'. 2019-07-26 12:57:48 +03:00
Martijn Dekker
5b602ca8a2 Add support for "\a" and "\v" to regex and command line args (#44)
Support POSIX-specified C-style escape sequences "\a" (alarm)
and "\v" (vertical tab) in command line arguments and regular
expressions, further to the support for them in strings added on
Apr 9, 1989. These now no longer match as literal "a" and "v"
characters (as they don't on gawk and mawk).

IOW, lex.c already supported these (lines 390-391 as of 4e343460);
the support needed to be added to b.c and tran.c.

Relevant POSIX reference:
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html#tag_20_06_13_04
2019-07-26 11:46:58 +03:00
Arnold D. Robbins
4e34346094 Update FIXES and main.c version. 2019-07-17 21:14:52 +03:00
M. Warner Losh
9310d452c9 Apply the following from FreeBSD / OpenBSD:
323965 | imp | 2017-09-23 23:04:06 -0600 (Sat, 23 Sep 2017) | 8 lines

Don't display empty error context.

Context extraction didn't handle this case and showed uninitialized memory.

Obtained from: OpenBSD lib.c 1.21
Sponsored by: Netflix
Differential Revision: https://reviews.freebsd.org/D12379
2019-07-16 22:23:19 +03:00
M. Warner Losh
0939e3392b Apply r323963 from FreeBSD (pulling in the fix from OpenBSD)
| Fix uninitialized variable
|
| echo | awk 'BEGIN {i=$1; print i}' prints a boatload of stack
| garbage. NUL terminate the memory returned from malloc to prevent it.
|
| Obtained from: OpenBSD run.c 1.40
| Sponsored by: Netflix
| Differential Revision: https://reviews.freebsd.org/D12379
2019-07-16 22:23:02 +03:00
M. Warner Losh
966fdc9c29 Bring in fix from FreeBSD:
| r323964 | imp | 2017-09-23 23:04:02 -0600 (Sat, 23 Sep 2017) | 6 lines
|
| Fix %c for floating values that become 0 when coerced to int.
|
| Obtained from: OpenBSD run.c 1.36 (From Jeremy Devenport)
| Sponsored by: Netflix
| Differential Revision: https://reviews.freebsd.org/D12379
2019-07-16 22:21:33 +03:00
pfg
c70b9fe882 awk: Use random(3) instead of rand(3)
While none of them is considered even near to cryptographic
level, random(3) is a better random generator than rand(3).

Use random(3) for awk as is done in other systems.

Thanks to Chenguang Li for discussing this in the lists
and submitting the patch upstream.

PR:		193147
MFC after:	5 weeks

git-svn-id: svn+ssh://svn.freebsd.org/base/head@271879 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
2019-07-16 22:19:56 +03:00
pfg
650d868ec4 MFV r315425: one-true-awk: have calloc(3) do the multiplication.
MFC after:	3 days

git-svn-id: svn+ssh://svn.freebsd.org/base/head@315426 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
2019-07-16 22:12:26 +03:00