NShiftKey-Rule-Guide logo NShiftKey-Rule-Guide

1. Vulnerability Description

2. Vulnerability Countermeasure

3. Sample Code

Window& Window::operator=(const Window& rhs)
{
    delete sb;
    sb = new ScrollBar(*rhs.sb);
    return *this;
}
Window& Window::operator=(const Window& rhs)
{
    // Check that it is self-assignment
    if (this == &rhs;)
	return *this;
    // Make sure to copy it because throw can occur after delete.
    ScrollBar *sbOld = sb;
    sb = new ScrollBar(*rhs.sb);
    delete sbOld;
    return *this;
}