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

Fix MSVC C4146 warnings #8366

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ilya071294
Copy link
Contributor

The warning description: "unary minus operator applied to unsigned type, result still unsigned".

The warning description: "unary minus operator applied to unsigned type, result still unsigned".
@ilya071294 ilya071294 requested a review from dyemanov December 27, 2024 13:06
@@ -432,7 +432,7 @@ void FirstValueWinNode::aggInit(thread_db* tdbb, Request* request) const

dsc* FirstValueWinNode::winPass(thread_db* tdbb, Request* request, SlidingWindow* window) const
{
if (!window->moveWithinFrame(-(window->getRecordPosition() - window->getFrameStart())))
if (!window->moveWithinFrame(-static_cast<SINT64>(window->getRecordPosition() - window->getFrameStart())))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I\d suggest a temporary variable for better readability, e.g.:

const SINT64 offset = window->getRecordPosition() - window->getFrameStart(); // with static_cast, if necessary
if (!window->moveWithinFrame(-offset))

Copy link
Member

@hvlad hvlad Dec 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expression window->getRecordPosition() - window->getFrameStart() used many times, makes sence to move it into separate function, like:

	class SlidingWindow
	{
	public:
...
	FB_UINT64 getInFrameOffset() const
	{
		return savedPosition - frameStart;
	}

Perhaps, it should return SINT64

@@ -583,7 +583,7 @@ dsc* NthValueWinNode::winPass(thread_db* tdbb, Request* request, SlidingWindow*
const SLONG fromPos = desc ? MOV_get_long(tdbb, desc, 0) : FROM_FIRST;

if (fromPos == FROM_FIRST)
records += -(window->getRecordPosition() - window->getFrameStart()) - 1;
records += -static_cast<SINT64>(window->getRecordPosition() - window->getFrameStart()) - 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just -= with a positive offset here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants