* fix double free
* keep strrealloc() semantic compatible with classic realloc() (do not
free original pointer on failed memory allocation).
* remove unnecessary goto
Signed-off-by: Karel Zak <kzak@redhat.com>
* improve strdup_to_offset() readability
* add strdup_between_offsets() and strdup_between_structs() to have
better support for use-cases when we copy structs
Signed-off-by: Karel Zak <kzak@redhat.com>
Recent lscpu fix caused gcc -Wnull-dereference to go off that this change
addresses.
Reference: b94acada9e
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
From the test input string ':' characters are removed:
cat x86_64-epyc_7451/sys/devices/system/cpu/vulnerabilities/spectre_v2
Mitigation: Full AMD retpoline, IBPB: conditional, STIBP: disabled, RSB filling
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
str2memcpy() - copy zero terminated string to optionally terminated buffer
mem2strcpy() - copy from buffer to zero terminated string
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>
For petty long time we have strdup_to_struct_member() macro to avoid
duplicate code when strdup() strings in setter functions. Let's use it
for libmount.
Signed-off-by: Karel Zak <kzak@redhat.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>
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>
[kzak@redhat.com: - add also skip_blank(),
- remove duplicate implementation from libmount]
Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
Avoid code dublication in libmount and time-util.
Proposed-by: Karel Zak <kzak@redhat.com>
Reference: http://markmail.org/message/h7zexvqsieqngtmx
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
We need [un]signed int ([u]int32_t) on many places. It's also more
readable and robust to use uintXX_t types than for example "long long".
Signed-off-by: Karel Zak <kzak@redhat.com>
* add strtosize_or_err(), we use strtosize() + err() on many places
* add STRTOXX_EXIT_CODE to overwrite the default EXIT_FAILURE
* remove else-after-noreturn (e.g. if (foo) err(...); else err(...))
* clean up indent...
Signed-off-by: Karel Zak <kzak@redhat.com>
This function currently sets the low or high values to 0 when the string doesn't
contain a value, like '123:' or ':123'. In order to make it more flexible, we allow it
to be passed an arbitrary value.
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
This function is currently only being used by partx(8), but it's handy and
generic enough that we can use it elsewhere as well.
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
string with a different format based on the following flags:
SIZE_SUFFIX_1LETTER = "1K"
SIZE_SUFFIX_3LETTER = "1KiB",
SIZE_SUFFIX_SPACE = "1 KiB" or "1 K"
[kzak@redhat.com: - rename flags to SIZE_SUFFIX_* format,
- fix suffix[] buffer size
- add 3 letter version to the test]
Signed-off-by: Francesco Cosoleto <cosoleto@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>