summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2018-12-13 15:13:06 +0100
committerBastien Nocera <hadess@hadess.net>2018-12-13 15:48:25 +0100
commit8a3a974ea3d21543173b33f25d8a12040482efec (patch)
tree825428cb6c5e85793824cd54bd8061f49ab3c27e
parentdb607c4a6f510d6984daac2cb71fb0f248ea60f2 (diff)
lib: Add helper for NBIS copy-paste library
This will allow us to segragate helper functions that we want to use within NBIS. The first helper will be a macro checking for overflow in multiplications.
-rw-r--r--doc/meson.build1
-rw-r--r--libfprint/fp_internal.h1
-rw-r--r--libfprint/meson.build1
-rw-r--r--libfprint/nbis-helpers.h33
4 files changed, 36 insertions, 0 deletions
diff --git a/doc/meson.build b/doc/meson.build
index 8324708..37d515d 100644
--- a/doc/meson.build
+++ b/doc/meson.build
@@ -6,6 +6,7 @@ private_headers = [
'aeslib.h',
'assembling.h',
'fp_internal.h',
+ 'nbis-helpers.h',
'fpi-async.h',
'fpi-data.h',
diff --git a/libfprint/fp_internal.h b/libfprint/fp_internal.h
index d985738..5c89e18 100644
--- a/libfprint/fp_internal.h
+++ b/libfprint/fp_internal.h
@@ -27,6 +27,7 @@
#include <glib.h>
#include <libusb.h>
+#include "nbis-helpers.h"
#include "fprint.h"
#include "fpi-dev.h"
#include "fpi-core.h"
diff --git a/libfprint/meson.build b/libfprint/meson.build
index ce761ba..abd0005 100644
--- a/libfprint/meson.build
+++ b/libfprint/meson.build
@@ -1,5 +1,6 @@
libfprint_sources = [
'fp_internal.h',
+ 'nbis-helpers.h',
'drivers_api.h',
'fpi-async.c',
'fpi-async.h',
diff --git a/libfprint/nbis-helpers.h b/libfprint/nbis-helpers.h
new file mode 100644
index 0000000..eab861e
--- /dev/null
+++ b/libfprint/nbis-helpers.h
@@ -0,0 +1,33 @@
+/*
+ * Helpers to use within the NBIS copy/paste library
+ * Copyright (C) 2018 Bastien Nocera <hadess@hadess.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <glib.h>
+
+#define ASSERT_SIZE_MUL(a,b) \
+ { \
+ gsize dest; \
+ g_assert(g_size_checked_mul(&dest, a, b)); \
+ }
+
+#define ASSERT_INT_MUL(a, b) \
+ { \
+ gsize dest; \
+ g_assert(g_size_checked_mul(&dest, a, b)); \
+ g_assert(dest < G_MAXINT); \
+ }