aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2018-12-09 19:02:32 -0600
committerRob Landley <rob@landley.net>2018-12-09 19:02:32 -0600
commit2eb2fdea88b848d07bb8aa7ca22cb624127e440d (patch)
tree6d3e83e192d49e1fc327640d327263833adc74f1 /toys
parentac89784055a6add93a3f45eeae70e9da2e4a8c98 (diff)
downloadtoybox-2eb2fdea88b848d07bb8aa7ca22cb624127e440d.tar.gz
Fix first grep.test failure (-B + -b not producing middle field).
When necessary, realloc() the line to add 4 aligned bytes of storage at the end, stick the unsigned offset in there, and then fish it back out for display (and add 1 because offset is 0 based and display is 1 based).
Diffstat (limited to 'toys')
-rw-r--r--toys/posix/grep.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/toys/posix/grep.c b/toys/posix/grep.c
index b2394c7b..49c69dd0 100644
--- a/toys/posix/grep.c
+++ b/toys/posix/grep.c
@@ -234,7 +234,8 @@ static void do_grep(int fd, char *name)
while (dlb) {
struct double_list *dl = dlist_pop(&dlb);
- outline(dl->data, '-', name, lcount-before, 0, -1);
+ outline(dl->data, '-', name, lcount-before,
+ *(unsigned *)(dl->data+((strlen(dl->data)+1)|3)+1)+1, -1);
free(dl->data);
free(dl);
before--;
@@ -260,6 +261,10 @@ static void do_grep(int fd, char *name)
discard = 0;
}
if (discard && TT.B) {
+ if (FLAG(b)) {
+ line = xrealloc(line, (ulen|3)+4);
+ *(unsigned *)(line+(ulen|3)+1) = offset-len;
+ }
dlist_add(&dlb, line);
line = 0;
if (++before>TT.B) {