summaryrefslogtreecommitdiff
path: root/support/dktools/dk4masz.c
blob: 9c304cac6852d5e0d7b3106e2e0258184b035bdf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
Copyright (C) 2015-2020, Dirk Krause
SPDX-License-Identifier: BSD-3-Clause
*/

/*
	WARNING: This file was generated by the dkct program (see
	http://dktools.sourceforge.net/ for details).
	Changes you make here will be lost if dkct is run again!
	You should modify the original source and run dkct on it.
	Original source: dk4masz.ctr
*/

/**	@file dk4masz.c The dk4masz module.
*/


#line 67 "dk4masz.ctr"

#include "dk4conf.h"
#include "dk4types.h"

#if DK4_HAVE_LIMITS_H
#ifndef LIMITS_H_INCLUDED
#include <limits.h>
#define LIMITS_H_INCLUDED 1
#endif
#endif
#if DK4_HAVE_STDINT_H
#ifndef STDINT_H_INCLUDED
#if defined(__cplusplus) && (!defined(__STDC_LIMIT_MACROS))
#define __STDC_LIMIT_MACROS 1
#endif
#if defined(__cplusplus) && (!defined(__STDC_CONSTANT_MACROS))
#define __STDC_CONSTANT_MACROS 1
#endif
#include <stdint.h>
#define STDINT_H_INCLUDED 1
#endif
#endif

#include "dk4error.h"
#include "dk4masz.h"
#include "dk4error.h"
#include "dk4numco.h"



size_t
dk4ma_size_t_add(size_t a, size_t b, dk4_er_t *erp)
{
  if ((SIZE_MAX - b) < a) {
    dk4error_set_simple_error_code(erp, DK4_E_MATH_OVERFLOW);
  }
  return (a + b);
}



size_t
dk4ma_size_t_mul(size_t a, size_t b, dk4_er_t *erp)
{
  if ((0 < a) && (0 < b)) {
    if ((SIZE_MAX / a) < b) {
      dk4error_set_simple_error_code(erp, DK4_E_MATH_OVERFLOW);
    }
  }
  return (a * b);
}