Skip to content

Commit

Permalink
spi: spidev_test: check error
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Mark Brown <[email protected]>
  • Loading branch information
d4ddi0 authored and broonie committed Nov 23, 2015
1 parent 983b278 commit a20874f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion tools/spi/spidev_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,17 @@ static void hex_dump(const void *src, size_t length, size_t line_size, char *pre
static int unescape(char *_dst, char *_src, size_t len)
{
int ret = 0;
int match;
char *src = _src;
char *dst = _dst;
unsigned int ch;

while (*src) {
if (*src == '\\' && *(src+1) == 'x') {
sscanf(src + 2, "%2x", &ch);
match = sscanf(src + 2, "%2x", &ch);
if (!match)
pabort("malformed input string");

src += 4;
*dst++ = (unsigned char)ch;
} else {
Expand Down

0 comments on commit a20874f

Please sign in to comment.