From 474ee93e20aa032266d42dbe9c6c43ccdd49ba51 Mon Sep 17 00:00:00 2001 From: hartkopp Date: Fri, 28 Nov 2008 21:50:24 +0000 Subject: [PATCH] Fixed parse_canframe() with reordering the checks for the can_id delimiter. Before this fix the function may have found delimiters in the string behind the terminating zero. git-svn-id: svn://svn.berlios.de//socketcan/trunk@871 030b6a49-0b11-0410-94ab-b0dab22257f2 --- can-utils/lib.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/can-utils/lib.c b/can-utils/lib.c index 7ae308a..0b91488 100644 --- a/can-utils/lib.c +++ b/can-utils/lib.c @@ -114,10 +114,16 @@ int parse_canframe(char *cs, struct can_frame *cf) { if (len < 4) return 1; - if (!((cs[3] == CANID_DELIM) || (cs[8] == CANID_DELIM))) - return 1; + if (cs[3] == CANID_DELIM) { /* 3 digits */ - if (cs[8] == CANID_DELIM) { /* 8 digits */ + idx = 4; + for (i=0; i<3; i++){ + if ((tmp = asc2nibble(cs[i])) > 0x0F) + return 1; + cf->can_id |= (tmp << (2-i)*4); + } + + } else if (cs[8] == CANID_DELIM) { /* 8 digits */ idx = 9; for (i=0; i<8; i++){ @@ -128,15 +134,8 @@ int parse_canframe(char *cs, struct can_frame *cf) { if (!(cf->can_id & CAN_ERR_FLAG)) /* 8 digits but no errorframe? */ cf->can_id |= CAN_EFF_FLAG; /* then it is an extended frame */ - } else { /* 3 digits */ - - idx = 4; - for (i=0; i<3; i++){ - if ((tmp = asc2nibble(cs[i])) > 0x0F) - return 1; - cf->can_id |= (tmp << (2-i)*4); - } - } + } else + return 1; if((cs[idx] == 'R') || (cs[idx] == 'r')){ /* RTR frame */ cf->can_id |= CAN_RTR_FLAG; -- 2.39.2