Skip to content
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

Unused variable warnings under NDEBUG #26

Open
iphydf opened this issue Sep 6, 2018 · 0 comments
Open

Unused variable warnings under NDEBUG #26

iphydf opened this issue Sep 6, 2018 · 0 comments

Comments

@iphydf
Copy link
Contributor

iphydf commented Sep 6, 2018

A possible solution:

diff --git a/src/listener.cpp b/src/listener.cpp
index 199af10..d35b56a 100644
--- a/src/listener.cpp
+++ b/src/listener.cpp
@@ -32,7 +32,9 @@ SocketListener::SocketListener(NetworkInterface* iface

 #ifdef ZMQ
     zmq_broadcast = zmq_socket(zmq, ZMQ_PUB);
+#ifndef NDEBUG
     int rc =
+#endif
         zmq_bind(zmq_broadcast,
                  (std::string("ipc://") + unixSocket + "broadcast").c_str());
     assert(rc == 0);
@@ -80,7 +82,10 @@ void SocketListener::broadcast(const char* msg) {
     char* hack = new char[4];
     strcpy(hack, "all");
     hack[3] = 0;
-    int rc = zmq_msg_init_data(&header, hack, 3, NULL, NULL);
+#ifndef NDEBUG
+    int rc =
+#endif
+        zmq_msg_init_data(&header, hack, 3, NULL, NULL);
     assert(rc == 0);
     zmq_msg_send(&header, zmq_broadcast, ZMQ_SNDMORE);

@@ -88,7 +93,10 @@ void SocketListener::broadcast(const char* msg) {
     strncpy(copy, msg, strlen(msg));

     zmq_msg_t msg_out;
-    rc = zmq_msg_init_data(&msg_out, (void*) copy, strlen(msg), NULL, NULL);
+#ifndef NDEBUG
+    rc =
+#endif
+        zmq_msg_init_data(&msg_out, (void*) copy, strlen(msg), NULL, NULL);
     assert(rc == 0);
     zmq_msg_send(&msg_out, zmq_broadcast, 0);
 #endif
diff --git a/src/main.cpp b/src/main.cpp
index 2a8287a..49ede36 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -49,7 +49,10 @@ void saveState(Tox* tox) {
     tox_get_savedata(tox, savedata);
     int fd = open("savedata", O_TRUNC | O_WRONLY | O_CREAT, 0644);
     assert(fd);
-    ssize_t written = write(fd, savedata, size);
+#ifndef NDEBUG
+    ssize_t written =
+#endif
+        write(fd, savedata, size);
     assert(written > 0); // FIXME: check even if NDEBUG is disabled
     close(fd);
     delete[] savedata;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant