Commit Graph

60 Commits

Author SHA1 Message Date
Frantisek Sumsal c40b3cd03d text-utils: correctly detect ASan under clang
__SANITIZE_ADDRESS__ is not defined when compiling with clang, so cover
both use cases with a special set of macros
2021-02-01 11:59:47 +01:00
Sami Kerola 14a36f96ee
col: make input to tolerate invalid wide characters
The getwchar(3) will choke and exit if invalid character is encountered.
This change will make col(1) to print broken multibyte characters as
\x{hex} string.

Reported-by: Vitaly Lipatov <lav@etersoft.ru>
Addresses: https://github.com/karelzak/util-linux/issues/1198
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-12-02 22:12:32 +00:00
Sami Kerola afbf8fe223 col: fix --help short option in usage() output
The col(1) is using unusual -H as --help short option.  The -h is used for
--tabs (horizontal tab?) in this implementation.

Fixes: 62dee0176a
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-10-16 11:13:04 +02:00
Karel Zak 598ea3fd30 col: enable deallocation on exit also for __SANITIZE_ADDRESS__
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: https://github.com/karelzak/util-linux/pull/1115
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-09-30 13:48:54 +02:00
Karel Zak 62dee0176a col: cleanup usage() and struct col_*
- remove extra line about stdout in usage() output

- use our macros to print int about --help and --version

- remove uint8_t bit-field from struct col_ctl (it seems fragile for
  future code changes).

Signed-off-by: Karel Zak <kzak@redhat.com>
2020-09-29 14:20:57 +02:00
Sami Kerola 81c9867d18
col: replace LINE and CHAR typedefs with structs
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: https://github.com/karelzak/util-linux/pull/1115#discussion_r481971317
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-09-12 23:20:18 +01:00
Sami Kerola 86c6d3ff68
col: free memory before exit [LeakSanitizer]
Clean up before exit to satisfy LeakSanitizer tests run by travis.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-09-12 23:19:16 +01:00
Sami Kerola 3375fd9ccf
col: tidy up sources a little bit
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-09-12 18:32:55 +01:00
Sami Kerola 12234f462a
col: add defaults to switch case clauses
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-09-12 18:32:55 +01:00
Sami Kerola e15ed08756
col: flip all comparisions to numerical order
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>
2020-09-12 18:32:54 +01:00
Sami Kerola 8f36d39294
col: use size_t when dealing with numbers that buffer sizes
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-09-12 18:31:05 +01:00
Sami Kerola 0148d75bcd
col: add structure to hold line variables
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-09-12 18:27:13 +01:00
Sami Kerola 812e849eac
col: add update_cur_line() function
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-09-12 18:27:13 +01:00
Sami Kerola 6591d3bd6b
col: add handle_not_graphic() function
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-09-12 18:27:13 +01:00
Sami Kerola d38392a1e8
col: initialize variables when they are declared
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-09-11 20:55:02 +01:00
Sami Kerola 9f60a69217
col: move option handling to separate function
Mark --tabs and --spaces mutually exclusive in same go.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-09-11 20:55:02 +01:00
Sami Kerola 31a61cbedc
col: move global variables to a control structure
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-09-11 20:55:02 +01:00
Sami Kerola fd8270b4f2
col: use inline function rather than function like define
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-09-11 20:55:02 +01:00
Sami Kerola 6c5a421e09
col: use typedef and enum to clarify struct
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-09-11 20:55:02 +01:00
Sami Kerola f5ab4ee375
col: remove function prototypes
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-09-11 20:55:02 +01:00
Sami Kerola d8bfcb4cc5
col: fix output when first line does not have newline character
Commit I made while back and has been part of util-linux v2.30 to v2.35 made
col(1) not to output anything when first line did not have newline character.

    printf "gone from output" | col

This commit fixes the issue.  Admittedly the col source code is unnecessarily
hard to work with.  It could be a good idea to refactor the col(1) as low
priority task, Assuming refactoring is done the first commit to get that done
should add tests that exhaust all possible input handling including all command
line option directives.

Addresses: https://github.com/karelzak/util-linux/issues/422
Fixes: b6b5272b03
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2020-06-20 22:17:30 +01:00
Karel Zak 2c308875a7 misc: consolidate version printing and close_stdout()
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-04-16 15:14:13 +02:00
Karel Zak cc06250f11 col: improve error message, update regression test
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-02-05 18:07:26 +01:00
Karel Zak 004356f050 col: make flush_line() a little bit robust
The code is horrible. The core of the problem are signed integers
and no check for the limits.

This patch fixes c->c_column = cur_col; where c_column is "short"
and "cur_col" is int. Let's use "int" for all the variables. It's
really not perfect as for bigger lines it can segfault again...

The patch also removes some unnecessary static variables.

Addresses: https://github.com/karelzak/util-linux/issues/749
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-02-05 12:06:00 +01:00
Ruediger Meier f45f3ec34a misc: consolidate macro style USAGE_HELP_OPTIONS
changed in include/c.h and applied via sed:

  sed -i 's/fprintf.*\(USAGE_MAN_TAIL.*\)/printf(\1/' $(git ls-files -- "*.c")
  sed -i 's/print_usage_help_options\(.*\);/printf(USAGE_HELP_OPTIONS\1);/' $(git ls-files -- "*.c")

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-29 16:54:33 +02:00
Ruediger Meier b305445495 misc: consolidate all --help option descriptions
Now we are always using the same text also for commands
which had still hardcoded descriptions or where we can't
use the standard print_usage_help_options macro.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-27 12:28:36 +02:00
Ruediger Meier 6e1eda6f22 misc: never use usage(stderr)
Here we fix all cases where we have usage(FILE*)
functions.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2017-06-26 14:38:24 +02:00
Sami Kerola b6b5272b03 col: avoid extra newline if no input
BSD fix missed for 22 years, and all util-linux releases so far.

