From 8c5bcacdecafd23928a048728a10c5f414d40ea2 Mon Sep 17 00:00:00 2001 From: Loup Vaillant Date: Fri, 4 Jun 2021 23:51:20 +0200 Subject: [PATCH] Fixed local variable shadowing In crypto_x25519_inverse(), line 2949 and 2953, we use the ZERO macro in a context where the enclosing scope already defines the varible `i`. Turns out ZERO defines `i` for internal use in an enclosed scope. This trigger a warning in some compilers about variable shadowing: declaring a local variable with the same name as an enclosing local variable. This warning is especially annoying when combined with -Werror. To prevent this, the macros COPY and ZERO have been modified so they use a variable name that is unlikely to be used anywhere else (`i__`). --- src/monocypher.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/monocypher.c b/src/monocypher.c index 2951003..8aeed41 100644 --- a/src/monocypher.c +++ b/src/monocypher.c @@ -58,8 +58,8 @@ ///////////////// #define FOR_T(type, i, start, end) for (type i = (start); i < (end); i++) #define FOR(i, start, end) FOR_T(size_t, i, start, end) -#define COPY(dst, src, size) FOR(i, 0, size) (dst)[i] = (src)[i] -#define ZERO(buf, size) FOR(i, 0, size) (buf)[i] = 0 +#define COPY(dst, src, size) FOR(i__, 0, size) (dst)[i__] = (src)[i__] +#define ZERO(buf, size) FOR(i__, 0, size) (buf)[i__] = 0 #define WIPE_CTX(ctx) crypto_wipe(ctx , sizeof(*(ctx))) #define WIPE_BUFFER(buffer) crypto_wipe(buffer, sizeof(buffer)) #define MIN(a, b) ((a) <= (b) ? (a) : (b)) -- 2.47.3