]> rtime.felk.cvut.cz Git - socketcan-devel.git/commitdiff
Fix datatype issue in sscanf() on 64bit systems.
authorhartkopp <hartkopp@030b6a49-0b11-0410-94ab-b0dab22257f2>
Sat, 25 Sep 2010 10:24:37 +0000 (10:24 +0000)
committerhartkopp <hartkopp@030b6a49-0b11-0410-94ab-b0dab22257f2>
Sat, 25 Sep 2010 10:24:37 +0000 (10:24 +0000)
On 64bit systems a 'long' is a 64bit value but the target values of scanf()
are always 32bit in the affected code - which means just an 'unsigned int'.
Unsigned int is fine on 32 and 64 bit systems.

Thanks to Andre Naujoks for reporting this issue.

git-svn-id: svn://svn.berlios.de//socketcan/trunk@1197 030b6a49-0b11-0410-94ab-b0dab22257f2

can-utils/candump.c
can-utils/cangw.c

index cc81b3f336d820fd2313a7993aaa7382928a4ebd..7aeeef576837fe57275f5e4da54e93b78b07c81c 100644 (file)
@@ -443,23 +443,18 @@ int main(int argc, char **argv)
                                ptr = nptr+1; /* hop behind the ',' */
                                nptr = strchr(ptr, ','); /* update exit condition */
 
-                               if (sscanf(ptr, "%lx:%lx",
-                                          (long unsigned int *)
+                               if (sscanf(ptr, "%x:%x",
                                           &rfilter[numfilter].can_id, 
-                                          (long unsigned int *)
                                           &rfilter[numfilter].can_mask) == 2) {
                                        rfilter[numfilter].can_mask &= ~CAN_ERR_FLAG;
                                        numfilter++;
-                               } else if (sscanf(ptr, "%lx~%lx",
-                                                 (long unsigned int *)
+                               } else if (sscanf(ptr, "%x~%x",
                                                  &rfilter[numfilter].can_id, 
-                                                 (long unsigned int *)
                                                  &rfilter[numfilter].can_mask) == 2) {
                                        rfilter[numfilter].can_id |= CAN_INV_FILTER;
                                        rfilter[numfilter].can_mask &= ~CAN_ERR_FLAG;
                                        numfilter++;
-                               } else if (sscanf(ptr, "#%lx",
-                                                 (long unsigned int *)&err_mask) != 1) { 
+                               } else if (sscanf(ptr, "#%x", &err_mask) != 1) { 
                                        fprintf(stderr, "Error in filter option parsing: '%s'\n", ptr);
                                        return 1;
                                }
index d6e96682f9287b977627f12ffecbd9a8298d3701..fbc230d4599e9a4532b14ac945bf37e0a6f829fa 100644 (file)
@@ -328,8 +328,7 @@ int parse_mod(char *optarg, struct modattr *modmsg)
                ptr++;
        }
 
-       if (sscanf(++ptr, "%lx.%hhx.%16s",
-                  (long unsigned int *)&modmsg->cf.can_id,
+       if (sscanf(++ptr, "%x.%hhx.%16s", &modmsg->cf.can_id,
                   (unsigned char *)&modmsg->cf.can_dlc, hexdata) != 3)
                return 5;
 
@@ -593,13 +592,11 @@ int main(int argc, char **argv)
                        break;
 
                case 'f':
-                       if (sscanf(optarg, "%lx:%lx",
-                                  (long unsigned int *)&filter.can_id, 
-                                  (long unsigned int *)&filter.can_mask) == 2) {
+                       if (sscanf(optarg, "%x:%x", &filter.can_id,
+                                  &filter.can_mask) == 2) {
                                have_filter = 1;
-                       } else if (sscanf(optarg, "%lx~%lx",
-                                         (long unsigned int *)&filter.can_id, 
-                                         (long unsigned int *)&filter.can_mask) == 2) {
+                       } else if (sscanf(optarg, "%x~%x", &filter.can_id,
+                                         &filter.can_mask) == 2) {
                                filter.can_id |= CAN_INV_FILTER;
                                have_filter = 1;
                        } else {