GCC 9.0.1 isn't smart enough to work out that buf is initialized on
all the relevant paths that lead to backend->pwrite being called. By
initializing it we can avoid the warning.
protocol.c: In function ‘protocol_recv_request_send_reply’:
protocol.c:241:9: error: ‘buf’ may be used uninitialized in this function
[-Werror=maybe-uninitialized]
241 | if (backend->pwrite (backend, conn, buf, count, offset, f, &err) ==
-1)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
protocol.c:614:9: note: ‘buf’ was declared here
614 | char *buf;
| ^~~
---
server/protocol.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/server/protocol.c b/server/protocol.c
index 6fd3b62..5033fd7 100644
--- a/server/protocol.c
+++ b/server/protocol.c
@@ -611,7 +611,7 @@ protocol_recv_request_send_reply (struct connection *conn)
uint16_t cmd, flags;
uint32_t magic, count, error = 0;
uint64_t offset;
- char *buf;
+ char *buf = NULL;
CLEANUP_EXTENTS_FREE struct nbdkit_extents *extents = NULL;
/* Read the request packet. */
--
2.20.1