universe@674: /* universe@674: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. universe@674: * universe@674: * Copyright 2023 Mike Becker, Olaf Wintermann All rights reserved. universe@674: * universe@674: * Redistribution and use in source and binary forms, with or without universe@674: * modification, are permitted provided that the following conditions are met: universe@674: * universe@674: * 1. Redistributions of source code must retain the above copyright universe@674: * notice, this list of conditions and the following disclaimer. universe@674: * universe@674: * 2. Redistributions in binary form must reproduce the above copyright universe@674: * notice, this list of conditions and the following disclaimer in the universe@674: * documentation and/or other materials provided with the distribution. universe@674: * universe@674: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" universe@674: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE universe@674: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE universe@674: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE universe@674: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR universe@674: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF universe@674: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS universe@674: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN universe@674: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) universe@674: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE universe@674: * POSSIBILITY OF SUCH DAMAGE. universe@674: */ universe@674: universe@674: int cx_szmul_impl( universe@674: size_t a, universe@674: size_t b, universe@674: size_t *result universe@674: ) { universe@674: if (a == 0 || b == 0) { universe@674: *result = 0; universe@674: return 0; universe@674: } universe@674: size_t r = a * b; universe@674: if (r / b == a) { universe@674: *result = r; universe@674: return 0; universe@674: } else { universe@674: *result = 0; universe@674: return 1; universe@674: } olaf@841: }