progs: Fix a number of format-related errors.
[u/mdw/catacomb] / symm / square.c
index 490b917..73b22bb 100644 (file)
@@ -36,7 +36,6 @@
 #include "gcipher.h"
 #include "paranoia.h"
 #include "square.h"
-#include "square-tab.h"
 
 /*----- Global variables --------------------------------------------------*/
 
@@ -44,10 +43,17 @@ const octet square_keysz[] = { KSZ_RANGE, SQUARE_KEYSZ, 4, 16, 4 };
 
 /*----- Constant tables ---------------------------------------------------*/
 
-static const octet S[256] = SQUARE_S, SI[256] = SQUARE_SI;
-static const uint32 T[4][256] = SQUARE_T, TI[4][256] = SQUARE_TI;
-static const uint32 U[4][256] = SQUARE_U;
-static const octet rcon[] = SQUARE_RCON;
+extern const octet square_s[256], square_si[256];
+extern const uint32 square_t[4][256], square_ti[4][256];
+extern const uint32 square_u[4][256];
+extern const octet square_rcon[32];
+
+#define S square_s
+#define SI square_si
+#define T square_t
+#define TI square_ti
+#define U square_u
+#define RCON square_rcon
 
 /*----- Main code ---------------------------------------------------------*/
 
@@ -86,11 +92,27 @@ void square_init(square_ctx *k, const void *buf, size_t sz)
   }
   nr = 8;
 
+  /* --- GCC complains about an out-of-bounds subscript here --- *
+   *
+   * This is impossible.  Thanks to @KSZ_ASSERT@, we know that @sz <= 16@ and
+   * hence @i <= nk <= 4@; but @SQUARE_KWORDS == 36@.
+   */
+
+#if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
+#  pragma GCC diagnostic push
+#  pragma GCC diagnostic ignored "-Warray-bounds"
+#endif
+
+  ww = kk[i - 1];
+
+#if __GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
+#  pragma GCC diagnostic pop
+#endif
+
   /* --- Expand this material to fill the rest of the table --- */
 
   nw = (nr + 1) * 4;
-  ww = kk[i - 1];
-  p = rcon;
+  p = RCON;
   for (; i < nw; i++) {
     uint32 w = kk[i - nk];
     if (i % nk == 0) {