From 659d8346beb4a0506d5c2f20c918a57804b4f591 Mon Sep 17 00:00:00 2001
From: Daniel Drake <dsd@cs.manchester.ac.uk>
Date: Thu, 27 Dec 2007 00:46:11 +0000
Subject: [PATCH] Compiler flags update

Dropped -Wextra as it is not that useful.
Set compiler flags to be more like the kernel's.
Set std=gnu99
Fixed some warnings.
---
 TODO                       |  4 ++++
 configure.ac               |  2 +-
 libfprint/aeslib.c         |  9 ++++-----
 libfprint/aeslib.h         |  4 ++--
 libfprint/core.c           | 10 +++++-----
 libfprint/data.c           |  8 ++++----
 libfprint/drivers/upektc.c |  7 +++----
 libfprint/img.c            |  2 +-
 8 files changed, 24 insertions(+), 22 deletions(-)

diff --git a/TODO b/TODO
index 66723a7..5d1034d 100644
--- a/TODO
+++ b/TODO
@@ -24,3 +24,7 @@ aes4000 resampling
 PPMM parameter to get_minutiae seems to have no effect
 nbis minutiae should be stored in endian-independent format
 
+PORTABILITY
+===========
+OpenBSD can't do -Wshadow or visibility
+OpenBSD: add compat codes for ENOTSUP ENODATA and EPROTO
diff --git a/configure.ac b/configure.ac
index 72618ee..fb128cd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -91,7 +91,7 @@ fi
 
 
 AC_DEFINE([API_EXPORTED], [__attribute__((visibility("default")))], [Default visibility])
-AM_CFLAGS="-Werror-implicit-function-declaration -Wimplicit-int -Wunreachable-code -Wunused-function -Wunused-label -Wunused-value -Wunused-variable -Wnonnull -Wreturn-type -Wextra -Wshadow"
+AM_CFLAGS="-std=gnu99 -fgnu89-inline -Wall -Wundef -Wunused -Wstrict-prototypes -Werror-implicit-function-declaration -Wno-pointer-sign -Wshadow"
 AC_SUBST(AM_CFLAGS)
 
 AC_CONFIG_FILES([libfprint.pc] [Makefile] [libfprint/Makefile] [examples/Makefile] [doc/Makefile])
diff --git a/libfprint/aeslib.c b/libfprint/aeslib.c
index aa8571e..f6d8dfb 100644
--- a/libfprint/aeslib.c
+++ b/libfprint/aeslib.c
@@ -32,8 +32,8 @@
 #define EP_IN			(1 | USB_ENDPOINT_IN)
 #define EP_OUT			(2 | USB_ENDPOINT_OUT)
 
