FreeBSD Bugzilla – Attachment 147858 Details for
Bug 186861
[PATCH] bsdgrep(1): xzgrep(1) sometimes doesn't find matches it should find
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
improved patch
patch-xzgrep-v2 (text/plain), 2.68 KB, created by
Stefan Ehmann
on 2014-09-30 19:49:37 UTC
(
hide
)
Description:
improved patch
Filename:
MIME Type:
Creator:
Stefan Ehmann
Created:
2014-09-30 19:49:37 UTC
Size:
2.68 KB
patch
obsolete
>Index: usr.bin/grep/file.c >=================================================================== >--- usr.bin/grep/file.c (revision 271683) >+++ usr.bin/grep/file.c (working copy) >@@ -65,6 +65,8 @@ > static gzFile gzbufdesc; > #ifndef WITHOUT_LZMA > static lzma_stream lstrm = LZMA_STREAM_INIT; >+static lzma_action laction; >+static uint8_t *lin_buf; > #endif > #ifndef WITHOUT_BZIP2 > static BZFILE* bzbufdesc; >@@ -123,34 +125,34 @@ > #endif > #ifndef WITHOUT_LZMA > } else if ((filebehave == FILE_XZ) || (filebehave == FILE_LZMA)) { >- lzma_action action = LZMA_RUN; >- uint8_t in_buf[MAXBUFSIZ]; > lzma_ret ret; >+ lstrm.next_out = buffer; > >- ret = (filebehave == FILE_XZ) ? >- lzma_stream_decoder(&lstrm, UINT64_MAX, >- LZMA_CONCATENATED) : >- lzma_alone_decoder(&lstrm, UINT64_MAX); >+ do { >+ if (lstrm.avail_in == 0) { >+ lstrm.next_in = lin_buf; >+ nr = read(f->fd, lin_buf, MAXBUFSIZ); > >- if (ret != LZMA_OK) >- return (-1); >+ if (nr < 0) >+ return (-1); >+ else if (nr == 0) >+ laction = LZMA_FINISH; > >- lstrm.next_out = buffer; >- lstrm.avail_out = MAXBUFSIZ; >- lstrm.next_in = in_buf; >- nr = read(f->fd, in_buf, MAXBUFSIZ); >+ lstrm.avail_in = nr; >+ } > >- if (nr < 0) >- return (-1); >- else if (nr == 0) >- action = LZMA_FINISH; >+ ret = lzma_code(&lstrm, laction); > >- lstrm.avail_in = nr; >- ret = lzma_code(&lstrm, action); >+ if (ret != LZMA_OK && ret != LZMA_STREAM_END) >+ return (-1); > >- if (ret != LZMA_OK && ret != LZMA_STREAM_END) >- return (-1); >- bufrem = MAXBUFSIZ - lstrm.avail_out; >+ if (lstrm.avail_out == 0 || ret == LZMA_STREAM_END) { >+ bufrem = MAXBUFSIZ - lstrm.avail_out; >+ lstrm.next_out = buffer; >+ lstrm.avail_out = MAXBUFSIZ; >+ } >+ } while (bufrem == 0 && ret != LZMA_STREAM_END); >+ > return (0); > #endif /* WIHTOUT_LZMA */ > } else >@@ -291,7 +293,26 @@ > (bzbufdesc = BZ2_bzdopen(f->fd, "r")) == NULL) > goto error2; > #endif >+#ifndef WITHOUT_LZMA >+ else if ((filebehave == FILE_XZ) || (filebehave == FILE_LZMA)) { >+ lzma_ret ret; > >+ lin_buf = grep_malloc(MAXBUFSIZ); >+ >+ ret = (filebehave == FILE_XZ) ? >+ lzma_stream_decoder(&lstrm, UINT64_MAX, >+ LZMA_CONCATENATED) : >+ lzma_alone_decoder(&lstrm, UINT64_MAX); >+ >+ if (ret != LZMA_OK) >+ goto error2; >+ >+ lstrm.avail_in = 0; >+ lstrm.avail_out = MAXBUFSIZ; >+ laction = LZMA_RUN; >+ } >+#endif >+ > /* Fill read buffer, also catches errors early */ > if (bufrem == 0 && grep_refill(f) != 0) > goto error2; >@@ -322,7 +343,12 @@ > if (filebehave == FILE_MMAP) { > munmap(buffer, fsiz); > buffer = NULL; >+#ifndef WITHOUT_LZMA >+ } else if ((filebehave == FILE_XZ) || (filebehave == FILE_LZMA)) { >+ free(lin_buf); >+ lin_buf = NULL; > } >+#endif > bufpos = buffer; > bufrem = 0; >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 186861
:
147810
| 147858