Skip to content

Commit e6e3253

Browse files
committed
asc2log: shrink string buffer for CAN identifier
Since using the %n feature the tmp1 buffer is only used for the handling of the CAN identifier. So this buffer can be shrinked for that use case. Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
1 parent 6d69bef commit e6e3253

1 file changed

Lines changed: 34 additions & 34 deletions

File tree

asc2log.c

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -151,20 +151,20 @@ static void eval_can(char* buf, struct timeval *date_tvp, char timestamps,
151151
int dlc = 0;
152152
int len = 0;
153153
int data[8];
154-
char tmp1[BUFLEN];
154+
char idstr[21];
155155
char dir[5]; /* 'Rx'/'Tx'/'TxRq' plus terminating zero */
156156
char *extra_info;
157157
int i, items;
158158
unsigned long long sec, usec;
159159

160160
/* check for ErrorFrames */
161-
if (sscanf(buf, "%llu.%llu %d %s",
161+
if (sscanf(buf, "%llu.%llu %d %20s",
162162
&sec, &usec,
163-
&interface, tmp1) == 4) {
163+
&interface, idstr) == 4) {
164164
read_tv.tv_sec = sec;
165165
read_tv.tv_usec = usec;
166166

167-
if (!strncmp(tmp1, "ErrorFrame", strlen("ErrorFrame"))) {
167+
if (!strncmp(idstr, "ErrorFrame", strlen("ErrorFrame"))) {
168168

169169
/* do not know more than 'Error' */
170170
cf.can_id = (CAN_ERR_FLAG | CAN_ERR_BUSERROR);
@@ -181,15 +181,15 @@ static void eval_can(char* buf, struct timeval *date_tvp, char timestamps,
181181

182182
/* check for CAN frames with (hexa)decimal values */
183183
if (base == 'h')
184-
items = sscanf(buf, "%llu.%llu %d %s %4s %c %x %x %x %x %x %x %x %x %x",
184+
items = sscanf(buf, "%llu.%llu %d %20s %4s %c %x %x %x %x %x %x %x %x %x",
185185
&sec, &usec, &interface,
186-
tmp1, dir, &rtr, &dlc,
186+
idstr, dir, &rtr, &dlc,
187187
&data[0], &data[1], &data[2], &data[3],
188188
&data[4], &data[5], &data[6], &data[7]);
189189
else
190-
items = sscanf(buf, "%llu.%llu %d %s %4s %c %x %d %d %d %d %d %d %d %d",
190+
items = sscanf(buf, "%llu.%llu %d %20s %4s %c %x %d %d %d %d %d %d %d %d",
191191
&sec, &usec, &interface,
192-
tmp1, dir, &rtr, &dlc,
192+
idstr, dir, &rtr, &dlc,
193193
&data[0], &data[1], &data[2], &data[3],
194194
&data[4], &data[5], &data[6], &data[7]);
195195

@@ -214,9 +214,9 @@ static void eval_can(char* buf, struct timeval *date_tvp, char timestamps,
214214

215215
/* check for CAN ID with (hexa)decimal value */
216216
if (base == 'h')
217-
get_can_id(&cf.can_id, tmp1, 16);
217+
get_can_id(&cf.can_id, idstr, 16);
218218
else
219-
get_can_id(&cf.can_id, tmp1, 10);
219+
get_can_id(&cf.can_id, idstr, 10);
220220

221221
/* dlc > 8 => len == CAN_MAX_DLEN => fill len8_dlc value */
222222
if (dlc > CAN_MAX_DLC)
@@ -260,7 +260,7 @@ static void eval_canfd(char* buf, struct timeval *date_tvp, char timestamps,
260260
unsigned char brs, esi, ctmp;
261261
unsigned int flags;
262262
int dlc, dlen = 0;
263-
char tmp1[BUFLEN];
263+
char idstr[21];
264264
char dir[5]; /* 'Rx'/'Tx'/'TxRq' plus terminating zero */
265265
char *extra_info;
266266
char *ptr;
@@ -280,14 +280,14 @@ static void eval_canfd(char* buf, struct timeval *date_tvp, char timestamps,
280280
*/
281281

282282
/* check for valid line without symbolic name */
283-
if (sscanf(buf, "%llu.%llu %*s %d %4s %s %hhx %hhx %x %d %n",
283+
if (sscanf(buf, "%llu.%llu %*s %d %4s %20s %hhx %hhx %x %d %n",
284284
&sec, &usec, &interface,
285-
dir, tmp1, &brs, &esi, &dlc, &dlen, &n) != 9) {
285+
dir, idstr, &brs, &esi, &dlc, &dlen, &n) != 9) {
286286

287287
/* check for valid line with a symbolic name */
288-
if (sscanf(buf, "%llu.%llu %*s %d %4s %s %*s %hhx %hhx %x %d %n",
288+
if (sscanf(buf, "%llu.%llu %*s %d %4s %20s %*s %hhx %hhx %x %d %n",
289289
&sec, &usec, &interface,
290-
dir, tmp1, &brs, &esi, &dlc, &dlen, &n) != 9) {
290+
dir, idstr, &brs, &esi, &dlc, &dlen, &n) != 9) {
291291

292292
/* no valid CANFD format pattern */
293293
return;
@@ -321,7 +321,7 @@ static void eval_canfd(char* buf, struct timeval *date_tvp, char timestamps,
321321
if (dlen != can_fd_dlc2len(can_fd_len2dlc(dlen)))
322322
return;
323323

324-
get_can_id(&cf.can_id, tmp1, 16);
324+
get_can_id(&cf.can_id, idstr, 16);
325325

326326
ptr = buf + n; /* start of ASCII hex frame data */
327327

@@ -389,7 +389,7 @@ static void eval_canxl_cc(char* buf, struct timeval *date_tvp, char timestamps,
389389
unsigned char ctmp;
390390
unsigned int flags;
391391
int dlc, dlen = 0;
392-
char tmp1[BUFLEN];
392+
char idstr[21];
393393
char dir[5]; /* 'Rx'/'Tx'/'TxRq' plus terminating zero */
394394
char *extra_info;
395395
char *ptr;
@@ -407,18 +407,18 @@ static void eval_canxl_cc(char* buf, struct timeval *date_tvp, char timestamps,
407407
/* check for valid line without symbolic name */
408408
if (sscanf(buf,
409409
"%llu.%llu %*s %d %4s " /* time, CANXL, channel, direction */
410-
"%*s %*s %*s %s " /* frame format, msg dur, bit count, ID */
410+
"%*s %*s %*s %20s " /* frame format, msg dur, bit count, ID */
411411
"%x %d %n", /* DLC, Datalen */
412412
&sec, &usec, &interface, dir,
413-
tmp1,
413+
idstr,
414414
&dlc, &dlen, &n) != 7) {
415415
/* check for valid line with a symbolic name */
416416
if (sscanf(buf,
417417
"%llu.%llu %*s %d %4s " /* time, CANXL, channel, direction */
418-
"%*s %*s %*s %s " /* frame format, msg dur, bit count, ID */
418+
"%*s %*s %*s %20s " /* frame format, msg dur, bit count, ID */
419419
"%*s %x %d %n", /* sym name, DLC, Datalen */
420420
&sec, &usec, &interface, dir,
421-
tmp1,
421+
idstr,
422422
&dlc, &dlen, &n) != 7) {
423423
/* no valid CAN CC format pattern */
424424
return;
@@ -448,7 +448,7 @@ static void eval_canxl_cc(char* buf, struct timeval *date_tvp, char timestamps,
448448
else
449449
extra_info = " T\n";
450450

451-
get_can_id(&cf.can_id, tmp1, 16);
451+
get_can_id(&cf.can_id, idstr, 16);
452452

453453
ptr = buf + n; /* start of ASCII hex frame data */
454454

@@ -503,7 +503,7 @@ static void eval_canxl_fd(char* buf, struct timeval *date_tvp, char timestamps,
503503
unsigned char ctmp;
504504
unsigned int flags;
505505
int dlc, dlen = 0;
506-
char tmp1[BUFLEN];
506+
char idstr[21];
507507
char dir[5]; /* 'Rx'/'Tx'/'TxRq' plus terminating zero */
508508
char *extra_info;
509509
char *ptr;
@@ -521,18 +521,18 @@ static void eval_canxl_fd(char* buf, struct timeval *date_tvp, char timestamps,
521521
/* check for valid line without symbolic name */
522522
if (sscanf(buf,
523523
"%llu.%llu %*s %d %4s " /* time, CANXL, channel, direction */
524-
"%*s %*s %*s %s " /* frame format, msg dur, bit count, ID */
524+
"%*s %*s %*s %20s " /* frame format, msg dur, bit count, ID */
525525
"%x %d %n", /* DLC, Datalen */
526526
&sec, &usec, &interface, dir,
527-
tmp1,
527+
idstr,
528528
&dlc, &dlen, &n) != 7) {
529529
/* check for valid line with a symbolic name */
530530
if (sscanf(buf,
531531
"%llu.%llu %*s %d %4s " /* time, CANXL, channel, direction */
532-
"%*s %*s %*s %s " /* frame format, msg dur, bit count, ID */
532+
"%*s %*s %*s %20s " /* frame format, msg dur, bit count, ID */
533533
"%*s %x %d %n", /* sym name, DLC, Datalen */
534534
&sec, &usec, &interface, dir,
535-
tmp1,
535+
idstr,
536536
&dlc, &dlen, &n) != 7) {
537537
/* no valid CAN CC format pattern */
538538
return;
@@ -562,7 +562,7 @@ static void eval_canxl_fd(char* buf, struct timeval *date_tvp, char timestamps,
562562
else
563563
extra_info = " T\n";
564564

565-
get_can_id(&cf.can_id, tmp1, 16);
565+
get_can_id(&cf.can_id, idstr, 16);
566566

567567
ptr = buf + n; /* start of ASCII hex frame data */
568568

@@ -613,7 +613,7 @@ static void eval_canxl_xl(char* buf, struct timeval *date_tvp, char timestamps,
613613
unsigned char sdt, vcid, secbit, ctmp;
614614
unsigned int af, flags;
615615
int dlc, dlen = 0;
616-
char tmp1[BUFLEN];
616+
char idstr[21];
617617
char dir[5]; /* 'Rx'/'Tx'/'TxRq' plus terminating zero */
618618
char *extra_info;
619619
char *ptr;
@@ -632,21 +632,21 @@ static void eval_canxl_xl(char* buf, struct timeval *date_tvp, char timestamps,
632632
/* check for valid line without symbolic name */
633633
if (sscanf(buf,
634634
"%llu.%llu %*s %d %4s " /* time, CANXL, channel, direction */
635-
"%*s %*s %*s %s " /* frame format, msg dur, bit count, ID */
635+
"%*s %*s %*s %20s " /* frame format, msg dur, bit count, ID */
636636
"%hhx %hhx %x %d " /* SDT, SEC, DLC, Datalen */
637637
"%*s %*s %hhx %x %n", /* stuff bit count, crc, VCID, AF */
638638
&sec, &usec, &interface, dir,
639-
tmp1,
639+
idstr,
640640
&sdt, &secbit, &dlc, &dlen,
641641
&vcid, &af, &n) != 11) {
642642
/* check for valid line with a symbolic name */
643643
if (sscanf(buf,
644644
"%llu.%llu %*s %d %4s " /* time, CANXL, channel, direction */
645-
"%*s %*s %*s %s " /* frame format, msg dur, bit count, ID */
645+
"%*s %*s %*s %20s " /* frame format, msg dur, bit count, ID */
646646
"%*s %hhx %hhx %x %d " /* sym name, SDT, SEC, DLC, Datalen */
647647
"%*s %*s %hhx %x %n", /* stuff bit count, crc, VCID, AF */
648648
&sec, &usec, &interface, dir,
649-
tmp1,
649+
idstr,
650650
&sdt, &secbit, &dlc, &dlen,
651651
&vcid, &af, &n) != 11) {
652652

@@ -685,7 +685,7 @@ static void eval_canxl_xl(char* buf, struct timeval *date_tvp, char timestamps,
685685
if (dlen != dlc + 1)
686686
return;
687687

688-
get_can_id(&cf.prio, tmp1, 16);
688+
get_can_id(&cf.prio, idstr, 16);
689689

690690
if ((cf.prio & CANXL_PRIO_MASK) != cf.prio)
691691
return;

0 commit comments

Comments
 (0)