]> rtime.felk.cvut.cz Git - socketcan-devel.git/commitdiff
Fixed parse_canframe() with reordering the checks for the can_id
authorhartkopp <hartkopp@030b6a49-0b11-0410-94ab-b0dab22257f2>
Fri, 28 Nov 2008 21:50:24 +0000 (21:50 +0000)
committerhartkopp <hartkopp@030b6a49-0b11-0410-94ab-b0dab22257f2>
Fri, 28 Nov 2008 21:50:24 +0000 (21:50 +0000)
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

index 7ae308a5a99a5f93b0908cff46853d4b225d246d..0b9148817b1e72d33b45f083d994582cc9a6b57f 100644 (file)
@@ -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;