math/gfreduce.[ch]: Fix out-of-bounds memory access.
[u/mdw/catacomb] / math / gfx-sqr.c
index 8e26f36..ba54da8 100644 (file)
 
 #include "mpx.h"
 #include "gfx.h"
-#include "gfx-sqr-tab.h"
 
 /*----- Static variables --------------------------------------------------*/
 
-static const uint16 tab[256] = GFX_SQRTAB;
+extern const uint16 gfx_sqrtab[256];
 
 /*----- Main code ---------------------------------------------------------*/
 
@@ -82,7 +81,7 @@ void gfx_sqr(mpw *dv, mpw *dvl, const mpw *av, const mpw *avl)
 
     /* --- Do the work in the middle --- */
 
-    aa |= (mpd)(tab[U8(a)]) << bb;
+    aa |= (mpd)(gfx_sqrtab[U8(a)]) << bb;
     bb += 16;
     a >>= 8;
     b -= 8;
@@ -101,7 +100,7 @@ void gfx_sqr(mpw *dv, mpw *dvl, const mpw *av, const mpw *avl)
   /* --- Flush the input buffer --- */
 
   if (b) for (;;) {
-    aa |= (mpd)(tab[U8(a)]) << bb;
+    aa |= (mpd)(gfx_sqrtab[U8(a)]) << bb;
     bb += 16;
     if (bb > MPW_BITS) {
       *dv++ = MPW(aa);