From ed33315f2506d7f75305a84a29785b13033bdeab Mon Sep 17 00:00:00 2001 From: Daniel Pouzzner Date: Mon, 23 Aug 2021 17:23:40 -0500 Subject: [PATCH] wolfcrypt/src/sp_int.c: add pragma to sp_set() to suppress false positive -Warray-bounds on gcc-11. --- wolfcrypt/src/sp_int.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/wolfcrypt/src/sp_int.c b/wolfcrypt/src/sp_int.c index 2ca65ef43..1a0630005 100644 --- a/wolfcrypt/src/sp_int.c +++ b/wolfcrypt/src/sp_int.c @@ -2902,11 +2902,26 @@ int sp_set(sp_int* a, sp_int_digit d) err = MP_VAL; } if (err == MP_OKAY) { +#if defined(__GNUC__) +#if __GNUC__ == 11 + /* gcc-11 falsely reports out-of-bounds array access if the byte array + * backing the sp_int* is smaller than sizeof(sp_int), as occurs when + * WOLFSSL_SP_SMALL. + */ + _Pragma("GCC diagnostic push"); + _Pragma("GCC diagnostic ignored \"-Warray-bounds\""); +#endif +#endif a->dp[0] = d; a->used = d > 0; #ifdef WOLFSSL_SP_INT_NEGATIVE a->sign = MP_ZPOS; #endif +#if defined(__GNUC__) +#if __GNUC__ >= 11 + _Pragma("GCC diagnostic pop"); +#endif +#endif } return err;