Closed ac000 closed 2 weeks ago
The first one was introduced at https://github.com/nginx/unit/commit/caa05887ff70bbd6338b129959a234ef56f1a287. And two ways to fix it.
1.
diff -r 0e6d01d0c23b src/nxt_sprintf.c
--- a/src/nxt_sprintf.c Thu Sep 28 15:14:21 2023 +0100
+++ b/src/nxt_sprintf.c Mon Oct 09 16:06:19 2023 +0800
@@ -156,7 +156,8 @@
p = va_arg(args, const u_char *);
if (nxt_slow_path(p == NULL)) {
- goto copy;
+ buf = nxt_cpymem(buf, null, nxt_length(null));
+ continue;
}
while (*p != '\0' && buf < end) {
@@ -174,6 +175,11 @@
fmt++;
p = va_arg(args, const u_char *);
+ if (nxt_slow_path(p == NULL)) {
+ buf = nxt_cpymem(buf, null, nxt_length(null));
+ continue;
+ }
+
goto copy;
}
@@ -556,14 +562,7 @@
copy:
- if (nxt_slow_path(p == NULL)) {
- p = null;
- length = nxt_length(null);
-
- } else {
- length = nxt_min((size_t) (end - buf), length);
- }
-
+ length = nxt_min((size_t) (end - buf), length);
buf = nxt_cpymem(buf, p, length);
continue;
}
2.
diff -r 0e6d01d0c23b src/nxt_sprintf.c
--- a/src/nxt_sprintf.c Thu Sep 28 15:14:21 2023 +0100
+++ b/src/nxt_sprintf.c Mon Oct 09 16:07:18 2023 +0800
@@ -156,6 +156,7 @@
p = va_arg(args, const u_char *);
if (nxt_slow_path(p == NULL)) {
+ length = 0;
goto copy;
}
I prefer (1) since the second one is a trick to avoid warnings.
About the notify
variable, we could just set it with an initial value like this. But it's also a trick like the above.
diff -r 0e6d01d0c23b src/nxt_router.c
--- a/src/nxt_router.c Thu Sep 28 15:14:21 2023 +0100
+++ b/src/nxt_router.c Mon Oct 09 16:23:24 2023 +0800
@@ -5244,7 +5244,7 @@
nxt_int_t res;
nxt_port_t *port, *reply_port;
- int notify;
+ int notify = 0;
struct {
nxt_port_msg_t pm;
nxt_port_mmap_msg_t mm;
diff -r 0e6d01d0c23b src/nxt_sprintf.c
And it has no issue here, since if nxt_app_queue_send()
returns NXT_OK
, the notify has been set a value.
But the fixes are based on if the GCC option -Og
is enabled.
do we want to suppress these warnings?
I rarely modify Makefile manually, but I'm open to it.
The first one was introduced at caa0588. And two ways to fix it.
diff -r 0e6d01d0c23b src/nxt_sprintf.c --- a/src/nxt_sprintf.c Thu Sep 28 15:14:21 2023 +0100 +++ b/src/nxt_sprintf.c Mon Oct 09 16:06:19 2023 +0800 @@ -156,7 +156,8 @@ p = va_arg(args, const u_char *); if (nxt_slow_path(p == NULL)) { - goto copy; + buf = nxt_cpymem(buf, null, nxt_length(null)); + continue; } while (*p != '\0' && buf < end) { @@ -174,6 +175,11 @@ fmt++; p = va_arg(args, const u_char *); + if (nxt_slow_path(p == NULL)) { + buf = nxt_cpymem(buf, null, nxt_length(null)); + continue; + } + goto copy; } @@ -556,14 +562,7 @@ copy: - if (nxt_slow_path(p == NULL)) { - p = null; - length = nxt_length(null); - - } else { - length = nxt_min((size_t) (end - buf), length); - } - + length = nxt_min((size_t) (end - buf), length); buf = nxt_cpymem(buf, p, length); continue; }
Yes, I like this one as it's more explicit than what we currently have.
About the
notify
variable, we could just set it with an initial value like this. But it's also a trick like the above.diff -r 0e6d01d0c23b src/nxt_router.c --- a/src/nxt_router.c Thu Sep 28 15:14:21 2023 +0100 +++ b/src/nxt_router.c Mon Oct 09 16:23:24 2023 +0800 @@ -5244,7 +5244,7 @@ nxt_int_t res; nxt_port_t *port, *reply_port; - int notify; + int notify = 0; struct { nxt_port_msg_t pm; nxt_port_mmap_msg_t mm; diff -r 0e6d01d0c23b src/nxt_sprintf.c
I'd be inclined not to bother about this. GCC may get better at this at some point and compiling with -O0 doesn't have this issue and generally does OK for debugging.
I'd be inclined not to bother about this.
Do you mean to keep them as is? including the rework on the length
warning?
If yes, I agree.
On Mon, 09 Oct 2023 02:47:47 -0700 hongzhidao @.***> wrote:
I'd be inclined not to bother about this.
Do you mean to keep them as is? including the rework on the
length
warning? If yes, I agree.
I mean to use your first option for the first problem, I think it improves the readability of the code.
But not bother fixing the second issue which would simply be an appeasement.
With current GCC (14..1.1) the second warning is gone.
When compiling with GCC and -Og we get the following warnings
This looks bogus as the only place we may end up at
without setting length is via
However in this case p is NULL, so we won't hit the problematic code.
The second also looks like a bogus warning as notify will get set by
I suppose the question is, do we want to suppress these warnings?