1 /* fileread.h - Offset checking routines for file reading 2 * 3 * Copyright (C) 1998 Oskar Liljeblad 4 * 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 #ifndef FILEREAD_H 20 #define FILEREAD_H 21 22 #include <stdbool.h> /* POSIX/Gnulib */ 23 #include "common/common.h" 24 25 #define RETURN_IF_BAD_POINTER(r, x) \ 26 if (!check_offset(fi->memory, fi->total_size, fi->name, &(x), sizeof(x))) { \ 27 /*printf("bad_pointer in %s:%d\n", __FILE__, __LINE__);*/ \ 28 return (r); \ 29 } 30 #define RETURN_IF_BAD_OFFSET(r, x, s) \ 31 if (!check_offset(fi->memory, fi->total_size, fi->name, x, s)) { \ 32 /*printf("bad_offset in %s:%d\n", __FILE__, __LINE__);*/ \ 33 return (r); \ 34 } 35 36 bool check_offset(const char *, size_t, const char *, const void *, size_t); 37 38 #endif 39