From: Andre Noll Date: Sat, 6 May 2023 14:49:56 +0000 (+0200) Subject: error.h: Be more careful with error code masking. X-Git-Tag: v0.7.3~23^2~1 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=5364bf49a734ba76400d3eb31f42f6a861e64bef error.h: Be more careful with error code masking. It should never happen that two or more of the three special high bits (osl, lopsub, system) are set in an integer that stores a paraslash error value, but gcc-12 can't prove this and complains as follows: error.h:304:28: warning: array subscript 268435456 is above array bounds of 'const char * const[220]' [-Warray-bounds] 304 | return para_errlist[num]; | ~~~~~~~~~~~~^~~~~ Avoid this warning by always clearing all three special bits. --- diff --git a/error.h b/error.h index fe44ff5c..f2c6e15e 100644 --- a/error.h +++ b/error.h @@ -303,18 +303,20 @@ static const char *weak_lls_strerror(int) __attribute__ ((weakref("lls_strerror" */ _static_inline_ const char *para_strerror(int num) { + unsigned idx = num & ~((1U << OSL_ERROR_BIT) | (1U << LLS_ERROR_BIT) + | (1U << SYSTEM_ERROR_BIT)); assert(num > 0); if (IS_OSL_ERROR(num)) { assert(weak_osl_strerror); - return weak_osl_strerror(num & ~(1U << OSL_ERROR_BIT)); + return weak_osl_strerror(idx); } if (IS_LLS_ERROR(num)) { assert(weak_lls_strerror); - return weak_lls_strerror(num & ~(1U << LLS_ERROR_BIT)); + return weak_lls_strerror(idx); } if (IS_SYSTEM_ERROR(num)) - return strerror(num & ~(1U << SYSTEM_ERROR_BIT)); - return para_errlist[num]; + return strerror(idx); + return para_errlist[idx]; } /**