eina: fix behaviour break of eina_error_msg_get()
authorJean Guyomarc'h <jean.guyomarch@openwide.fr>
Mon, 29 Aug 2016 13:24:51 +0000 (15:24 +0200)
committerJean Guyomarc'h <jean@guyomarch.bzh>
Mon, 29 Aug 2016 18:03:52 +0000 (20:03 +0200)
eina_error_msg_get() must return NULL if an incorrect error is provided.
The XSI strerror_r() returns EINVAL when an invalid error is passed to
it, so we can end the function here. If we kept on, we would have tested
against the 'unknown_prefix' ("Unknown error ") which is implementation
defined, and registered a new error when the invalid error message
didn't match the 'unknown_prefix'. This new error message would have
been returned, which is not what we expected.

This case arised on Mac OS X where the 'unkwown prefix' is
"Unknown error: " instead of "Unknown error ".

It fixes eina test suite on Mac OS X.

src/lib/eina/eina_error.c

index 79c934a..779739d 100644 (file)
@@ -315,8 +315,13 @@ eina_error_msg_get(Eina_Error error)
 
 #ifdef HAVE_STRERROR_R
 # ifndef STRERROR_R_CHAR_P
-             if (strerror_r(error, buf, sizeof(buf)) == 0) /* XSI */
+             int ret;
+
+             ret = strerror_r(error, buf, sizeof(buf)); /* XSI */
+             if (ret == 0)
                str = buf;
+             else if (ret == EINVAL)
+               return NULL;
 # else /* STRERROR_R_CHAR_P */
              str = strerror_r(error, buf, sizeof(buf)); /* GNU */
 # endif /* ! STRERROR_R_CHAR_P */