Skip to content

Commit 4a12a29

Browse files
Prevent crash when only instance of class is marked as an overlay
1 parent 841313d commit 4a12a29

File tree

1 file changed

+34
-36
lines changed

1 file changed

+34
-36
lines changed

jbmc/src/java_bytecode/java_class_loader.cpp

+34-36
Original file line numberDiff line numberDiff line change
@@ -168,50 +168,48 @@ java_class_loadert::get_parse_tree(
168168
}
169169
}
170170

171-
if(!parse_trees.empty())
171+
auto parse_tree_it = parse_trees.begin();
172+
// If the first class implementation is an overlay emit a warning and
173+
// skip over it until we find a non-overlay class
174+
while(parse_tree_it != parse_trees.end())
172175
{
173-
auto parse_tree_it = parse_trees.begin();
174-
// If the first class implementation is an overlay emit a warning and
175-
// skip over it until we find a non-overlay class
176-
while(parse_tree_it != parse_trees.end())
177-
{
178-
// Skip parse trees that failed to load - though these shouldn't exist yet
179-
if(parse_tree_it->loading_successful)
180-
{
181-
if(!is_overlay_class(parse_tree_it->parsed_class))
182-
{
183-
// Keep the non-overlay class
184-
++parse_tree_it;
185-
break;
186-
}
187-
warning()
188-
<< "Skipping class " << class_name
189-
<< " marked with OverlayClassImplementation but found before"
190-
" original definition"
191-
<< eom;
192-
}
193-
auto unloaded_or_overlay_out_of_order_it = parse_tree_it;
194-
++parse_tree_it;
195-
parse_trees.erase(unloaded_or_overlay_out_of_order_it);
196-
}
197-
// Collect overlay classes
198-
while(parse_tree_it != parse_trees.end())
176+
// Skip parse trees that failed to load - though these shouldn't exist yet
177+
if(parse_tree_it->loading_successful)
199178
{
200-
// Remove non-initial classes that aren't overlays
201179
if(!is_overlay_class(parse_tree_it->parsed_class))
202180
{
203-
warning()
204-
<< "Skipping duplicate definition of class " << class_name
205-
<< " not marked with OverlayClassImplementation" << eom;
206-
auto duplicate_non_overlay_it = parse_tree_it;
181+
// Keep the non-overlay class
207182
++parse_tree_it;
208-
parse_trees.erase(duplicate_non_overlay_it);
183+
break;
209184
}
210-
else
211-
++parse_tree_it;
185+
warning()
186+
<< "Skipping class " << class_name
187+
<< " marked with OverlayClassImplementation but found before"
188+
" original definition"
189+
<< eom;
212190
}
213-
return parse_trees;
191+
auto unloaded_or_overlay_out_of_order_it = parse_tree_it;
192+
++parse_tree_it;
193+
parse_trees.erase(unloaded_or_overlay_out_of_order_it);
214194
}
195+
// Collect overlay classes
196+
while(parse_tree_it != parse_trees.end())
197+
{
198+
// Remove non-initial classes that aren't overlays
199+
if(!is_overlay_class(parse_tree_it->parsed_class))
200+
{
201+
warning()
202+
<< "Skipping duplicate definition of class " << class_name
203+
<< " not marked with OverlayClassImplementation" << eom;
204+
auto duplicate_non_overlay_it = parse_tree_it;
205+
++parse_tree_it;
206+
parse_trees.erase(duplicate_non_overlay_it);
207+
}
208+
else
209+
++parse_tree_it;
210+
}
211+
if(!parse_trees.empty())
212+
return parse_trees;
215213

216214
// Not found or failed to load
217215
warning() << "failed to load class `" << class_name << '\'' << eom;

0 commit comments

Comments
 (0)