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

libsodium 1.0.6: sodium_init() marked with __attribute__ ((warn_unused_result)) #1632

Closed
sthen opened this issue Nov 3, 2015 · 6 comments
Closed

Comments

@sthen
Copy link

sthen commented Nov 3, 2015

libsodium 1.0.6 now marks sodium_init() with an attribute:

int sodium_init(void)
            __attribute__ ((warn_unused_result));

As a result, libzmq's build done with -Werror fails:

cc1plus: warnings being treated as errors
src/curve_client.cpp: In constructor 'zmq::curve_client_t::curve_client_t(const zmq::options_t&)':
src/curve_client.cpp:61: warning: ignoring return value of 'int sodium_init()', declared with attribute warn_unused_result
@xaqq
Copy link
Member

xaqq commented Nov 3, 2015

Somehow your fix doesn't show up on the github page.

Yes it seems reasonable, though I'd personnaly prefer something like:

int ret = sodium_init();
zmq_assert(ret == 0);

I've been beaten by assert disappearing in non debug code before. (I know
that zmq_assert() is not disabled in release mode, but still).

On Tue, Nov 3, 2015 at 2:20 PM, Stuart Henderson notifications@github.com
wrote:

libsodium 1.0.6 now marks sodium_init() with an attribute:

int sodium_init(void)
attribute ((warn_unused_result));

As a result, libzmq's build done with -Werror fails:

cc1plus: warnings being treated as errors
src/curve_client.cpp: In constructor 'zmq::curve_client_t::curve_client_t(const zmq::options_t&)':
src/curve_client.cpp:61: warning: ignoring return value of 'int sodium_init()', declared with attribute warn_unused_result

Is this a reasonable fix for now?

--- src/curve_client.cpp.orig Tue Nov 3 13:11:25 2015
+++ src/curve_client.cpp Tue Nov 3 13:12:29 2015
@@ -57,8 +57,7 @@ zmq::curve_client_t::curve_client_t (const options_t &
unsigned char tmpbytes[4];
randombytes(tmpbytes, 4);
#else

  • // todo check return code

  • sodium_init();

  • zmq_assert (sodium_init() == 0);
    #endif

    // Generate short-term key pair
    --- src/curve_server.cpp.orig Tue Nov 3 13:12:52 2015
    +++ src/curve_server.cpp Tue Nov 3 13:13:18 2015
    @@ -60,8 +60,7 @@ zmq::curve_server_t::curve_server_t (session_base_t *s
    unsigned char tmpbytes[4];
    randombytes(tmpbytes, 4);
    #else

  • // todo check return code

  • sodium_init();

  • zmq_assert (sodium_init() == 0);
    #endif

    // Generate short-term key pair


Reply to this email directly or view it on GitHub
#1632.

Kapp Arnaud - Xaqq

@sthen
Copy link
Author

sthen commented Nov 3, 2015

Ah I edited the post to remove the fix as it triggers an abort in the tests, so I wasn't sure what else needed doing ;)

@xaqq
Copy link
Member

xaqq commented Nov 3, 2015

Okay, I believe I know why.

sodium_init() can be called multiple time, however if the library was
already initialized it will return 1 instead of 0.

"sodium_init() returns 0 on success, -1 on failure, and 1 is the library
had already been initialized." from
http://doc.libsodium.org/usage/index.html

On Tue, Nov 3, 2015 at 3:39 PM, Stuart Henderson notifications@github.com
wrote:

Ah I edited the post to remove the fix as it triggers an abort in the
tests, so I wasn't sure what else needed doing ;)


Reply to this email directly or view it on GitHub
#1632 (comment).

Kapp Arnaud - Xaqq

@sthen
Copy link
Author

sthen commented Nov 3, 2015

So this does the trick, or it could just check for != -1 ..

Index: patch-src_curve_client_cpp
===================================================================
RCS file: patch-src_curve_client_cpp
diff -N patch-src_curve_client_cpp
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patch-src_curve_client_cpp  3 Nov 2015 16:38:21 -0000
@@ -0,0 +1,14 @@
+--- src/curve_client.cpp.orig  Tue Nov  3 16:35:06 2015
++++ src/curve_client.cpp   Tue Nov  3 16:36:32 2015
+@@ -57,8 +57,8 @@ zmq::curve_client_t::curve_client_t (const options_t &
+     unsigned char tmpbytes[4];
+     randombytes(tmpbytes, 4);
+ #else
+-    // todo check return code
+-    sodium_init();
++    const int ret = sodium_init();
++    zmq_assert ((ret == 0) || (ret == 1));
+ #endif
+ 
+     //  Generate short-term key pair
Index: patch-src_curve_server_cpp
===================================================================
RCS file: patch-src_curve_server_cpp
diff -N patch-src_curve_server_cpp
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patch-src_curve_server_cpp  3 Nov 2015 16:38:21 -0000
@@ -0,0 +1,14 @@
+--- src/curve_server.cpp.orig  Tue Nov  3 16:35:06 2015
++++ src/curve_server.cpp   Tue Nov  3 16:36:49 2015
+@@ -60,8 +60,8 @@ zmq::curve_server_t::curve_server_t (session_base_t *s
+     unsigned char tmpbytes[4];
+     randombytes(tmpbytes, 4);
+ #else
+-    // todo check return code
+-    sodium_init();
++    const int ret = sodium_init();
++    zmq_assert ((ret == 0) || (ret == 1));
+ #endif
+ 
+     //  Generate short-term key pair

@c-rack
Copy link
Member

c-rack commented Nov 3, 2015

Please correct me if I am wrong, but this has been in libzmq since 479db21 (about a year ago).
@sthen which version of libzmq are you using?

@hintjens
Copy link
Member

hintjens commented Nov 4, 2015

Backported to 4-1. I'm closing this issue now.

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

4 participants