Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qtapp clipPoint: use intermediate int64_t to avoid overflow #511

Open
wants to merge 1 commit into
base: demo5
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/qtapp/appcmn_qt/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ int Graph::clipPoint(QPoint *p0, int area, QPoint *p1)

if (area & 1) { // left
if (p0->x() == p1->x()) return 0;
y_ = p0->y() + (p1->y() - p0->y()) * (xmin - p0->x()) / (p1->x() - p0->x());
y_ = p0->y() + (int64_t)(p1->y() - p0->y()) * (xmin - p0->x()) / (p1->x() - p0->x());
if (ymin <= y_ && y_ <= ymax) {
p0->setX(xmin);
p0->setY(y_);
Expand All @@ -723,7 +723,7 @@ int Graph::clipPoint(QPoint *p0, int area, QPoint *p1)
}
if (area & 2) { // right
if (p0->x() == p1->x()) return 0;
y_ = p0->y() + (p1->y() - p0->y()) * (xmax - p0->x()) / (p1->x() - p0->x());
y_ = p0->y() + (int64_t)(p1->y() - p0->y()) * (xmax - p0->x()) / (p1->x() - p0->x());
if (ymin <= y_ && y_ <= ymax) {
p0->setX(xmax);
p0->setY(y_);
Expand All @@ -732,7 +732,7 @@ int Graph::clipPoint(QPoint *p0, int area, QPoint *p1)
}
if (area & 4) { // upper
if (p0->y() == p1->y()) return 0;
x_ = p0->x() + (p1->x() - p0->x()) * (ymin - p0->y()) / (p1->y() - p0->y());
x_ = p0->x() + (int64_t)(p1->x() - p0->x()) * (ymin - p0->y()) / (p1->y() - p0->y());
if (xmin <= x_ && x_ <= xmax) {
p0->setX(x_);
p0->setY(ymin);
Expand All @@ -741,7 +741,7 @@ int Graph::clipPoint(QPoint *p0, int area, QPoint *p1)
}
if (area & 8) { // lower
if (p0->y()==p1->y()) return 0;
x_ = p0->x() + (p1->x() - p0->x()) * (ymax - p0->y()) / (p1->y() - p0->y());
x_ = p0->x() + (int64_t)(p1->x() - p0->x()) * (ymax - p0->y()) / (p1->y() - p0->y());
if (xmin <= x_ && x_ <= xmax) {
p0->setX(x_);
p0->setY(ymax);
Expand Down