Skip to contentSkip to conversation

curl: Cast fd to int for DPRINTF

PATCH In review Fam Zheng 2 participants 5 messages Aug 1, 2016 – Aug 10, 2016 Block layer

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

PATCH 1/1 curl: Cast fd to int for DPRINTF

Currently "make docker-test-mingw@fedora" has a warning like:

/tmp/qemu-test/src/block/curl.c: In function 'curl_sock_cb':
/tmp/qemu-test/src/block/curl.c:172:6: warning: format '%d' expects argument of type 'int', but argument 4 has type 'curl_socket_t {aka long long unsigned int}'
DPRINTF("CURL (AIO): Sock action %d on fd %d\n", action, fd);
^
cc1: all warnings being treated as errors

Cast to int to suppress it.

---
 block/curl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/curl.c +1 -1
index da9f5e8..426fb4d 100644
@@ -169,7 +169,7 @@ static int curl_sock_cb(CURL *curl, curl_socket_t fd, int action,
     state->sock_fd = fd;
     s = state->s;
 
-    DPRINTF("CURL (AIO): Sock action %d on fd %d\n", action, fd);
+    DPRINTF("CURL (AIO): Sock action %d on fd %d\n", action, (int)fd);
     switch (action) {
         case CURL_POLL_IN:
             aio_set_fd_handler(s->aio_context, fd, false,
Signature · 1 line
2.7.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 23 lines · Fam Zheng

Currently "make docker-test-mingw@fedora" has a warning like:

/tmp/qemu-test/src/block/curl.c: In function 'curl_sock_cb':
/tmp/qemu-test/src/block/curl.c:172:6: warning: format '%d' expects argument of type 'int', but argument 4 has type 'curl_socket_t {aka long long unsigned int}'
DPRINTF("CURL (AIO): Sock action %d on fd %d\n", action, fd);
^
cc1: all warnings being treated as errors

Cast to int to suppress it.

---
 block/curl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/curl.c +0 -0
index da9f5e8..426fb4d 100644

block/curl.c static int curl_sock_cb(CURL *curl, curl_socket_t fd, int action, · line 175

Quoted 8 lines
block/curl.c +1 -1
@@ -169,7 +169,7 @@ static int curl_sock_cb(CURL *curl, curl_socket_t fd, int action,
     state->sock_fd = fd;
     s = state->s;
 
-    DPRINTF("CURL (AIO): Sock action %d on fd %d\n", action, fd);
+    DPRINTF("CURL (AIO): Sock action %d on fd %d\n", action, (int)fd);
     switch (action) {
         case CURL_POLL_IN:
             aio_set_fd_handler(s->aio_context, fd, false,

Is curl_socket_t always of type long long unsigned int? why not use %llu ?

(...Yeah, I know, we're probably not going to be dealing with FDs above 2-4 billion, just curious...)

--js

Benefit of doubt (this cast is almost certain to never do the wrong thing, and even if it did, it's just a dprintf)

author
#2 lore raw
Quoted 8 lines · John Snow

block/curl.c static int curl_sock_cb(CURL *curl, curl_socket_t fd, int action, · line 175

Quoted 6 lines
block/curl.c +1 -1
-    DPRINTF("CURL (AIO): Sock action %d on fd %d\n", action, fd);
+    DPRINTF("CURL (AIO): Sock action %d on fd %d\n", action, (int)fd);
     switch (action) {
         case CURL_POLL_IN:
             aio_set_fd_handler(s->aio_context, fd, false,

Is curl_socket_t always of type long long unsigned int? why not use %llu ?

Since it is a typedef, variation between platforms is imaginable. On Linux it is 4 bytes, the error is only seen on Windows.

Fam

#3 lore raw
Quoted 8 lines · Fam Zheng
Quoted 7 lines · John Snow
Quoted 6 lines
block/curl.c +1 -1
-    DPRINTF("CURL (AIO): Sock action %d on fd %d\n", action, fd);
+    DPRINTF("CURL (AIO): Sock action %d on fd %d\n", action, (int)fd);
     switch (action) {
         case CURL_POLL_IN:
             aio_set_fd_handler(s->aio_context, fd, false,
Quoted 7 lines
Quoted 1 line

Is curl_socket_t always of type long long unsigned int? why not use %llu ?

Since it is a typedef, variation between platforms is imaginable. On Linux it is 4 bytes, the error is only seen on Windows.

Fam

Ah, there we go. The B-O-D was justified. :)

author
#4 lore raw
In reply to Fam Zheng
Quoted 34 lines · Fam Zheng

Currently "make docker-test-mingw@fedora" has a warning like:

/tmp/qemu-test/src/block/curl.c: In function 'curl_sock_cb':
/tmp/qemu-test/src/block/curl.c:172:6: warning: format '%d' expects argument of type 'int', but argument 4 has type 'curl_socket_t {aka long long unsigned int}'
DPRINTF("CURL (AIO): Sock action %d on fd %d\n", action, fd);
^
cc1: all warnings being treated as errors

Cast to int to suppress it.

---
 block/curl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/curl.c +1 -1
index da9f5e8..426fb4d 100644
@@ -169,7 +169,7 @@ static int curl_sock_cb(CURL *curl, curl_socket_t fd, int action,
     state->sock_fd = fd;
     s = state->s;
 
-    DPRINTF("CURL (AIO): Sock action %d on fd %d\n", action, fd);
+    DPRINTF("CURL (AIO): Sock action %d on fd %d\n", action, (int)fd);
     switch (action) {
         case CURL_POLL_IN:
             aio_set_fd_handler(s->aio_context, fd, false,
Signature · 1 line
2.7.4

Since this is blocking the mingw testing on patchew, I'm taking this in my tree. Applied to my docker branch:

https://github.com/famz/qemu/tree/docker

Thanks,
Fam