ireallocarray.c - stagit-gopher - A git gopher frontend. (mirror) Err bitreich.org 70 hgit clone git://bitreich.org/stagit-gopher/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/stagit-gopher/ URL:git://bitreich.org/stagit-gopher/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/stagit-gopher/ bitreich.org 70 1Log /scm/stagit-gopher/log.gph bitreich.org 70 1Files /scm/stagit-gopher/files.gph bitreich.org 70 1Refs /scm/stagit-gopher/refs.gph bitreich.org 70 1Tags /scm/stagit-gopher/tag bitreich.org 70 1README /scm/stagit-gopher/file/README.gph bitreich.org 70 1LICENSE /scm/stagit-gopher/file/LICENSE.gph bitreich.org 70 i--- Err bitreich.org 70 ireallocarray.c (1306B) Err bitreich.org 70 i--- Err bitreich.org 70 i 1 /* Err bitreich.org 70 i 2 * Copyright (c) 2008 Otto Moerbeek Err bitreich.org 70 i 3 * Err bitreich.org 70 i 4 * Permission to use, copy, modify, and distribute this software for any Err bitreich.org 70 i 5 * purpose with or without fee is hereby granted, provided that the above Err bitreich.org 70 i 6 * copyright notice and this permission notice appear in all copies. Err bitreich.org 70 i 7 * Err bitreich.org 70 i 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES Err bitreich.org 70 i 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF Err bitreich.org 70 i 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR Err bitreich.org 70 i 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES Err bitreich.org 70 i 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN Err bitreich.org 70 i 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF Err bitreich.org 70 i 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. Err bitreich.org 70 i 15 */ Err bitreich.org 70 i 16 Err bitreich.org 70 i 17 #include Err bitreich.org 70 i 18 #include Err bitreich.org 70 i 19 #include Err bitreich.org 70 i 20 #include Err bitreich.org 70 i 21 Err bitreich.org 70 i 22 #include "compat.h" Err bitreich.org 70 i 23 Err bitreich.org 70 i 24 /* Err bitreich.org 70 i 25 * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX Err bitreich.org 70 i 26 * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW Err bitreich.org 70 i 27 */ Err bitreich.org 70 i 28 #define MUL_NO_OVERFLOW (1UL << (sizeof(size_t) * 4)) Err bitreich.org 70 i 29 Err bitreich.org 70 i 30 void * Err bitreich.org 70 i 31 reallocarray(void *optr, size_t nmemb, size_t size) Err bitreich.org 70 i 32 { Err bitreich.org 70 i 33 if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) && Err bitreich.org 70 i 34 nmemb > 0 && SIZE_MAX / nmemb < size) { Err bitreich.org 70 i 35 errno = ENOMEM; Err bitreich.org 70 i 36 return NULL; Err bitreich.org 70 i 37 } Err bitreich.org 70 i 38 return realloc(optr, size * nmemb); Err bitreich.org 70 i 39 } Err bitreich.org 70 .