Skip to content
This repository was archived by the owner on Apr 5, 2025. It is now read-only.

Commit d3a9ab5

Browse files
committed
Revise for possible null current_image
1 parent 6f2526c commit d3a9ab5

1 file changed

Lines changed: 12 additions & 15 deletions

File tree

src/util.cpp

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -393,15 +393,16 @@ size_t mystrftime(ctx_dev *cam, char *s, size_t max
393393
const char *pos_userformat;
394394
int width;
395395
struct tm timestamp_tm;
396-
timespec ts1;
396+
ctx_image_data img;
397397

398398
if (cam->current_image == NULL) {
399-
clock_gettime(CLOCK_REALTIME, &ts1);
399+
memset(&img, 0, sizeof(ctx_image_data));
400+
clock_gettime(CLOCK_REALTIME, &img.imgts);
400401
} else {
401-
ts1 = cam->current_image->imgts;
402+
memcpy(&img, cam->current_image, sizeof(ctx_image_data));
402403
}
403404

404-
localtime_r(&ts1.tv_sec, &timestamp_tm);
405+
localtime_r(&img.imgts.tv_sec, &timestamp_tm);
405406

406407
format = formatstring;
407408

@@ -438,43 +439,39 @@ size_t mystrftime(ctx_dev *cam, char *s, size_t max
438439
break;
439440

440441
case 'q': // shots
441-
sprintf(tempstr, "%0*d", width ? width : 2,
442-
cam->current_image->shot);
442+
sprintf(tempstr, "%0*d", width ? width : 2, img.shot);
443443
break;
444444

445445
case 'D': // diffs
446-
sprintf(tempstr, "%*d", width, cam->current_image->diffs);
446+
sprintf(tempstr, "%*d", width, img.diffs);
447447
break;
448448

449449
case 'N': // noise
450450
sprintf(tempstr, "%*d", width, cam->noise);
451451
break;
452452

453453
case 'i': // motion width
454-
sprintf(tempstr, "%*d", width,
455-
cam->current_image->location.width);
454+
sprintf(tempstr, "%*d", width, img.location.width);
456455
break;
457456

458457
case 'J': // motion height
459-
sprintf(tempstr, "%*d", width,
460-
cam->current_image->location.height);
458+
sprintf(tempstr, "%*d", width, img.location.height);
461459
break;
462460

463461
case 'K': // motion center x
464-
sprintf(tempstr, "%*d", width, cam->current_image->location.x);
462+
sprintf(tempstr, "%*d", width, img.location.x);
465463
break;
466464

467465
case 'L': // motion center y
468-
sprintf(tempstr, "%*d", width, cam->current_image->location.y);
466+
sprintf(tempstr, "%*d", width, img.location.y);
469467
break;
470468

471469
case 'o': // threshold
472470
sprintf(tempstr, "%*d", width, cam->threshold);
473471
break;
474472

475473
case 'Q': // number of labels
476-
sprintf(tempstr, "%*d", width,
477-
cam->current_image->total_labels);
474+
sprintf(tempstr, "%*d", width, img.total_labels);
478475
break;
479476

480477
case 't': // device id

0 commit comments

Comments
 (0)