Fix potential divisions by 0 reported by MSVC
The `TextEdit` one was indeed a potential bug. The `PCKPacker` one seems to be a false positive, it's already in a `for` loop that depends on `files.size()`.
This commit is contained in:
parent
cce0a27ec7
commit
ca4e4506db
|
@ -163,7 +163,7 @@ Error PCKPacker::flush(bool p_verbose) {
|
||||||
src->close();
|
src->close();
|
||||||
memdelete(src);
|
memdelete(src);
|
||||||
count += 1;
|
count += 1;
|
||||||
if (p_verbose) {
|
if (p_verbose && files.size() > 0) {
|
||||||
if (count % 100 == 0) {
|
if (count % 100 == 0) {
|
||||||
printf("%i/%i (%.2f)\r", count, files.size(), float(count) / files.size() * 100);
|
printf("%i/%i (%.2f)\r", count, files.size(), float(count) / files.size() * 100);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
|
@ -1582,7 +1582,7 @@ void TextEdit::_notification(int p_what) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool completion_below = false;
|
bool completion_below = false;
|
||||||
if (completion_active) {
|
if (completion_active && completion_options.size() > 0) {
|
||||||
// Code completion box.
|
// Code completion box.
|
||||||
Ref<StyleBox> csb = get_stylebox("completion");
|
Ref<StyleBox> csb = get_stylebox("completion");
|
||||||
int maxlines = get_constant("completion_lines");
|
int maxlines = get_constant("completion_lines");
|
||||||
|
@ -1590,13 +1590,14 @@ void TextEdit::_notification(int p_what) {
|
||||||
int scrollw = get_constant("completion_scroll_width");
|
int scrollw = get_constant("completion_scroll_width");
|
||||||
Color scrollc = get_color("completion_scroll_color");
|
Color scrollc = get_color("completion_scroll_color");
|
||||||
|
|
||||||
int lines = MIN(completion_options.size(), maxlines);
|
const int completion_options_size = completion_options.size();
|
||||||
|
int lines = MIN(completion_options_size, maxlines);
|
||||||
int w = 0;
|
int w = 0;
|
||||||
int h = lines * get_row_height();
|
int h = lines * get_row_height();
|
||||||
int nofs = cache.font->get_string_size(completion_base).width;
|
int nofs = cache.font->get_string_size(completion_base).width;
|
||||||
|
|
||||||
if (completion_options.size() < 50) {
|
if (completion_options_size < 50) {
|
||||||
for (int i = 0; i < completion_options.size(); i++) {
|
for (int i = 0; i < completion_options_size; i++) {
|
||||||
int w2 = MIN(cache.font->get_string_size(completion_options[i].display).x, cmax_width);
|
int w2 = MIN(cache.font->get_string_size(completion_options[i].display).x, cmax_width);
|
||||||
if (w2 > w)
|
if (w2 > w)
|
||||||
w = w2;
|
w = w2;
|
||||||
|
@ -1627,7 +1628,7 @@ void TextEdit::_notification(int p_what) {
|
||||||
|
|
||||||
completion_rect.size.width = w + 2;
|
completion_rect.size.width = w + 2;
|
||||||
completion_rect.size.height = h;
|
completion_rect.size.height = h;
|
||||||
if (completion_options.size() <= maxlines)
|
if (completion_options_size <= maxlines)
|
||||||
scrollw = 0;
|
scrollw = 0;
|
||||||
|
|
||||||
draw_style_box(csb, Rect2(completion_rect.position - csb->get_offset(), completion_rect.size + csb->get_minimum_size() + Size2(scrollw, 0)));
|
draw_style_box(csb, Rect2(completion_rect.position - csb->get_offset(), completion_rect.size + csb->get_minimum_size() + Size2(scrollw, 0)));
|
||||||
|
@ -1635,14 +1636,14 @@ void TextEdit::_notification(int p_what) {
|
||||||
if (cache.completion_background_color.a > 0.01) {
|
if (cache.completion_background_color.a > 0.01) {
|
||||||
VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(completion_rect.position, completion_rect.size + Size2(scrollw, 0)), cache.completion_background_color);
|
VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(completion_rect.position, completion_rect.size + Size2(scrollw, 0)), cache.completion_background_color);
|
||||||
}
|
}
|
||||||
int line_from = CLAMP(completion_index - lines / 2, 0, completion_options.size() - lines);
|
int line_from = CLAMP(completion_index - lines / 2, 0, completion_options_size - lines);
|
||||||
VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(completion_rect.position.x, completion_rect.position.y + (completion_index - line_from) * get_row_height()), Size2(completion_rect.size.width, get_row_height())), cache.completion_selected_color);
|
VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(completion_rect.position.x, completion_rect.position.y + (completion_index - line_from) * get_row_height()), Size2(completion_rect.size.width, get_row_height())), cache.completion_selected_color);
|
||||||
draw_rect(Rect2(completion_rect.position + Vector2(icon_area_size.x + icon_hsep, 0), Size2(MIN(nofs, completion_rect.size.width - (icon_area_size.x + icon_hsep)), completion_rect.size.height)), cache.completion_existing_color);
|
draw_rect(Rect2(completion_rect.position + Vector2(icon_area_size.x + icon_hsep, 0), Size2(MIN(nofs, completion_rect.size.width - (icon_area_size.x + icon_hsep)), completion_rect.size.height)), cache.completion_existing_color);
|
||||||
|
|
||||||
for (int i = 0; i < lines; i++) {
|
for (int i = 0; i < lines; i++) {
|
||||||
|
|
||||||
int l = line_from + i;
|
int l = line_from + i;
|
||||||
ERR_CONTINUE(l < 0 || l >= completion_options.size());
|
ERR_CONTINUE(l < 0 || l >= completion_options_size);
|
||||||
Color text_color = cache.completion_font_color;
|
Color text_color = cache.completion_font_color;
|
||||||
for (int j = 0; j < color_regions.size(); j++) {
|
for (int j = 0; j < color_regions.size(); j++) {
|
||||||
if (completion_options[l].insert_text.begins_with(color_regions[j].begin_key)) {
|
if (completion_options[l].insert_text.begins_with(color_regions[j].begin_key)) {
|
||||||
|
@ -1669,8 +1670,8 @@ void TextEdit::_notification(int p_what) {
|
||||||
|
|
||||||
if (scrollw) {
|
if (scrollw) {
|
||||||
// Draw a small scroll rectangle to show a position in the options.
|
// Draw a small scroll rectangle to show a position in the options.
|
||||||
float r = maxlines / (float)completion_options.size();
|
float r = (float)maxlines / completion_options_size;
|
||||||
float o = line_from / (float)completion_options.size();
|
float o = (float)line_from / completion_options_size;
|
||||||
draw_rect(Rect2(completion_rect.position.x + completion_rect.size.width, completion_rect.position.y + o * completion_rect.size.y, scrollw, completion_rect.size.y * r), scrollc);
|
draw_rect(Rect2(completion_rect.position.x + completion_rect.size.width, completion_rect.position.y + o * completion_rect.size.y, scrollw, completion_rect.size.y * r), scrollc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue