src/ucx.c

Sun, 21 Jan 2018 14:10:59 +0100

author
Mike Becker <universe@uap-core.de>
date
Sun, 21 Jan 2018 14:10:59 +0100
changeset 273
9c1591b3c4a4
parent 270
3d80d425543b
child 331
3b985a4eb05b
permissions
-rw-r--r--

fixes return value for multiplication with zero in ucx_szmul

universe@114 1 /**
universe@114 2 * @mainpage UAP Common Extensions
universe@114 3 * Library with common and useful functions, macros and data structures.
universe@114 4 * <p>
universe@259 5 * Latest available source:<br>
universe@259 6 * <a href="https://sourceforge.net/projects/ucx/files/">
universe@259 7 * https://sourceforge.net/projects/ucx/files/</a>
universe@259 8 * </p>
universe@259 9 *
universe@259 10 * <p>
universe@259 11 * Repositories:<br>
universe@263 12 * <a href="https://sourceforge.net/p/ucx/code">
universe@263 13 * https://sourceforge.net/p/ucx/code</a>
universe@259 14 * -&nbsp;or&nbsp;-
universe@114 15 * <a href="https://develop.uap-core.de/hg/ucx">
universe@114 16 * https://develop.uap-core.de/hg/ucx</a>
universe@114 17 * </p>
universe@114 18 *
universe@114 19 * <h2>LICENCE</h2>
universe@114 20 *
universe@259 21 * Copyright 2017 Mike Becker, Olaf Wintermann All rights reserved.
universe@114 22 *
universe@114 23 * Redistribution and use in source and binary forms, with or without
universe@114 24 * modification, are permitted provided that the following conditions are met:
universe@114 25 *
universe@114 26 * 1. Redistributions of source code must retain the above copyright
universe@114 27 * notice, this list of conditions and the following disclaimer.
universe@114 28 *
universe@114 29 * 2. Redistributions in binary form must reproduce the above copyright
universe@114 30 * notice, this list of conditions and the following disclaimer in the
universe@114 31 * documentation and/or other materials provided with the distribution.
universe@114 32 *
universe@114 33 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
universe@114 34 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
universe@114 35 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
universe@114 36 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
universe@114 37 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
universe@114 38 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
universe@114 39 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
universe@114 40 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
universe@114 41 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
universe@114 42 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
universe@114 43 * POSSIBILITY OF SUCH DAMAGE.
universe@114 44 */
universe@114 45
universe@251 46 #include "ucx/ucx.h"
olaf@270 47
olaf@270 48 #ifndef UCX_MUL_BUILTIN
olaf@270 49 int ucx_szmul(size_t a, size_t b, size_t *result) {
olaf@270 50 if(a == 0 || b == 0) {
olaf@270 51 *result = 0;
universe@273 52 return 0;
olaf@270 53 }
olaf@270 54 size_t r = a * b;
olaf@270 55 if(r / b == a) {
olaf@270 56 *result = r;
olaf@270 57 return 0;
olaf@270 58 } else {
olaf@270 59 *result = 0;
olaf@270 60 return 1;
olaf@270 61 }
olaf@270 62 }
olaf@270 63 #endif
universe@273 64

mercurial