diff options
author | Joshua Clayton <stillcompiling@gmail.com> | 2015-11-18 17:30:41 -0500 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2015-11-23 09:54:01 -0500 |
commit | a20874f78be633b9e3a505d5f191735188b110a5 (patch) | |
tree | fd20e39027a9f7526e23f2d767ecdeab8e6eeb87 /tools/spi | |
parent | 983b27886a3c7f6eff4e987ddba932da74703f4e (diff) |
spi: spidev_test: check error
Check the result of sscanf to verify a result was found.
report and error and abort if pattern was not found.
Signed-off-by: Joshua Clayton <stillcompiling@gmail.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'tools/spi')
-rw-r--r-- | tools/spi/spidev_test.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/tools/spi/spidev_test.c b/tools/spi/spidev_test.c index 02fc3a44901b..322370dbc770 100644 --- a/tools/spi/spidev_test.c +++ b/tools/spi/spidev_test.c | |||
@@ -86,13 +86,17 @@ static void hex_dump(const void *src, size_t length, size_t line_size, char *pre | |||
86 | static int unescape(char *_dst, char *_src, size_t len) | 86 | static int unescape(char *_dst, char *_src, size_t len) |
87 | { | 87 | { |
88 | int ret = 0; | 88 | int ret = 0; |
89 | int match; | ||
89 | char *src = _src; | 90 | char *src = _src; |
90 | char *dst = _dst; | 91 | char *dst = _dst; |
91 | unsigned int ch; | 92 | unsigned int ch; |
92 | 93 | ||
93 | while (*src) { | 94 | while (*src) { |
94 | if (*src == '\\' && *(src+1) == 'x') { | 95 | if (*src == '\\' && *(src+1) == 'x') { |
95 | sscanf(src + 2, "%2x", &ch); | 96 | match = sscanf(src + 2, "%2x", &ch); |
97 | if (!match) | ||
98 | pabort("malformed input string"); | ||
99 | |||
96 | src += 4; | 100 | src += 4; |
97 | *dst++ = (unsigned char)ch; | 101 | *dst++ = (unsigned char)ch; |
98 | } else { | 102 | } else { |