Commit Graph

12 Commits

Author SHA1 Message Date
Lennart Poettering 6dd91b3682 tree-wide: CMP()ify all the things
Let's employ coccinelle to fix everything up automatically for us.
2018-10-16 17:45:53 +02:00
Lennart Poettering ee7b9f1dfc format-table: don't use unsigned when there's no point in it
CID 1394372
2018-10-13 12:37:13 +02:00
Yu Watanabe ba0a7bfb98 tree-wide: use typesafe_qsort_r() 2018-09-19 08:05:13 +09:00
Yu Watanabe 8301aa0bf1 tree-wide: use DEFINE_TRIVIAL_REF_UNREF_FUNC() macro or friends where applicable 2018-08-27 14:01:46 +09:00
Yu Watanabe 475d8599b0 format-table: fix typo in comment 2018-07-15 17:07:38 +09:00
NOGISAKA Sadata a26db0bc5d format-table: make all widths be set properly
Fixes #9549.
2018-07-12 13:51:58 +09:00
Zbigniew Jędrzejewski-Szmek 5d904a6aaa tree-wide: drop !! casts to booleans
They are not needed, because anything that is non-zero is converted
to true.

C11:
> 6.3.1.2: When any scalar value is converted to _Bool, the result is 0 if the
> value compares equal to 0; otherwise, the result is 1.

https://stackoverflow.com/questions/31551888/casting-int-to-bool-in-c-c
2018-06-13 10:52:40 +02:00
Zbigniew Jędrzejewski-Szmek cfc01c1e02 basic/format-table: remove parameter with constant value 2018-06-11 10:04:10 +02:00
Zbigniew Jędrzejewski-Szmek 21e4e3e06f basic/ellipsize: do not assume the string is NUL-terminated when length is given
oss-fuzz flags this as:

==1==WARNING: MemorySanitizer: use-of-uninitialized-value

0. 0x7fce77519ca5 in ascii_is_valid systemd/src/basic/utf8.c:252:9
1. 0x7fce774d203c in ellipsize_mem systemd/src/basic/string-util.c:544:13
2. 0x7fce7730a299 in print_multiline systemd/src/shared/logs-show.c:244:37
3. 0x7fce772ffdf3 in output_short systemd/src/shared/logs-show.c:495:25
4. 0x7fce772f5a27 in show_journal_entry systemd/src/shared/logs-show.c:1077:15
5. 0x7fce772f66ad in show_journal systemd/src/shared/logs-show.c:1164:29
6. 0x4a2fa0 in LLVMFuzzerTestOneInput systemd/src/fuzz/fuzz-journal-remote.c:64:21
...

I didn't reproduce the issue, but this looks like an obvious error: the length
is specified, so we shouldn't use the string with any functions for normal
C-strings.
2018-06-11 10:04:10 +02:00
Zbigniew Jędrzejewski-Szmek f20f4a775e basic/format-table: add missing va_end()
CID #1390930, #1390940.
2018-05-10 01:36:50 +02:00
Lennart Poettering 5d13a15b1d tree-wide: drop spurious newlines (#8764)
Double newlines (i.e. one empty lines) are great to structure code. But
let's avoid triple newlines (i.e. two empty lines), quadruple newlines,
quintuple newlines, …, that's just spurious whitespace.

It's an easy way to drop 121 lines of code, and keeps the coding style
of our sources a bit tigther.
2018-04-19 12:13:23 +02:00
Lennart Poettering 1960e73611 basic: add minimalistic table formatter
We have plenty of code in our codebase that outputs tables to the
console, and all is homegrown and awful. Let's replace it with a generic
implementation that can do automatically what the old implementations
did manually.

Features:

1. Ellipsation (for fields overly long) and alignment (for
   fields overly short)

2. Sorting of rows

3. automatically copies formatting from the same cell in the row above

4. Heavy use of varargs to make putting together tables easy

5. can expand and compress tables, with weights

6. Has a minimal understanding of unicode wide characters in order to
   match unicode strings to character cell terminals.

7. Columns can be reordered and individually turned off.

8. pretty printing for various data types

And more.
2018-04-18 12:51:15 +02:00