File: checked-integer-arithmetic.c

package info (click to toggle)
zathura 0.4.7-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,616 kB
  • sloc: ansic: 13,668; python: 49; xml: 48; perl: 41; makefile: 8
file content (16 lines) | stat: -rw-r--r-- 328 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/* SPDX-License-Identifier: Zlib */

#include "checked-integer-arithmetic.h"
#include <stdint.h>
#include <limits.h>

#ifndef HAVE_BUILTIN
bool
checked_umul(unsigned int lhs, unsigned int rhs, unsigned int* res)
{
  const uint64_t r = (uint64_t) lhs * (uint64_t) rhs;
  *res = (unsigned int) r;

  return r > UINT_MAX;
}
#endif