]> git.codecow.com Git - Monocypher.git/commitdiff
Fixed local variable shadowing
authorLoup Vaillant <loup@loup-vaillant.fr>
Fri, 4 Jun 2021 21:51:20 +0000 (23:51 +0200)
committerLoup Vaillant <loup@loup-vaillant.fr>
Fri, 4 Jun 2021 21:51:20 +0000 (23:51 +0200)
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

index 29510039103bf497d381c4939b8b3b409d25ed17..8aeed41cd7c1268d026907c272f60b5b4650ad73 100644 (file)
@@ -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))