-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Col refactor #1115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Col refactor #1115
Conversation
With these tests coverage is about 89%. The ts_run is added to ensure ASAN_OPTIONS and UBSAN_OPTIONS are set correctly when the tests run. Reference: util-linux#1115 (comment) Signed-off-by: Sami Kerola <kerolasa@iki.fi>
I should have taken a look what failed. The cf7825e should fix the LeakSanitizer in cost of being free() before exit fix that is usually considered quite pointless activity. |
I think by analogy with #1077 (comment) another option would be to pass |
Speaking of Coverity @kerolasa I'm not sure if you have access to it. I've just invited you to the "util-linux" organization there. I hope it's all right. |
FWIW to judge from https://travis-ci.org/github/karelzak/util-linux/jobs/716144038 it seems on macOS
|
Thank you. Looks like there are plenty of small fixes that could be done. Perhaps I should cease the opportunity and make this release cycle to be mostly about covery fixes. I will try to look into latest failures. Maybe the easiest is to compile the col(1) on my laptop with leaksanitizer enabled and make the feedback loop a lot shorter. |
@kerolasa apart from Coverity |
@evverx I have no idea what to expect with OSS-Fuzz but I am sure the reports themselves will educate me how to use them. My addresses are kerolasa(at)iki.fi and kerolasa(at)gmail.com. Thank you Evgeny, really nice to see another active contributor working to get util-linux better. |
With these tests coverage is about 89%. The ts_run is added to ensure ASAN_OPTIONS and UBSAN_OPTIONS are set correctly when the tests run. Reference: util-linux#1115 (comment) Signed-off-by: Sami Kerola <kerolasa@iki.fi>
OSS-Fuzz has found two issues so far: https://bugs.chromium.org/p/oss-fuzz/issues/list?q=label%3AProj-util-linux&can=1. https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=23861&q=label%3AProj-util-linux&can=1 seems to be a bug in the fuzz target though. Looks like I forgot to limit the number of bytes it's supposed to handle. I'll fix it next week.
I've just opened google/oss-fuzz#4287. |
With these tests coverage is about 89%. The ts_run is added to ensure ASAN_OPTIONS and UBSAN_OPTIONS are set correctly when the tests run. Reference: util-linux#1115 (comment) Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Hopefully last fix. The col io test "exit sane" is now discarding error message about invalid multibyte because linux and macos does not share the same error message string. |
Really weird, why MacOS is adding newline? https://travis-ci.org/github/karelzak/util-linux/jobs/716341634#L3804 |
With these tests coverage is about 89%. The ts_run is added to ensure ASAN_OPTIONS and UBSAN_OPTIONS are set correctly when the tests run. Reference: util-linux#1115 (comment) Signed-off-by: Sami Kerola <kerolasa@iki.fi>
The part of test that upset macos is removed. |
With these tests coverage is about 89%. The ts_run is added to ensure ASAN_OPTIONS and UBSAN_OPTIONS are set correctly when the tests run. Reference: util-linux#1115 (comment) Signed-off-by: Sami Kerola <kerolasa@iki.fi>
text-utils/col.c
Outdated
{ | ||
errx(EXIT_FAILURE, _("write error")); | ||
if (putwchar(ch) == WEOF) | ||
errx(EXIT_FAILURE, _("write error")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be better to use _("write failed") as we have in other tools? Would be possible to use err() to get details about the error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Text is fixed in 3375fd9, and I checked the err() is used not the errx().
text-utils/col.c
Outdated
} | ||
nb /= 2; | ||
for (i = nb; --i >= 0;) | ||
ctl->nblank_lines /= 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it correct? It seems you modify global ctl->nblank_lines, but the original code uses a local variable and it does not refresh the original global setting -- nblank_lines is unmodified by this function in original code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I removed the commit that had ill thought variable removal.
text-utils/col.c
Outdated
@@ -104,19 +104,20 @@ struct line_str { | |||
CHAR *l_line; /* characters on the line */ | |||
LINE *l_prev; /* previous line */ | |||
LINE *l_next; /* next line */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice by a separate patch to remove all the typedefs and LINE and CHAR, and use struct col_line
and struct col_char
. The typedef makes sense for simple opaque types (like some numbers etc.), otherwise typedef is evil.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, typedefs are removed in 2446db1.
text-utils/col.c
Outdated
@@ -173,7 +176,7 @@ static void __attribute__((__noreturn__)) usage(void) | |||
static inline void col_putchar(wchar_t ch) | |||
{ | |||
if (putwchar(ch) == WEOF) | |||
errx(EXIT_FAILURE, _("write error")); | |||
err(EXIT_FAILURE, _("write error")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yes, err() -- thanks.
@@ -651,5 +682,6 @@ int main(int argc, char **argv) | |||
/* missing a \n on the last line? */ | |||
ctl.nblank_lines = 2; | |||
flush_blanks(&ctl); | |||
free_line_allocations(ctl.alloc_root); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can use some #ifdef to call free_line_allocations() only to make LeakSanitizer happy :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets see if 3252914 works as expected. I added #if defined(__SANITIZE_ADDRESS__)
around code that is performing these pointless at exit free's.
With these tests coverage is about 89%. The ts_run is added to ensure ASAN_OPTIONS and UBSAN_OPTIONS are set correctly when the tests run. Reference: util-linux#1115 (comment) Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Mark --tabs and --spaces mutually exclusive in same go. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Left side is always smaller or equal to right side. This makes reading code quicker when not having to constantly swap where is the greater value. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Karel Zak said; typedef is evil, see reference. I don't know are they evil, but it is fair comment structs without hiding what is the data type is easier and quicker understand when reading the code. Reference: util-linux#1115 (comment) Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2bc5a16
to
2446db1
Compare
Clean up before exit to satisfy LeakSanitizer tests run by travis. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Karel Zak said; typedef is evil, see reference. I don't know are they evil, but it is fair comment structs without hiding what is the data type is easier and quicker understand when reading the code. Reference: util-linux#1115 (comment) Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2446db1
to
81c9867
Compare
Thanks! I did tiny changes to the code too. |
The macro FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION does not have to enabled in all cases (e.g. default travis-ci, local tests, ...). It seems more robust also check for __SANITIZE_ADDRESS__ too. Addresses: #1115 Signed-off-by: Karel Zak <kzak@redhat.com>
Welcome back from vacation @karelzak
While back when d8bfcb4 was in review phase I mentioned col(1) is in need for whole bunch of attention. This pull request contains the things that I thought make sense when bringing the command from past to present. The patches start with tests that work when they are added, and do not need changes at any step on the way. I hope that gives more confidence these changes are probably ok.