@@ -501,7 +501,8 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data)
501501 * A trigger was set up, so we need to tell the frontend
502502 * about it.
503503 */
504- if (devc -> trigger_at_smpl > 0 ) {
504+ if (devc -> trigger_at_smpl > 0
505+ && (unsigned int )devc -> trigger_at_smpl <= devc -> num_samples ) {
505506 /* There are pre-trigger samples, send those first. */
506507 packet .type = SR_DF_LOGIC ;
507508 packet .payload = & logic ;
@@ -516,14 +517,16 @@ SR_PRIV int ols_receive_data(int fd, int revents, void *cb_data)
516517 }
517518
518519 /* Send post-trigger / all captured samples. */
519- int num_pre_trigger_samples = devc -> trigger_at_smpl == OLS_NO_TRIGGER
520- ? 0 : devc -> trigger_at_smpl ;
521- packet .type = SR_DF_LOGIC ;
522- packet .payload = & logic ;
523- logic .length = (devc -> num_samples - num_pre_trigger_samples ) * 4 ;
524- logic .unitsize = 4 ;
525- logic .data = devc -> raw_sample_buf + num_pre_trigger_samples * 4 ;
526- sr_session_send (sdi , & packet );
520+ unsigned int num_pre_trigger_samples = devc -> trigger_at_smpl == OLS_NO_TRIGGER
521+ ? 0 : MIN ((unsigned int )devc -> trigger_at_smpl , devc -> num_samples );
522+ if (devc -> num_samples > num_pre_trigger_samples ) {
523+ packet .type = SR_DF_LOGIC ;
524+ packet .payload = & logic ;
525+ logic .length = (devc -> num_samples - num_pre_trigger_samples ) * 4 ;
526+ logic .unitsize = 4 ;
527+ logic .data = devc -> raw_sample_buf + num_pre_trigger_samples * 4 ;
528+ sr_session_send (sdi , & packet );
529+ }
527530
528531 g_free (devc -> raw_sample_buf );
529532 devc -> raw_sample_buf = 0 ;
0 commit comments