Merged
Conversation
This reverts some changes introduced in d054f0a. xsprintf should be used in cases where we calculated the right buffer size by hand (using DECIMAL_STRING_MAX and such), and never in cases where we are printing externally specified strings of arbitrary length. Fixes systemd#4534.
If we encounter the (unlikely) situation where the combined path to the new root and a path to a mount to be moved together exceed maximum path length, we shouldn't crash, but fail this path instead.
evverx
reviewed
Nov 3, 2016
| else { | ||
| xsprintf(m->sender_buffer, ":1.%llu", | ||
| (unsigned long long)k->src_id); | ||
| xsprintf(m->sender_buffer, ":1.%"PRIu64, k->src_id); |
Contributor
There was a problem hiding this comment.
This produces:
src/libsystemd/sd-bus/bus-kernel.c: In function ‘bus_kernel_make_message’:
src/libsystemd/sd-bus/bus-kernel.c:851:44: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 4 has type ‘__u64 {aka long long unsigned int}’ [-Wformat=]
xsprintf(m->sender_buffer, ":1.%"PRIu64, k->src_id);
^
./src/basic/macro.h:45:44: note: in definition of macro ‘_unlikely_’
#define _unlikely_(x) (__builtin_expect(!!(x),0))
^
./src/basic/stdio-util.h:30:9: note: in expansion of macro ‘assert_message_se’
assert_message_se((size_t) snprintf(buf, ELEMENTSOF(buf), fmt, __VA_ARGS__) < ELEMENTSOF(buf), "xsprintf: " #buf "[] must be big enough")
^~~~~~~~~~~~~~~~~
src/libsystemd/sd-bus/bus-kernel.c:851:17: note: in expansion of macro ‘xsprintf’
xsprintf(m->sender_buffer, ":1.%"PRIu64, k->src_id);
^~~~~~~~
src/libsystemd/sd-bus/bus-kernel.c:862:49: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 4 has type ‘__u64 {aka long long unsigned int}’ [-Wformat=]
xsprintf(m->destination_buffer, ":1.%"PRIu64, k->dst_id);
^
./src/basic/macro.h:45:44: note: in definition of macro ‘_unlikely_’
#define _unlikely_(x) (__builtin_expect(!!(x),0))
^
./src/basic/stdio-util.h:30:9: note: in expansion of macro ‘assert_message_se’
assert_message_se((size_t) snprintf(buf, ELEMENTSOF(buf), fmt, __VA_ARGS__) < ELEMENTSOF(buf), "xsprintf: " #buf "[] must be big enough")
^~~~~~~~~~~~~~~~~
src/libsystemd/sd-bus/bus-kernel.c:862:17: note: in expansion of macro ‘xsprintf’
xsprintf(m->destination_buffer, ":1.%"PRIu64, k->dst_id);
^~~~~~~~
Member
There was a problem hiding this comment.
ah yeah, __u64 is defined differently than uint64_t. Kernel hackers FTW!
keszybz
added a commit
to keszybz/systemd
that referenced
this pull request
Nov 3, 2016
This reverts commit 75ead2b. Follow up for systemd#4546: > @@ -848,8 +848,7 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) { if (k->src_id == KDBUS_SRC_ID_KERNEL) bus_message_set_sender_driver(bus, m); else { - xsprintf(m->sender_buffer, ":1.%llu", - (unsigned long long)k->src_id); + xsprintf(m->sender_buffer, ":1.%"PRIu64, k->src_id); This produces: ``` src/libsystemd/sd-bus/bus-kernel.c: In function ‘bus_kernel_make_message’: src/libsystemd/sd-bus/bus-kernel.c:851:44: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 4 has type ‘__u64 {aka long long unsigned int}’ [-Wformat=] xsprintf(m->sender_buffer, ":1.%"PRIu64, k->src_id); ^
Member
Author
|
I'd argue that this is a gcc bug: it's trying to be helpful but just gets in the way. It should never emit this warning when the variable is of the right size. |
keszybz
added a commit
that referenced
this pull request
Nov 3, 2016
This reverts commit 75ead2b. Follow up for #4546: > @@ -848,8 +848,7 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) { if (k->src_id == KDBUS_SRC_ID_KERNEL) bus_message_set_sender_driver(bus, m); else { - xsprintf(m->sender_buffer, ":1.%llu", - (unsigned long long)k->src_id); + xsprintf(m->sender_buffer, ":1.%"PRIu64, k->src_id); This produces: src/libsystemd/sd-bus/bus-kernel.c: In function ‘bus_kernel_make_message’: src/libsystemd/sd-bus/bus-kernel.c:851:44: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 4 has type ‘__u64 {aka long long unsigned int}’ [-Wformat=] xsprintf(m->sender_buffer, ":1.%"PRIu64, k->src_id); ^
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.