]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Clarify para_strerror().
authorAndre Noll <maan@tuebingen.mpg.de>
Mon, 10 Aug 2015 18:00:49 +0000 (20:00 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Sun, 27 Sep 2015 13:25:39 +0000 (13:25 +0000)
para_strerror() needs to distinguish three kinds of errors: paraslash
errors, errors from the osl library, and system (libc) errors. This
is achieved through dedicated bits in the error code which are
set for errors from osl and libc function calls. These bits tell
para_strerror() which function to call in order to obtain the text
that corresponds to the error code.

If such a dedicated bit is set, para_strerror() first clears the bit,
then calls the library strerror() function that corresponds to the
bit. The code to clear the bit is

num & ((1 << OSL_ERROR_BIT) - 1))

and similar for libc errors. However, this expression clears *all*
high bits, not only bit number OSL_ERROR_BIT. This is not a problem
since the higher bits are not set under normal circumstances, but it
is better to fix this anyway. The new code is

num & ~(1U << OSL_ERROR_BIT),

which turns off the osl error bit only.

error.h

diff --git a/error.h b/error.h
index 27e9e264ba10206e9218ac25013f63f04bc821ec..379d37326782f308ce6b7e576c25383ea1b7b8c7 100644 (file)
--- a/error.h
+++ b/error.h
@@ -590,10 +590,10 @@ _static_inline_ const char *para_strerror(int num)
        assert(num > 0);
 #ifdef _OSL_H
        if (IS_OSL_ERROR(num))
-               return osl_strerror(num & ((1 << OSL_ERROR_BIT) - 1));
+               return osl_strerror(num & ~(1U << OSL_ERROR_BIT));
 #endif
        if (IS_SYSTEM_ERROR(num))
-               return strerror(num & ((1 << SYSTEM_ERROR_BIT) - 1));
+               return strerror(num & ~(1U << SYSTEM_ERROR_BIT));
        return para_errlist[ERRNUM_TO_SS(num)][ERRNUM_TO_INDEX(num)];
 }