diff options
author | Patrick Uiterwijk <patrick@puiterwijk.org> | 2018-02-22 19:41:30 +0100 |
---|---|---|
committer | Adrian Szyndela <adrian.s@samsung.com> | 2020-02-26 11:39:00 +0100 |
commit | 92a796aaa622a5c7ca7d2360a3a0b3dce2c4cf4d (patch) | |
tree | feecb0c276db08fdc6b77915705d40dae44320c1 /src/test | |
parent | de15a1bdad48788116c0e2588b67b4d4ac8bd3ab (diff) | |
download | systemd-92a796aaa622a5c7ca7d2360a3a0b3dce2c4cf4d.tar.gz systemd-92a796aaa622a5c7ca7d2360a3a0b3dce2c4cf4d.tar.bz2 systemd-92a796aaa622a5c7ca7d2360a3a0b3dce2c4cf4d.zip |
(backport) Fix format-truncation compile failure by typecasting USB IDs (#8250)
This patch adds safe_atoux16 for parsing an unsigned hexadecimal 16bit int, and
uses that for parsing USB device and vendor IDs.
This fixes a compile error with gcc-8 because while we know that USB IDs are 2 bytes,
the compiler does not know that.
../src/udev/udev-builtin-hwdb.c:80:38: error: '%04X' directive output may be
truncated writing between 4 and 8 bytes into a region of size between 2 and 6
[-Werror=format-truncation=]
Change-Id: I40b2eb8b424c57ba430b217ebead2fc5d67bbb14
Signed-off-by: Adam Williamson <awilliam@redhat.com>
Signed-off-by: Patrick Uiterwijk <puiterwijk@redhat.com>
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/test-parse-util.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/test/test-parse-util.c b/src/test/test-parse-util.c index 1b29b2ea87..4e5cbd2098 100644 --- a/src/test/test-parse-util.c +++ b/src/test/test-parse-util.c @@ -433,6 +433,44 @@ static void test_safe_atoi16(void) { assert_se(r == -EINVAL); } +static void test_safe_atoux16(void) { + int r; + uint16_t l; + + r = safe_atoux16("1234", &l); + assert_se(r == 0); + assert_se(l == 0x1234); + + r = safe_atoux16("abcd", &l); + assert_se(r == 0); + assert_se(l == 0xabcd); + + r = safe_atoux16(" 1234", &l); + assert_se(r == 0); + assert_se(l == 0x1234); + + r = safe_atoux16("12345", &l); + assert_se(r == -ERANGE); + + r = safe_atoux16("-1", &l); + assert_se(r == -ERANGE); + + r = safe_atoux16(" -1", &l); + assert_se(r == -ERANGE); + + r = safe_atoux16("junk", &l); + assert_se(r == -EINVAL); + + r = safe_atoux16("123x", &l); + assert_se(r == -EINVAL); + + r = safe_atoux16("12.3", &l); + assert_se(r == -EINVAL); + + r = safe_atoux16("", &l); + assert_se(r == -EINVAL); +} + static void test_safe_atou64(void) { int r; uint64_t l; @@ -618,6 +656,7 @@ int main(int argc, char *argv[]) { test_safe_atolli(); test_safe_atou16(); test_safe_atoi16(); + test_safe_atoux16(); test_safe_atou64(); test_safe_atoi64(); test_safe_atod(); |