For example
./test_strutils --size '1.0000000000000000000000000000018000000000000000010M'
./test_strutils --size '1.18446744073709551615M'
ends with infinite loop due to frac_div variable overflow.
Addresses: https://github.com/karelzak/util-linux/issues/1023
Signed-off-by: Karel Zak <kzak@redhat.com>
Old code:
./test_strutils --size 0.5MiB
0.5MiB : 512000 : 500K : 500 KiB
./test_strutils --size 0.50MiB
0.50MiB : 5120000 : 4.9M : 4.9 MiB
New code:
./test_strutils --size 0.5MiB
0.5MiB : 524288 : 512K : 512 KiB
./test_strutils --size 0.50MiB
0.50MiB : 524288 : 512K : 512 KiB
Note that the new implementation also does not use float points,
because we need to support PiB and so on... it seems good enough for
things like:
./test_strutils --size 7.13G
7.13G : 7656104581 : 7.1G : 7.1 GiB
./test_strutils --size 7.16G
7.16G : 7690675814 : 7.2G : 7.2 GiB
to avoid situation where cfdisk creates partition with completely
crazy numbers.
Addresses: https://github.com/karelzak/util-linux/issues/782
Signed-off-by: Karel Zak <kzak@redhat.com>
* don't cast from char to const char
* don't share endptr from strtoxxx() with rest of the code
as the end pointer is char, but code works with const chars
Signed-off-by: Karel Zak <kzak@redhat.com>
[util-linux-2.32.1/lib/strutils.c:122]: (style) Redundant condition: If 'EXPR == '0'', the comparison 'EXPR' is always true.
Reported-by: David Binderman <dcb314@hotmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
As discussed on the mailing list. We fix all places
where the non-working define STRTOXX_EXIT_CODE was used.
Regarding tunelp, also see 7e3c80a7.
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Add helper functions which allow to parse hexadecimal numbers.
Based on a patch from Clemens von Mann.
Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
///aaa/bbb and /aaa/bbb/ are the same paths. This is important
especially with NFS where number of slashes are not the same in
the /proc/self/mountinfo and fstab or utab. The regular URI is
euler://tmp
but /proc contains
euler:/tmp
Reported-by: Ales Novak <alnovak@suse.cz>
Signed-off-by: Karel Zak <kzak@redhat.com>
Fix various typos in error messages, warnings, debug strings,
comments and names of static functions.
Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
Currently the code supports /dev/name or PARTUUID= only. We also
need to support 'maj:min' and 'hexhex' notations.
Reported-by: George Spelvin <linux@horizon.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
Maybe strtosize_or_err() is the only function which uses
this errno (wrongly). But it doesnt hurt to maintain rc
as well as errno.
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Don't use undefined errno:
$ ./logger --no-act -t "wtf" --id="" message
logger: failed to parse id: '': No such file or directory
Don't print useless EINVAL message but ERANGE only:
$ ./logger --no-act -t "wtf" --id="XX" message
logger: failed to parse id: 'XX': Invalid argument
Note the ERANGE-only improvement does not change anything on
Linux/c99 as strtoul(3) only set ERANGE there.
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Fix the warnings below for OSX clang and add a few more
casts for timeval:
lib/at.c:131:27: warning: format specifies type 'intmax_t' (aka 'long') but the argument has type 'off_t' (aka 'long long') [-Wformat]
printf("%16jd bytes ", st.st_size);
~~~~~ ^~~~~~~~~~
lib/strutils.c:522:52: warning: format specifies type 'intmax_t' (aka 'long') but the argument has type 'uint64_t' (aka 'unsigned long long') [-Wformat]
snprintf(buf, sizeof(buf), "%d%s%jd%s", dec, dp, frac, suffix);
~~~ ^~~~
lib/sysfs.c:468:42: warning: format specifies type 'uintmax_t' (aka 'unsigned long') but the argument has type 'uint64_t' (aka 'unsigned long long') [-Wformat]
len = snprintf(buf, sizeof(buf), "%ju", num);
~~~ ^~~
libuuid/src/gen_uuid.c:316:34: warning: format specifies type 'unsigned long' but the argument has type '__darwin_suseconds_t' (aka 'int') [-Wformat]
clock_seq, last.tv_sec, last.tv_usec, adjustment);
^~~~~~~~~~~~
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
Make skipping two lines more robust, and add message about unexpected
adjfile contents when running with --verbose.
Reviewed-by: Karel Zak <kzak@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
The function uses "int" as argument, but for array size (and index) is better
to use unsigned type (size_t). If we mix "size_t" in util (e.g. fdisk)
and "int" in lib/strutils.c then result is unexpected behavior on
ppc64.
# sfdisk --list -o DEVICE,START,SIZE /dev/sdb
Disk /dev/sdb: 50 MiB, 52428800 bytes, 102400 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 32768 bytes
Disklabel type: gpt
Disk identifier: 3B8559DB-33AF-43E9-BEFC-C331D829B539
lt-sfdisk: libfdisk/src/label.c:178: fdisk_label_get_field: Assertion `id > 0' failed.
The patch cleanup all code to use size_t everywhere.
Signed-off-by: Karel Zak <kzak@redhat.com>
Just line 'M' and 'm' are accepted for mega, 'G' and 'g' for giga,
'S' and 's' for sectors, and so on.
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>