]> git.ipfire.org Git - thirdparty/wireguard-tools.git/commitdiff
c: specify static array size in function params
authorJason A. Donenfeld <Jason@zx2c4.com>
Wed, 27 Jul 2016 09:30:05 +0000 (11:30 +0200)
committerJason A. Donenfeld <Jason@zx2c4.com>
Tue, 2 Aug 2016 00:55:42 +0000 (02:55 +0200)
The C standard states:

  A declaration of a parameter as ``array of type'' shall be adjusted to ``qualified pointer to
  type'', where the type qualifiers (if any) are those specified within the [ and ] of the
  array type derivation. If the keyword static also appears within the [ and ] of the
  array type derivation, then for each call to the function, the value of the corresponding
  actual argument shall provide access to the first element of an array with at least as many
  elements as specified by the size expression.

By changing void func(int array[4]) to void func(int array[static 4]),
we automatically get the compiler checking argument sizes for us, which
is quite nice.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
src/config.c
src/curve25519.c
src/curve25519.h
src/show.c

index 611207e1f7863c8b2be839b911035f2af9b8dd76..55a8ab5b245f98e81c4637734d00ee6ae6851b17 100644 (file)
@@ -90,7 +90,7 @@ static inline uint16_t parse_port(const char *value)
        return port;
 }
 
-static inline bool parse_key(uint8_t key[WG_KEY_LEN], const char *value)
+static inline bool parse_key(uint8_t key[static WG_KEY_LEN], const char *value)
 {
        uint8_t tmp[WG_KEY_LEN + 1];
        if (strlen(value) != b64_len(WG_KEY_LEN) - 1 || b64_pton(value, tmp, WG_KEY_LEN + 1) != WG_KEY_LEN) {
index 6c2653587d27742bb87cdc38bf70c373aad38b2a..3d0b615b0a8e3ad13d0e2abcaa895d63e762b4c2 100644 (file)
@@ -337,7 +337,7 @@ static void fmonty(limb *x2, limb *z2, /* output 2Q */
  * This function performs the swap without leaking any side-channel
  * information.
  */
-static void swap_conditional(limb a[5], limb b[5], limb iswap)
+static void swap_conditional(limb a[static 5], limb b[static 5], limb iswap)
 {
        unsigned i;
        const limb swap = -iswap;
@@ -430,7 +430,7 @@ static void crecip(felem out, const felem z)
        /* 2^255 - 21 */ fmul(out, t0, a);
 }
 
-void curve25519(uint8_t mypublic[CURVE25519_POINT_SIZE], const uint8_t secret[CURVE25519_POINT_SIZE], const uint8_t basepoint[CURVE25519_POINT_SIZE])
+void curve25519(uint8_t mypublic[static CURVE25519_POINT_SIZE], const uint8_t secret[static CURVE25519_POINT_SIZE], const uint8_t basepoint[static CURVE25519_POINT_SIZE])
 {
        limb bp[5], x[5], z[5], zmone[5];
        uint8_t e[32];
@@ -1104,7 +1104,7 @@ static void fmonty(limb *x2, limb *z2,  /* output 2Q */
  * reduced-degree form: the values in a[10..19] or b[10..19] aren't swapped,
  * and all all values in a[0..9],b[0..9] must have magnitude less than
  * INT32_MAX. */
-static void swap_conditional(limb a[19], limb b[19], limb iswap)
+static void swap_conditional(limb a[static 19], limb b[static 19], limb iswap)
 {
        unsigned i;
        const int32_t swap = (int32_t) -iswap;
@@ -1235,7 +1235,7 @@ static void crecip(limb *out, const limb *z)
        /* 2^255 - 21 */ fmul(out,t1,z11);
 }
 
-void curve25519(uint8_t mypublic[CURVE25519_POINT_SIZE], const uint8_t secret[CURVE25519_POINT_SIZE], const uint8_t basepoint[CURVE25519_POINT_SIZE])
+void curve25519(uint8_t mypublic[static CURVE25519_POINT_SIZE], const uint8_t secret[static CURVE25519_POINT_SIZE], const uint8_t basepoint[static CURVE25519_POINT_SIZE])
 {
        limb bp[10], x[10], z[11], zmone[10];
        uint8_t e[32];
@@ -1251,7 +1251,7 @@ void curve25519(uint8_t mypublic[CURVE25519_POINT_SIZE], const uint8_t secret[CU
 }
 #endif
 
-void curve25519_generate_public(uint8_t *pub, const uint8_t *secret)
+void curve25519_generate_public(uint8_t pub[static CURVE25519_POINT_SIZE], const uint8_t secret[static CURVE25519_POINT_SIZE])
 {
        static const uint8_t basepoint[CURVE25519_POINT_SIZE] = { 9 };
        curve25519(pub, secret, basepoint);
index 3c1404ac14f7531fd6ecd8ec425e7f2aef3051dd..0be59b78554dd417b1567847fb824690d4b6d093 100644 (file)
@@ -10,9 +10,9 @@ enum curve25519_lengths {
        CURVE25519_POINT_SIZE = 32,
 };
 
-void curve25519(uint8_t *mypublic, const uint8_t *secret, const uint8_t *basepoint);
-void curve25519_generate_public(uint8_t *pub, const uint8_t *secret);
-static inline void curve25519_normalize_secret(uint8_t secret[CURVE25519_POINT_SIZE])
+void curve25519(uint8_t mypublic[static CURVE25519_POINT_SIZE], const uint8_t secret[static CURVE25519_POINT_SIZE], const uint8_t basepoint[static CURVE25519_POINT_SIZE]);
+void curve25519_generate_public(uint8_t pub[static CURVE25519_POINT_SIZE], const uint8_t secret[static CURVE25519_POINT_SIZE]);
+static inline void curve25519_normalize_secret(uint8_t secret[static CURVE25519_POINT_SIZE])
 {
        secret[0] &= 248;
        secret[31] &= 127;
index ddda6c3fdf0bc78ced1d2cec3c56f7a049821c6c..3a32cb82f275e54ca65ef2b30238215b4138aed9 100644 (file)
@@ -78,7 +78,7 @@ static void sort_peers(struct wgdevice *device)
 
 static const uint8_t zero[WG_KEY_LEN] = { 0 };
 
-static char *key(const unsigned char key[WG_KEY_LEN])
+static char *key(const unsigned char key[static WG_KEY_LEN])
 {
        static char b64[b64_len(WG_KEY_LEN)];
        if (!memcmp(key, zero, WG_KEY_LEN))