Backported-from: 2a15260a2a
Addresses: https://github.com/karelzak/util-linux/issues/422
Reported-by: Pavel Raiskup <praiskup@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-05-10 10:53:28 +02:00
Sami Kerola 2ba641e5f3 misc: add static keyword to where needed [smatch scan]
text-utils/rev.c:68:9: warning: symbol 'buf' was not declared. Should it be
static?

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-20 12:58:49 +01:00
Sami Kerola 8791804065 misc: do not use plain 0 as NULL [smatch scan]
text-utils/tailf.c:69:21: warning: Using plain integer as NULL pointer

Since many 'struct option' has used zero as NULL make them more readable in
same go by reindenting, and using named argument requirements.

Reference: https://lwn.net/Articles/93577/
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-02-20 12:58:49 +01:00
Grady Martin 26c91027b2
col: backspacing widechars
Until now, backspace characters have not accounted for characters of widths
other than one.  This single line amends that.

Requsted-by: Grady Martin <admin@nosuck.org>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2017-01-04 22:01:40 +00:00
Karel Zak 677ec86cef Use --help suggestion on invalid option
The current default is to print all usage() output. This is overkill
in many case.

Addresses: https://github.com/karelzak/util-linux/issues/338
Signed-off-by: Karel Zak <kzak@redhat.com>
2016-12-19 13:13:34 +01:00
Ruediger Meier fea1cbf748 misc: never cast void* from malloc(3) and friends
Such cast could hide serious compiler warnings in case we are
missing includes (e.g. <stdlib.h> or "xalloc.h").

See
http://stackoverflow.com/questions/605845/do-i-cast-the-result-of-malloc

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2016-03-07 23:29:27 +01:00
Benno Schulenberg 451dbcfae1 textual: add a docstring to most of the utilities
This adds a concise description of a tool to its usage text.

A first form of this patch was proposed by Steven Honeyman
(see http://www.spinics.net/lists/util-linux-ng/msg09994.html).

Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2015-01-06 11:27:38 +01:00
Sami Kerola a587cc5520 textual: use manual tail usage() macro
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-10-01 12:33:24 +02:00
Sami Kerola f627750083 textual: use version printing macro everywhere
Only mount, umount, and blkid remains not using the macro because they
are print also library references.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-10-01 12:33:23 +02:00
Sami Kerola 7d2600e2d0 docs: update deprecation banners
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2014-10-01 12:33:11 +02:00
Sami Kerola 9e01635e32 libmount, col: remove redundant null checks [smatch scan]
libmount/src/context_umount.c:174 mnt_context_find_umount_fs() info: redundant null check on loopdev calling free()
libmount/src/context_umount.c:179 mnt_context_find_umount_fs() info: redundant null check on loopdev calling free()
text-utils/col.c:406 flush_lines() info: redundant null check on l->l_line calling free()

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-04-09 12:26:42 +02:00
Sami Kerola 3acc206d39 various: fix variable and function declarations [smatch scan]
disk-utils/fsck.minix.c:511:9: warning: mixing declarations and code
fdisks/sfdisk.c:982:5: warning: mixing declarations and code
fdisks/sfdisk.c:1254:5: warning: mixing declarations and code
fdisks/sfdisk.c:1564:5: warning: mixing declarations and code
lib/mbsalign.c:279:7: warning: mixing declarations and code
libblkid/src/devname.c:378:17: warning: mixing declarations and code
libfdisk/src/alignment.c:219:9: warning: mixing declarations and code
term-utils/wall.c:111:9: warning: mixing declarations and code
text-utils/col.c:418:19: warning: non-ANSI function declaration of function 'flush_blanks'
text-utils/col.c:553:12: warning: non-ANSI function declaration of function 'alloc_line'
text-utils/rev.c:105:9: warning: mixing declarations and code
text-utils/tailf.c:245:9: warning: mixing declarations and code

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2013-04-09 12:17:20 +02:00
Benno Schulenberg b50945d4ac textual: spell and encode the name of Arkadiusz Miśkiewicz correctly
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-02-06 11:15:02 +01:00
Benno Schulenberg 48899b9eae textual: remove inconsistent periods from two error messages
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
2013-01-25 11:47:27 +01:00
Karel Zak 0825179f47 col: fix compiler warning [-Wstrict-prototypes]
text-utils/col.c:142:43: warning: function declaration isn’t a prototype [-Wstrict-prototypes]

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-09-04 16:49:28 +02:00
Karel Zak 3b56eea7c9 text-utils: cleanup strtoxx_or_err()
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-05-15 17:46:20 +02:00
Sami Kerola b87cbe8486 text-utils: verify writing to streams was successful
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-04-04 19:45:41 +02:00
Sami Kerola b07e72d9ec col: check with strtol_or_err option argument
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-06-08 11:12:53 +02:00
Sami Kerola 8e0ec3b48a col: coding style changes
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-06-01 09:08:01 +02:00
Sami Kerola f688c29873 col: use long options
This commit introduces help & version options.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-06-01 09:07:56 +02:00
Karel Zak bcf006d71f don't declare usage() without parametr
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-01-21 01:00:18 +01:00
Karel Zak 2ebef8704d col: use err.h and EXIT_* macros
Signed-off-by: Karel Zak <kzak@redhat.com>
2010-11-01 14:51:08 +01:00
Davidlohr Bueso 04faca4a13 col: use xalloc for memory allocation
Differentiate between malloc and realloc (not done so far) and get rid of local warn()

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2010-11-01 14:32:48 +01:00