From: Andre Noll Date: Mon, 10 Aug 2015 18:00:49 +0000 (+0200) Subject: Clarify para_strerror(). X-Git-Tag: v0.5.6~91^2~1 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=1fd34762208566dfe2d2e07772e4af088f833a2b;hp=4f18e922663731106fbc64dcc0583a7b017ac407 Clarify para_strerror(). 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. --- diff --git a/error.h b/error.h index 27e9e264..379d3732 100644 --- 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)]; }