safe.c revision 0d63efe476bd07c8ea9a98dc8c9da7b4b114b701
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * Copyright (C) 2013 Internet Systems Consortium, Inc. ("ISC")
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * Permission to use, copy, modify, and/or distribute this software for any
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * purpose with or without fee is hereby granted, provided that the above
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * copyright notice and this permission notice appear in all copies.
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews * PERFORMANCE OF THIS SOFTWARE.
19d1b1667d073850d4366352aaf8319efc5debeeBrian Wellingtonisc_safe_memequal(const void *s1, const void *s2, size_t n) {
09f22ac5b09e70bc526015f37168ba33e21ea91fDavid Lawrence if (n != 0U) {
b54630c4518a1a173fee3478f4bf51dff450b6dcMark Andrews } while (--n != 0U);
78da321b437bbb690ef570ccf17dcc8583a5a4a0Mark Andrewsisc_safe_memcompare(const void *b1, const void *b2, size_t len) {
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff for (i = 0; i < len; i++) {
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff /* lt is -1 if p1[i] < p2[i]; else 0. */
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff /* gt is -1 if p1[i] > p2[i]; else 0. */
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff /* cmp is 1 if p1[i] > p2[i]; -1 if p1[i] < p2[i]; else 0. */
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff /* set res = cmp if !done. */
ca9739800f045cd4d39014f98b920d4354b5bd14Michael Graff /* set done if p1[i] != p2[i]. */