Tomas-M / iotop

A top utility for IO
Other
376 stars 50 forks source link

Warnings with clang #27

Closed rossburton closed 2 years ago

rossburton commented 2 years ago

When building with clang for 32-bit arm:

src/xxxid_info.c:103:52: warning: comparison of integers of different signs: '__u32' (aka 'unsigned int') and 'ssize_t' (aka 'int') [-Wsign-compare]
        if (answ.n.nlmsg_type==NLMSG_ERROR||(rep_len<0)||!NLMSG_OK((&answ.n),rep_len))
                                                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/linux/netlink.h:100:24: note: expanded from macro 'NLMSG_OK'
                           (nlh)->nlmsg_len <= (len))
                           ~~~~~~~~~~~~~~~~ ^   ~~~
src/xxxid_info.c:157:38: warning: comparison of integers of different signs: '__u32' (aka 'unsigned int') and 'ssize_t' (aka 'int') [-Wsign-compare]
        if (msg.n.nlmsg_type==NLMSG_ERROR||!NLMSG_OK((&msg.n),rv)) {
                                            ^~~~~~~~~~~~~~~~~~~~~
/usr/include/linux/netlink.h:100:24: note: expanded from macro 'NLMSG_OK'
                           (nlh)->nlmsg_len <= (len))
                           ~~~~~~~~~~~~~~~~ ^   ~~~
2 warnings generated.
bbonev commented 2 years ago

No (easy) way for me to test...

Does this help:

--- a/src/xxxid_info.c
+++ b/src/xxxid_info.c
@@ -100,7 +100,7 @@ inline int get_family_id(int sock_fd) {
                return 0;

        rep_len=recv(sock_fd,&answ,sizeof answ,0);
-       if (answ.n.nlmsg_type==NLMSG_ERROR||(rep_len<0)||!NLMSG_OK((&answ.n),rep_len))
+       if (answ.n.nlmsg_type==NLMSG_ERROR||(rep_len<0)||!NLMSG_OK((&answ.n),(unsigned)rep_len))
                return 0;

        na=(struct nlattr *)GENLMSG_DATA(&answ);
@@ -154,7 +154,7 @@ inline int nl_xxxid_info(pid_t tid,pid_t pid,struct xxxid_stats *stats) {
        struct msgtemplate msg;
        ssize_t rv=recv(nl_sock,&msg,sizeof msg,0);

-       if (msg.n.nlmsg_type==NLMSG_ERROR||!NLMSG_OK((&msg.n),rv)) {
+       if (msg.n.nlmsg_type==NLMSG_ERROR||!NLMSG_OK((&msg.n),(unsigned)rv)) {
                struct nlmsgerr *err=NLMSG_DATA(&msg);
                if (err->error!=-ESRCH)
                        fprintf(stderr,"fatal reply error, %d\n",err->error);
bbonev commented 2 years ago

The bigger problem with these checks is that they are not done in the proper order. Fixed, thanks for the hint!