summaryrefslogtreecommitdiff
path: root/sys/src/cmd/awk
AgeCommit message (Collapse)Author
2023-04-06awk: getline: do not access unitialized data on EOFJacob Moody
echo 'a' | awk 'BEGIN { getline l; getline l; print (s=substr(l,1,10)) " len=" length(s) }' https://github.com/onetrueawk/awk/commit/1debe1993fc852545a9215621d884be27f08a223
2023-04-06awk: dont leak memory on extra format argumentsJacob Moody
awk 'BEGIN { while(++i <= 100000) { mem = "ps | grep awk"; printf("%d", 1+2, 3+4, 5+6, 7+8, 9+0) > "/dev/null"; if(i % 10000 == 0) system(mem) }}' https://github.com/onetrueawk/awk/commit/821c502359855d0c43be8e9b08f037ecb543d310
2022-06-25awk: correct incoherent cell in assignment (thanks smj, mpinjr)Ori Bernstein
In run.c::assign(), assigning to $0 from $F, a field, where F >= 2, produces an incoherent cell. The assignment occurs in two steps, first the string value and then the float. When the string value is assigned to $0, setsval invalidates the fields. If FS hasn't changed, after getfval rebuilds the fields, NF = 1 and F >= 2, therefore $F is definitely uninitialized. The result is a float val of 0.0, producing a boolean false in the pattern expression. Coercing a string comparison gives the expected result because the incoherent cell has the correct string value, which is not empty and evaluates to true.
2022-06-25awk: initialize records fully in recinit()Ori Bernstein
when using records in BEGIN, we would read from the field table before we read into it; this ensures that the fields are an empty string before we start touching their contents.
2022-03-12awk: fix off-by-one string buffer overflow from gsubcinap_lenrek
the bug happens when we did the fast exit thru "done" label, where we would not make sure that theres space in the buffer for the NUL terminator. instead, avoid the fast exit and always do the final adjbuf() that makes sure we have space for the NUL terminator. remove the pointless pb checks, they'r wrong (should'v been bp >= buf+bufsz) and adjbuf() already makes sure this can never happen.
2020-11-19awk: fix truncated input after fflushAnthony Martin
Before the "native" awk work, a call to the fflush function resulted in one or more calls to the APE fflush(2). Calling fflush on a stream open for reading has different behavior based on the environment: within APE, it's a no-op¹; on OpenBSD, it's an error²; in musl, it depends on whether or not the underlying file descriptor is seekable³; etc. I'm sure glibc is subtly different. Now that awk uses libbio, things are different: calling Bflush(2) on a file open for reading simply discards any data in the buffer. This explains why we're seeing truncated input. When awk attempts to read in the next record, there's nothing in the buffer and no more data to read so it gets EOF and exits normally. Note that this behavior is not documented in bio(2). It was added in the second edition but I haven't figured out why or what depends on it. The simple fix is to have awk only call Bflush on files that were opened for writing. You could argue that this is the only correct behavior according to the awk(1) manual and it is, in fact, how GNU awk behaves⁴. 1. /sys/src/ape/lib/ap/stdio/fflush.c 2. https://cvsweb.openbsd.org/src/lib/libc/stdio/fflush.c?rev=1.9 3. https://git.musl-libc.org/cgit/musl/tree/src/stdio/fflush.c 4. https://git.savannah.gnu.org/cgit/gawk.git/tree/io.c#n1492
2020-05-24awk: fix race condition with sub-mk in mkfilecinap_lenrek
the maketab helper program was generated in parallel, which had a dependency to y.tab.h which lead to yacc running twice in parallel. this removes the dependency to y.tab.h in the virtual maketab.$objtype target to prevent this race condition. the dependency to y.tab.h is resolved in the main mk at the $cputype.maketab target which serializes with the other targets.
2020-03-10improve usage messages (thanks henesy)Ori Bernstein
Fix inconsistencies between programs and their usage messages, correct instances where information seems to be missing or lost. This includes missing arguments, making usage consistent with manuals, and so on.
2019-10-09awk: make empty FS unicodely-correct.Ori Bernstein
2019-05-24awk: no need to call getargv() twice to get the value for FILENAMEcinap_lenrek
2019-04-16awk: fix nextfile crash (thanks leetspete)cinap_lenrek
to reproduce the bug: term% awk 'BEGIN{nextfile; nextfile;}' sys: trap: fault read addr=0x10 pc=0x00019a3a awk 6584: suicide: sys: trap: fault read addr=0x10 pc=0x00019a3a
2018-10-31awk(1): fix append operator to avoid truncating fileAlex Musolino
2017-08-12awk: allow string as exit statuscinap_lenrek
2017-08-11awk: don't get into a infinite loop with eof while in string (thanks BurnZeZ)cinap_lenrek
2017-06-02awk: handle bad/incomplete input in maketab (thanks kenji arisawa)cinap_lenrek
2016-12-18awk: improve random number generationcinap_lenrek
don't use rand() and scale it to 0..1, instead call native frand() which produces uniform random number. instead of seeding the rng with time(0), use truerand().
2016-08-18fix awk format printing bugs (thanks aiju)spew
2016-05-27awk: restore old buffering behaviour for printfcinap_lenrek
2016-05-01just use wait in "system" call for awk, get rid of unix dependent status ↵spew
code divisor
2016-05-01null terminate await buffer for proper tokenize callspew
2016-05-01use rc in awk, remove awk from APEDIRS in cmd mkfileben
2016-05-02awk: dont require sed to build awkcinap_lenrek
2016-05-02awk: bring back ENVIRON[] supportcinap_lenrek
2016-04-30awk: temporarily fix for NaN() exceptions on 386cinap_lenrek
problem is NaN() produces a SNaN, not a QNaN... and on the 387, storing 80 bit SNaN in register to a 64-bit memory destination traps. SNaN/QNaN encoding is machine specific. mips has the qiet/signaling bit inverted. disabling fp exception in main() now, but that sucks. i think the best solution would be to not even call strtod() in is_number() but just write a regex or a little state machine that will only accept numbers without nan and ±inf. that might even make it faster and is more robust than relying on the os's strtod() details.
2016-04-29handle NaN in awk (thanks spew)aiju
2016-04-28awk: fix mkfile for cross-compiles (thanks, spew)stanley lieber
2016-04-28fix printing a char from an empty stringben
2016-04-28fix printing a char from a string that starts with a runeben
2016-04-28fix unsigned printing for awkben
2016-04-27use Beof for awk portben
2016-04-27remove ape regexp library, add utility for awk native portben
2016-04-26New libregexp and APE ported to nativeben
2013-05-09awk: proctab.c is always regenerated from maketab, so it is unnecessary to ↵ppatience0
keep it
2012-12-10awk: fix the fixcinap_lenrek
be more carefull. have to preserve DONTFREE flag!
2012-12-10awk: prevent split(a[x], a) from freeing a[x]cinap_lenrek
the freesymtab() call frees the y argument. temporarily mark it not to be freed.
2011-03-30Import sources from 2011-03-30 iso image - libTaru Karttunen
2011-03-30Import sources from 2011-03-30 iso imageTaru Karttunen