-static int do_write_regv(struct fp_img_dev *dev, struct aes_regwrite *regs,
-	unsigned int num)
+static int do_write_regv(struct fp_img_dev *dev,
+	const struct aes_regwrite *regs, unsigned int num)
 {
 	size_t alloc_size = num * 2;
 	unsigned char *data = g_malloc(alloc_size);
@@ -59,7 +59,7 @@ static int do_write_regv(struct fp_img_dev *dev, struct aes_regwrite *regs,
 	return 0;
 }
 
-int aes_write_regv(struct fp_img_dev *dev, struct aes_regwrite *regs,
+int aes_write_regv(struct fp_img_dev *dev, const struct aes_regwrite *regs,
 	unsigned int num)
 {
 	unsigned int i;
@@ -93,10 +93,9 @@ int aes_write_regv(struct fp_img_dev *dev, struct aes_regwrite *regs,
 	return 0;
 }
 
-int aes_assemble_image(unsigned char *input, size_t width, size_t height,
+void aes_assemble_image(unsigned char *input, size_t width, size_t height,
 	unsigned char *output)
 {
-	size_t frame_size = width * height;
 	size_t row, column;
 
 	for (column = 0; column < width; column++) {
diff --git a/libfprint/aeslib.h b/libfprint/aeslib.h
index c02f507..792c6d4 100644
--- a/libfprint/aeslib.h
+++ b/libfprint/aeslib.h
@@ -27,10 +27,10 @@ struct aes_regwrite {
 	unsigned char value;
 };
 
-int aes_write_regv(struct fp_img_dev *dev, struct aes_regwrite *regs,
+int aes_write_regv(struct fp_img_dev *dev, const struct aes_regwrite *regs,
 	unsigned int num);
 
-int aes_assemble_image(unsigned char *input, size_t width, size_t height,
+void aes_assemble_image(unsigned char *input, size_t width, size_t height,
 	unsigned char *output);
 
 #endif
diff --git a/libfprint/core.c b/libfprint/core.c
index 1a5a146..47a4e2d 100644
--- a/libfprint/core.c
+++ b/libfprint/core.c
@@ -367,7 +367,7 @@ static struct fp_driver *find_supporting_driver(struct usb_device *udev,
 				*usb_id = id;
 				return drv;
 			}
-	} while (elem = g_slist_next(elem));
+	} while ((elem = g_slist_next(elem)));
 	return NULL;
 }
 
@@ -439,7 +439,7 @@ API_EXPORTED struct fp_dscv_dev **fp_discover_devs(void)
 		int i = 0;
 		do {
 			list[i++] = elem->data;
-		} while (elem = g_slist_next(elem));
+		} while ((elem = g_slist_next(elem)));
 	}
 	list[dscv_count] = NULL; /* NULL-terminate */
 
@@ -541,7 +541,7 @@ API_EXPORTED struct fp_dscv_dev *fp_dscv_dev_for_print_data(struct fp_dscv_dev *
 	struct fp_dscv_dev *ddev;
 	int i;
 
-	for (i = 0; ddev = devs[i]; i++)
+	for (i = 0; (ddev = devs[i]); i++)
 		if (fp_dscv_dev_supports_print_data(ddev, data))
 			return ddev;
 	return NULL;
@@ -561,7 +561,7 @@ API_EXPORTED struct fp_dscv_dev *fp_dscv_dev_for_dscv_print(struct fp_dscv_dev *
 	struct fp_dscv_dev *ddev;
 	int i;
 
-	for (i = 0; ddev = devs[i]; i++)
+	for (i = 0; (ddev = devs[i]); i++)
 		if (fp_dscv_dev_supports_dscv_print(ddev, print))
 			return ddev;
 	return NULL;
@@ -1138,7 +1138,7 @@ API_EXPORTED void fp_exit(void)
 		do {
 			fp_dbg("naughty app left a device open on exit!");
 			do_close((struct fp_dev *) elem->data);
-		} while (elem = g_slist_next(elem));
+		} while ((elem = g_slist_next(elem)));
 		g_slist_free(opened_devices);
 		opened_devices = NULL;
 	}
diff --git a/libfprint/data.c b/libfprint/data.c
index c36f94d..2027e9c 100644
--- a/libfprint/data.c
+++ b/libfprint/data.c
@@ -477,7 +477,7 @@ static GSList *scan_dev_store_dir(char *devpath, uint16_t driver_id,
 		return list;
 	}
 
-	while (ent = g_dir_read_name(dir)) {
+	while ((ent = g_dir_read_name(dir))) {
 		/* ent is an 1 hex character fp_finger code */
 		guint64 val;
 		enum fp_finger finger;
@@ -518,7 +518,7 @@ static GSList *scan_driver_store_dir(char *drvpath, uint16_t driver_id,
 		return list;
 	}
 
-	while (ent = g_dir_read_name(dir)) {
+	while ((ent = g_dir_read_name(dir))) {
 		/* ent is an 8 hex character devtype */
 		guint64 val;
 		uint32_t devtype;
@@ -571,7 +571,7 @@ API_EXPORTED struct fp_dscv_print **fp_discover_prints(void)
 		return NULL;
 	}
 
-	while (ent = g_dir_read_name(dir)) {
+	while ((ent = g_dir_read_name(dir))) {
 		/* ent is a 4 hex digit driver_id */
 		gchar *endptr;
 		gchar *path;
@@ -620,7 +620,7 @@ API_EXPORTED void fp_dscv_prints_free(struct fp_dscv_print **prints)
 	if (!prints)
 		return;
 
-	for (i = 0; print = prints[i]; i++) {
+	for (i = 0; (print = prints[i]); i++) {
 		if (print)
 			g_free(print->path);
 		g_free(print);
diff --git a/libfprint/drivers/upektc.c b/libfprint/drivers/upektc.c
index 92aeffa..16df00a 100644
--- a/libfprint/drivers/upektc.c
+++ b/libfprint/drivers/upektc.c
@@ -36,7 +36,7 @@ typedef int sint32;
 typedef unsigned int uint32;
 
 /** scan command */
-static const sint8 anScanCommand[ 0x40 ] = {
+static const unsigned char anScanCommand[ 0x40 ] = {
 	0x0e, 0x00, 0x03, 0xa8, 0x00, 0xb6, 0xbb, 0xbb,
 	0xb8, 0xb7, 0xb8, 0xb5, 0xb8, 0xb9, 0xb8, 0xb9,
 	0xbb, 0xbb, 0xbe, 0xbb, 0x4e, 0x16, 0xf4, 0x77,
@@ -48,7 +48,7 @@ static const sint8 anScanCommand[ 0x40 ] = {
 };
 
 /** init command */
-static const sint8 anInitCommand[ 0x40 ] = {
+static const unsigned char anInitCommand[ 0x40 ] = {
 	0x03, 0x00, 0x00, 0x00, 0x02, 0xfb, 0x0f, 0x00,
 	0xc4, 0xf9, 0x2f, 0x01, 0x6d, 0x4f, 0x01, 0x10,
 	0x44, 0xf9, 0x2f, 0x01, 0x40, 0x00, 0x00, 0x00,
@@ -67,7 +67,7 @@ static const sint8 anInitCommand[ 0x40 ] = {
  * \param pnBuffer buffer pointer we want to store the read buffer
  * \return error code
  */
-static sint32 askScanner( struct fp_img_dev *dev, sint8 *pnRawString, sint32 nLen, sint8 *pnBuffer ) {
+static sint32 askScanner( struct fp_img_dev *dev, const unsigned char *pnRawString, sint32 nLen, sint8 *pnBuffer ) {
     sint8 anBuf[ 65535 ];
 	sint32 nRet;
 
@@ -357,7 +357,6 @@ static int capture( struct fp_img_dev *dev, gboolean unconditional, struct fp_im
 		nRet = -1;
 	}
 
-end:
 	g_free( pnData );
 
 	return nRet;
diff --git a/libfprint/img.c b/libfprint/img.c
index 80fd6e4..da831d5 100644
--- a/libfprint/img.c
+++ b/libfprint/img.c
@@ -372,7 +372,7 @@ int fpi_img_compare_print_data_to_gallery(struct fp_print_data *print,
 	int probe_len = bozorth_probe_init(pstruct);
 	size_t i = 0;
 
-	while (gallery_print = gallery[i++]) {
+	while ((gallery_print = gallery[i++])) {
 		struct xyt_struct *gstruct = (struct xyt_struct *) gallery_print->data;
 		int r = bozorth_to_gallery(probe_len, pstruct, gstruct);
 		if (r >= match_threshold) {