Skip to content

Commit 4173cde

Browse files
committed
Fixed some warnings on Windows and a potential crash on overwrite.
Signed-off-by: Gonzalo Garramuño <[email protected]>
1 parent e6ebb66 commit 4173cde

File tree

1 file changed

+43
-6
lines changed

1 file changed

+43
-6
lines changed

src/opentimelineio/algo/editAlgorithm.cpp

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ overwrite(
128128
// Find the items to overwrite.
129129
auto items =
130130
composition->find_children<Item>(error_status, range, true);
131+
if (items.empty())
132+
{
133+
if (error_status)
134+
*error_status = ErrorStatus::NOT_AN_ITEM;
135+
return;
136+
}
131137
TimeRange item_range =
132138
composition->trimmed_range_of_child(items.front()).value();
133139
if (1 == items.size() && item_range.contains(range, 0.0))
@@ -169,7 +175,7 @@ overwrite(
169175
first_item->set_source_range(source_range);
170176
++insert_index;
171177
}
172-
const TimeRange item_range = item->trimmed_range();
178+
item_range = item->trimmed_range();
173179
if (range.duration() < item_range.duration() && !is_fill_fit)
174180
item->set_source_range(
175181
TimeRange(trimmed_range.start_time(), range.duration()));
@@ -372,8 +378,20 @@ void trim(
372378
ErrorStatus* error_status)
373379
{
374380
Composition* composition = item->parent();
381+
if (!composition)
382+
{
383+
if (error_status)
384+
*error_status = ErrorStatus::NOT_A_CHILD_OF;
385+
return;
386+
}
375387
auto children = composition->children();
376388
const int index = composition->index_of_child(item);
389+
if (index < 0)
390+
{
391+
if (error_status)
392+
*error_status = ErrorStatus::NOT_AN_ITEM;
393+
return;
394+
}
377395

378396
const TimeRange range = item->trimmed_range();
379397
RationalTime start_time = range.start_time();
@@ -392,7 +410,7 @@ void trim(
392410
}
393411
if (delta_out.value() != 0.0)
394412
{
395-
const size_t next_index = index + 1;
413+
const int next_index = index + 1;
396414
if (next_index < children.size())
397415
{
398416
auto next = dynamic_retainer_cast<Item>(children[next_index]);
@@ -492,8 +510,8 @@ slice(
492510
{
493511
for (auto transition : transitions)
494512
{
495-
const int index = composition->index_of_child(transition);
496-
composition->remove_child(index);
513+
const int child_index = composition->index_of_child(transition);
514+
composition->remove_child(child_index);
497515
}
498516
}
499517
else
@@ -560,6 +578,11 @@ void slide(
560578
RationalTime const& delta)
561579
{
562580
Composition* composition = item->parent();
581+
if (!composition)
582+
{
583+
return;
584+
}
585+
563586
const int index = composition->index_of_child(item);
564587

565588
// Exit early if we are at the first clip or if the delta is 0.
@@ -604,6 +627,8 @@ void ripple(
604627
RationalTime const& delta_out,
605628
ErrorStatus* error_status)
606629
{
630+
if (error_status) *error_status = ErrorStatus::OK;
631+
607632
const TimeRange range = item->trimmed_range();
608633
RationalTime start_time = range.start_time();
609634
RationalTime end_time_exclusive = range.end_time_exclusive();
@@ -651,8 +676,20 @@ roll(
651676
ErrorStatus* error_status)
652677
{
653678
Composition* composition = item->parent();
679+
if (!composition)
680+
{
681+
if (error_status)
682+
*error_status = ErrorStatus::NOT_A_CHILD_OF;
683+
return;
684+
}
654685
auto children = composition->children();
655686
const int index = composition->index_of_child(item);
687+
if (index < 0)
688+
{
689+
if (error_status)
690+
*error_status = ErrorStatus::NOT_AN_ITEM;
691+
return;
692+
}
656693

657694
const TimeRange range = item->trimmed_range();
658695
const TimeRange available_range = item->available_range();
@@ -696,15 +733,15 @@ roll(
696733
{
697734
auto next = dynamic_retainer_cast<Item>(children[next_index]);
698735
TimeRange next_range = next->trimmed_range();
699-
const TimeRange available_range = next->available_range();
736+
const TimeRange next_available_range = next->available_range();
700737
RationalTime next_start_time = next_range.start_time();
701738
RationalTime out_offset = delta_out;
702739

703740
// If avalable range, clamp to it.
704741
if (!(isEqual(available_range.duration().value(), 0.0)))
705742
{
706743
RationalTime available_start_time =
707-
available_range.start_time();
744+
next_available_range.start_time();
708745
if (-out_offset > available_start_time)
709746
out_offset = -available_start_time;
710747
}

0 commit comments

Comments
 (0)