-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
remove invalid string format and args #15729
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
So this format string is stil wrong. |
|
Please add this commit to your PR after it all compiles: |
src/resolve/resolved-dns-rr.c
Outdated
| t = dns_type_to_string(key->type); | ||
|
|
||
| snprintf(buf, buf_size, "%s %s%s%.0u %s%s%.0u", | ||
| snprintf(buf, buf_size, "%s %s%s%.0d %s%s%.0d", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PRIu16
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc -Isrc/resolve/085a0f9@@systemd-resolve-core@sta -Isrc/resolve -I../src/resolve -Isrc/basic -I../src/basic -Isrc/boot -I../src/boot -Isrc/home -I../src/home -Isrc/shared -I../src/shared -Isrc/systemd -I../src/systemd -Isrc/journal -I../src/journal -Isrc/journal-remote -I../src/journal-remote -Isrc/nspawn -I../src/nspawn -Isrc/timesync -I../src/timesync -I../src/time-wait-sync -Isrc/login -I../src/login -Isrc/udev -I../src/udev -Isrc/libudev -I../src/libudev -Isrc/core -I../src/core -Isrc/shutdown -I../src/shutdown -I../src/libsystemd/sd-bus -I../src/libsystemd/sd-device -I../src/libsystemd/sd-event -I../src/libsystemd/sd-hwdb -I../src/libsystemd/sd-id128 -I../src/libsystemd/sd-netlink -I../src/libsystemd/sd-network -I../src/libsystemd/sd-resolve -Isrc/libsystemd-network -I../src/libsystemd-network -I. -I.. -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -std=gnu99 -g -Wno-unused-parameter -Wno-missing-field-initializers -Wno-unused-result -Wno-format-signedness -Werror=undef -Wlogical-op -Wmissing-include-dirs -Wold-style-definition -Wpointer-arith -Winit-self -Wfloat-equal -Wsuggest-attribute=noreturn -Werror=missing-prototypes -Werror=implicit-function-declaration -Werror=missing-declarations -Werror=return-type -Werror=incompatible-pointer-types -Werror=format=2 -Wstrict-prototypes -Wredundant-decls -Wmissing-noreturn -Wimplicit-fallthrough=5 -Wshadow -Wendif-labels -Wstrict-aliasing=2 -Wwrite-strings -Werror=overflow -Werror=shift-count-overflow -Werror=shift-overflow=2 -Wdate-time -Wnested-externs -Wno-maybe-uninitialized -ffast-math -fno-common -fdiagnostics-show-option -fno-strict-aliasing -fvisibility=hidden -fstack-protector -fstack-protector-strong --param=ssp-buffer-size=4 -Werror=shadow -include config.h -fPIC -MD -MQ 'src/resolve/085a0f9@@systemd-resolve-core@sta/resolved-dns-rr.c.o' -MF 'src/resolve/085a0f9@@systemd-resolve-core@sta/resolved-dns-rr.c.o.d' -o 'src/resolve/085a0f9@@systemd-resolve-core@sta/resolved-dns-rr.c.o' -c ../src/resolve/resolved-dns-rr.c
../src/resolve/resolved-dns-rr.c: In function ‘dns_resource_key_to_string’:
../src/resolve/resolved-dns-rr.c:324:44: error: unknown conversion type character ‘P’ in format [-Werror=format=]
324 | snprintf(buf, buf_size, "%s %s%s%.0PRIu16 %s%s%.0PRIu16",
| ^
../src/resolve/resolved-dns-rr.c:324:52: error: format ‘%s’ expects argument of type ‘char *’, but argument 7 has type ‘int’ [-Werror=format=]
324 | snprintf(buf, buf_size, "%s %s%s%.0PRIu16 %s%s%.0PRIu16",
| ~^
| |
| char *
| %d
325 | dns_resource_key_name(key),
326 | strempty(c), c ? "" : "CLASS", c ? 0 : key->class,
| ~~~~~~~~~~~~~~~~~~
| |
| int
../src/resolve/resolved-dns-rr.c:324:58: error: unknown conversion type character ‘P’ in format [-Werror=format=]
324 | snprintf(buf, buf_size, "%s %s%s%.0PRIu16 %s%s%.0PRIu16",
| ^
../src/resolve/resolved-dns-rr.c:324:33: error: too many arguments for format [-Werror=format-extra-args]
324 | snprintf(buf, buf_size, "%s %s%s%.0PRIu16 %s%s%.0PRIu16",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PRIu16 is a format string, so it should be used as:
snprintf(buf, buf_size, "%s %s%s%" PRIu16 " %s%s%" PRIu16,
...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the examples here:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, fixed locally, just trying to get #15729 (comment) patched but having some issues
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, not actually fixed, is it?
|
i am not sure it's worth fixing a source code we copied in, and probably should stay close to its origin like this, in particular if the code is ifdeffed out... But if we fix that, then at least do it properly, using the PRI macros |
keszybz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i am not sure it's worth fixing a source code we copied in, and probably should stay close to its origin like this, in particular if the code is ifdeffed out...
I think it is. See my comment above, we can than run it as a unit test.
@keszybz Are you OK that I applied it manually, couldn't do git am and needed some extra work to fix the errors and warnings? I can reference you in the commit? Will fixup the commit after |
d7a8219 to
e5e6bc8
Compare
|
Looks OK, but please remove the "wip" strings... We don't want that in git log. |
Agreed, but it still doesn't pass. Even after fixing the errors in the test script caught by pylint. Will investigate why but not entirely sure why, my guess is that it needs re-factoring but could be wrong |
a50f540 to
f593f2d
Compare
src/journal/lookup3.c
Outdated
| { | ||
| h = hashlittle(buf, 0, h); | ||
| printf("%2ld 0-byte strings, hash is %.8x\n", i, h); | ||
| printf("%2u 0-byte strings, hash is %.8x\n", i, h); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
src/resolve/resolved-dns-rr.c
Outdated
| t = dns_type_to_string(key->type); | ||
|
|
||
| snprintf(buf, buf_size, "%s %s%s%.0u %s%s%.0u", | ||
| snprintf(buf, buf_size, "%s %s%s%" PRIu16 " %s%s%" PRIu16, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this shouldn't drop the .0
|
@FrazerClews can we please have another round here? |
|
bb9c2be to
acafc85
Compare
ca6f61c to
58c40d1
Compare
2ea82ad to
2deb6e6
Compare
5aaab32 to
9f00d0b
Compare
hixiomh
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull requested
7d910ff to
91a189c
Compare
src/journal/lookup3.c
Outdated
| } | ||
| time(&z); | ||
| if (z-a > 0) printf("time %d %.8x\n", z-a, h); | ||
| if (z-a > 0) printf("time %ld %.8x\n", z-a, h); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, if we wanted to do this fully correctly, we'd define TIME_FMT that maps to the correct format string for time_t... We do it like that for uid_t → UID_FMT, pid_t → PID_FMT and so on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried using the function difftime() and used lf as the string format for doubles to have it as close as it was before. If that's what you want it?
src/resolve/resolved-dns-rr.c
Outdated
| t = dns_type_to_string(key->type); | ||
|
|
||
| snprintf(buf, buf_size, "%s %s%s%.0u %s%s%.0u", | ||
| snprintf(buf, buf_size, "%s %s%s%.0d %s%s%.0d", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, not actually fixed, is it?
8aea240 to
55b2f27
Compare
- also remove unused variables and fix string format - systemd-networkd-tests.py singleton comparison and simplify inheritance - remove resolvectl test while -t MX still fails when DNSSEC is enabled
55b2f27 to
2a5bbc9
Compare
dnicolodi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first patch seems ok. The second one has a couple of good hunks in it, but the hash lookup tests and the changes to the networkd test suite should be split into two separate patches. I think that the third patch should go. Other comments inline.
| not (expected == 'managed' and actual != 'unmanaged')): | ||
| self.fail("Link {} expects state {}, found {}".format(iface, expected, actual)) | ||
| err_msg = "Link {} expects state {}, found {}".format(iface, expected, actual) | ||
| self.fail(err_msg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a hack to get it working during testing, before if you got an error, it would print Link {} expects state {}, found {} and not format. Trying to find a better solution
|
|
||
|
|
||
| class BridgeTest(NetworkdTestingUtilities, unittest.TestCase): | ||
| class BridgeTest(unittest.TestCase, NetworkdTestingUtilities): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this make a difference in practice?
| def setUpClass(klass): | ||
| klass.orig_log_level = subprocess.check_output( | ||
| def setUpClass(cls): | ||
| cls.orig_log_level = subprocess.check_output( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cls may be a tiny bit more idiomatic than klass, but I don't see the point of this change and similar ones below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's to follow python convention of having the class argument being called cls. Which makes it easier for new users and tools like pylint to know what it does
| out = subprocess.check_output(['resolvectl', 'query', '--type=MX', 'example.com']) | ||
| self.assertIn(b'example.com IN MX 1 mail.example.com', out) | ||
| # out = subprocess.check_output(['resolvectl', 'query', '--type=MX', 'example.com']) | ||
| # self.assertIn(b'example.com IN MX 1 mail.example.com', out) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it is ok to comment out tests...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This failed and I think is due to the issue listed above
# FIXME: -t MX query fails with enabled DNSSEC (even when using
# the known negative trust anchor .internal instead of .example.com)
|
|
||
|
|
||
| class Utilities(): | ||
| class Utilities(unittest.TestCase): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
| self.assertRegex(output, address_regex) | ||
|
|
||
| class NetworkctlTests(unittest.TestCase, Utilities): | ||
| class NetworkctlTests(Utilities): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see the point. The code was actually more semantically correct before. It of course applies to all similar changes below.
| #define hashlittle2 jenkins_hashlittle2 | ||
| #define hashword jenkins_hashword | ||
| #define hashword2 jenkins_hashword2 | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why this is necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add this commit to your PR after it all compiles:
This was a patch @keszybz wanted
|
Let's close this. After a4ea5d1 I think we get most types right, and the compiler should warn us where we don't. if you see this is not the case, please file a new PR. |
WIP since the last commit needs a double check for if it's correct for
memset