Index: aocutils.c ================================================================== --- aocutils.c +++ aocutils.c @@ -1,24 +1,18 @@ -#include +#include #include #include #include "aocutils.h" -struct TextGrid { - unsigned rows, cols; - char *data; // may have '\n' at end of rows -}; - bool TGvalid(struct TextGrid *tg, unsigned row, unsigned col) { if (row >= tg->rows) return false; if (col >= tg->cols) return false; return true; } char *TGcharptr(struct TextGrid *tg, unsigned row, unsigned col) { - if (row >= tg->rows) return NULL; - if (col >= tg->cols) return NULL; - return data + (row * tg->cols) + col; + if (!TGvalid(tg, row, col)) return NULL; + return tg->data + (row * tg->cols) + col; } // TODO: rewrite this shit size_t linearize2d(unsigned width, unsigned row, unsigned col) { return (row * width) + col;