From: Bastien Nocera <hadess@hadess.net>
To: linux-bluetooth@vger.kernel.org
Cc: Bastien Nocera <hadess@hadess.net>
Subject: [PATCH 4/8] tools/csr_usb: Fix compilation failure
Date: Thu, 9 May 2019 14:37:42 +0200 [thread overview]
Message-ID: <20190509123746.8396-4-hadess@hadess.net> (raw)
In-Reply-To: <20190509123746.8396-1-hadess@hadess.net>
GCC's "format-nonliteral" security check is enabled as an error in
recent versions of Fedora. Given the limited formats, pass a boolean
to switch between the 2 different formats.
tools/csr_usb.c: In function 'read_value':
tools/csr_usb.c:82:2: error: format not a string literal, argument types not checked [-Werror=format-nonliteral]
n = fscanf(file, format, &value);
^
---
tools/csr_usb.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/tools/csr_usb.c b/tools/csr_usb.c
index f3ab2ddce..32fdf1f14 100644
--- a/tools/csr_usb.c
+++ b/tools/csr_usb.c
@@ -32,6 +32,7 @@
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <string.h>
#include <dirent.h>
#include <limits.h>
@@ -68,7 +69,7 @@ struct usbfs_bulktransfer {
#define USBFS_IOCTL_CLAIMINTF _IOR('U', 15, unsigned int)
#define USBFS_IOCTL_RELEASEINTF _IOR('U', 16, unsigned int)
-static int read_value(const char *name, const char *attr, const char *format)
+static int read_value(const char *name, const char *attr, bool hex_number)
{
char path[PATH_MAX];
FILE *file;
@@ -80,7 +81,7 @@ static int read_value(const char *name, const char *attr, const char *format)
if (!file)
return -1;
- n = fscanf(file, format, &value);
+ n = fscanf(file, hex_number ? "%d" : "%04x", &value);
if (n != 1) {
fclose(file);
return -1;
@@ -90,26 +91,29 @@ static int read_value(const char *name, const char *attr, const char *format)
return value;
}
+#define read_hex_value(name, file) read_value((name), (file), true)
+#define read_num_value(name, file) read_value((name), (file), false)
+
static char *check_device(const char *name)
{
char path[PATH_MAX];
int busnum, devnum, vendor, product;
- busnum = read_value(name, "busnum", "%d");
+ busnum = read_num_value(name, "busnum");
if (busnum < 0)
return NULL;
- devnum = read_value(name, "devnum", "%d");
+ devnum = read_num_value(name, "devnum");
if (devnum < 0)
return NULL;
snprintf(path, sizeof(path), "/dev/bus/usb/%03u/%03u", busnum, devnum);
- vendor = read_value(name, "idVendor", "%04x");
+ vendor = read_hex_value(name, "idVendor");
if (vendor < 0)
return NULL;
- product = read_value(name, "idProduct", "%04x");
+ product = read_hex_value(name, "idProduct");
if (product < 0)
return NULL;
--
2.21.0
next prev parent reply other threads:[~2019-05-09 12:37 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-09 12:37 [PATCH 1/8] build: Add a few default configure options Bastien Nocera
2019-05-09 12:37 ` [PATCH 2/8] build: Add warnings for non-literal strings Bastien Nocera
2019-05-09 12:37 ` [PATCH 3/8] build: Enable BIND_NOW Bastien Nocera
2019-05-09 12:37 ` Bastien Nocera [this message]
2019-05-09 12:37 ` [PATCH 5/8] obex: Work-around compilation failure Bastien Nocera
2019-05-09 12:37 ` [PATCH 6/8] android/avrcp-lib: Fix unaligned struct access Bastien Nocera
2019-05-09 12:37 ` [PATCH 7/8] android/hal-bluetooth: " Bastien Nocera
2019-05-09 12:37 ` [PATCH 8/8] android/handsfree: " Bastien Nocera
2019-05-13 17:38 ` [PATCH 1/8] build: Add a few default configure options Luiz Augusto von Dentz
2019-05-13 18:13 ` Bastien Nocera
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190509123746.8396-4-hadess@hadess.net \
--to=hadess@hadess.net \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).