[Base, Sketcher] remove redundant boolean checks

This commit is contained in:
Uwe
2022-10-02 22:14:45 +02:00
parent 2dd9f90f57
commit bf3d7f64ca
3 changed files with 52 additions and 66 deletions

View File

@@ -261,7 +261,7 @@ public:
// SymInitialize
if (szSymPath != NULL)
m_szSymPath = _strdup(szSymPath);
if (this->pSI(m_hProcess, m_szSymPath, FALSE) == FALSE)
if (!this->pSI(m_hProcess, m_szSymPath, FALSE))
this->m_parent->OnDbgHelpErr("SymInitialize", GetLastError(), 0);
DWORD symOptions = this->pSGO(); // SymGetOptions
@@ -272,10 +272,9 @@ public:
symOptions = this->pSSO(symOptions);
char buf[StackWalker::STACKWALK_MAX_NAMELEN] = {0};
if (this->pSGSP != NULL)
{
if (this->pSGSP(m_hProcess, buf, StackWalker::STACKWALK_MAX_NAMELEN) == FALSE)
this->m_parent->OnDbgHelpErr("SymGetSearchPath", GetLastError(), 0);
if (this->pSGSP != NULL) {
if (!this->pSGSP(m_hProcess, buf, !StackWalker::STACKWALK_MAX_NAMELEN))
this->m_parent->OnDbgHelpErr("SymGetSearchPath", GetLastError(), 0);
}
char szUserName[1024] = {0};
DWORD dwSize = 1024;
@@ -621,29 +620,26 @@ private:
// retrieve some additional-infos about the module
IMAGEHLP_MODULE64_V3 Module;
const char *szSymType = "-unknown-";
if (this->GetModuleInfo(hProcess, baseAddr, &Module) != FALSE)
{
switch(Module.SymType)
{
case SymNone:
szSymType = "-nosymbols-";
if (this->GetModuleInfo(hProcess, baseAddr, &Module)) {
switch (Module.SymType) {
case SymNone: szSymType = "-nosymbols-";
break;
case SymCoff: // 1
case SymCoff: // 1
szSymType = "COFF";
break;
case SymCv: // 2
case SymCv: // 2
szSymType = "CV";
break;
case SymPdb: // 3
case SymPdb: // 3
szSymType = "PDB";
break;
case SymExport: // 4
case SymExport: // 4
szSymType = "-exported-";
break;
case SymDeferred: // 5
case SymDeferred: // 5
szSymType = "-deferred-";
break;
case SymSym: // 6
case SymSym: // 6
szSymType = "SYM";
break;
case 7: // SymDia:
@@ -692,10 +688,8 @@ public:
}
memcpy(pData, pModuleInfo, sizeof(IMAGEHLP_MODULE64_V3));
static bool s_useV3Version = true;
if (s_useV3Version)
{
if (this->pSGMI(hProcess, baseAddr, (IMAGEHLP_MODULE64_V3*) pData) != FALSE)
{
if (s_useV3Version) {
if (this->pSGMI(hProcess, baseAddr, (IMAGEHLP_MODULE64_V3 *)pData)) {
// only copy as much memory as is reserved...
memcpy(pModuleInfo, pData, sizeof(IMAGEHLP_MODULE64_V3));
pModuleInfo->SizeOfStruct = sizeof(IMAGEHLP_MODULE64_V3);
@@ -708,8 +702,7 @@ public:
// could not retrieve the bigger structure, try with the smaller one (as defined in VC7.1)...
pModuleInfo->SizeOfStruct = sizeof(IMAGEHLP_MODULE64_V2);
memcpy(pData, pModuleInfo, sizeof(IMAGEHLP_MODULE64_V2));
if (this->pSGMI(hProcess, baseAddr, (IMAGEHLP_MODULE64_V3*) pData) != FALSE)
{
if (this->pSGMI(hProcess, baseAddr, (IMAGEHLP_MODULE64_V3 *)pData)) {
// only copy as much memory as is reserved...
memcpy(pModuleInfo, pData, sizeof(IMAGEHLP_MODULE64_V2));
pModuleInfo->SizeOfStruct = sizeof(IMAGEHLP_MODULE64_V2);
@@ -767,7 +760,7 @@ BOOL StackWalker::LoadModules()
SetLastError(ERROR_DLL_INIT_FAILED);
return FALSE;
}
if (m_modulesLoaded != FALSE)
if (m_modulesLoaded)
return TRUE;
// Build the sym-path:
@@ -861,15 +854,14 @@ BOOL StackWalker::LoadModules()
// First Init the whole stuff...
BOOL bRet = this->m_sw->Init(szSymPath);
if (szSymPath != NULL) free(szSymPath); szSymPath = NULL;
if (bRet == FALSE)
{
if (!bRet) {
this->OnDbgHelpErr("Error while initializing dbghelp.dll", 0, 0);
SetLastError(ERROR_DLL_INIT_FAILED);
return FALSE;
}
bRet = this->m_sw->LoadModules(this->m_hProcess, this->m_dwProcessId);
if (bRet != FALSE)
if (bRet)
m_modulesLoaded = TRUE;
return bRet;
}
@@ -893,11 +885,10 @@ BOOL StackWalker::ShowCallstack(HANDLE hThread, const CONTEXT *context, PReadPro
bool bLastEntryCalled = true;
int curRecursionCount = 0;
if (m_modulesLoaded == FALSE)
if (!m_modulesLoaded)
this->LoadModules(); // ignore the result...
if (this->m_sw->m_hDbhHelp == NULL)
{
if (this->m_sw->m_hDbhHelp == NULL) {
SetLastError(ERROR_DLL_INIT_FAILED);
return FALSE;
}
@@ -905,20 +896,16 @@ BOOL StackWalker::ShowCallstack(HANDLE hThread, const CONTEXT *context, PReadPro
s_readMemoryFunction = readMemoryFunction;
s_readMemoryFunction_UserData = pUserData;
if (context == NULL)
{
if (context == NULL) {
// If no context is provided, capture the context
if (hThread == GetCurrentThread())
{
if (hThread == GetCurrentThread()) {
GET_CURRENT_CONTEXT(c, USED_CONTEXT_FLAGS);
}
else
{
else {
SuspendThread(hThread);
memset(&c, 0, sizeof(CONTEXT));
c.ContextFlags = USED_CONTEXT_FLAGS;
if (GetThreadContext(hThread, &c) == FALSE)
{
if (!GetThreadContext(hThread, &c)) {
ResumeThread(hThread);
return FALSE;
}
@@ -1013,7 +1000,7 @@ BOOL StackWalker::ShowCallstack(HANDLE hThread, const CONTEXT *context, PReadPro
{
// we seem to have a valid PC
// show procedure info (SymGetSymFromAddr64())
if (this->m_sw->pSGSFA(this->m_hProcess, s.AddrPC.Offset, &(csEntry.offsetFromSmybol), pSym) != FALSE)
if (this->m_sw->pSGSFA(this->m_hProcess, s.AddrPC.Offset, &(csEntry.offsetFromSmybol), pSym))
{
MyStrCpy(csEntry.name, STACKWALK_MAX_NAMELEN, pSym->Name);
// UnDecorateSymbolName()
@@ -1026,22 +1013,20 @@ BOOL StackWalker::ShowCallstack(HANDLE hThread, const CONTEXT *context, PReadPro
}
// show line number info, NT5.0-method (SymGetLineFromAddr64())
if (this->m_sw->pSGLFA != NULL )
{ // yes, we have SymGetLineFromAddr64()
if (this->m_sw->pSGLFA(this->m_hProcess, s.AddrPC.Offset, &(csEntry.offsetFromLine), &Line) != FALSE)
{
csEntry.lineNumber = Line.LineNumber;
MyStrCpy(csEntry.lineFileName, STACKWALK_MAX_NAMELEN, Line.FileName);
if (this->m_sw->pSGLFA != NULL) { // yes, we have SymGetLineFromAddr64()
if (this->m_sw->pSGLFA(this->m_hProcess, s.AddrPC.Offset, &(csEntry.offsetFromLine),
&Line)) {
csEntry.lineNumber = Line.LineNumber;
MyStrCpy(csEntry.lineFileName, STACKWALK_MAX_NAMELEN, Line.FileName);
}
else
{
else {
this->OnDbgHelpErr("SymGetLineFromAddr64", GetLastError(), s.AddrPC.Offset);
}
} // yes, we have SymGetLineFromAddr64()
// show module info (SymGetModuleInfo64())
if (this->m_sw->GetModuleInfo(this->m_hProcess, s.AddrPC.Offset, &Module ) != FALSE)
{ // got module info OK
if (this->m_sw->GetModuleInfo(this->m_hProcess, s.AddrPC.Offset, &Module)) {
// got module info OK
switch ( Module.SymType )
{
case SymNone:
@@ -1195,11 +1180,10 @@ void StackWalker::OnSymInit(LPCSTR szSearchPath, DWORD symOptions, LPCSTR szUser
OSVERSIONINFOEXA ver;
ZeroMemory(&ver, sizeof(OSVERSIONINFOEXA));
ver.dwOSVersionInfoSize = sizeof(ver);
if (GetVersionExA( (OSVERSIONINFOA*) &ver) != FALSE)
{
_snprintf_s(buffer, STACKWALK_MAX_NAMELEN, "OS-Version: %d.%d.%d (%s) 0x%x-0x%x\n",
ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber,
ver.szCSDVersion, ver.wSuiteMask, ver.wProductType);
if (GetVersionExA((OSVERSIONINFOA *)&ver)) {
_snprintf_s(buffer, STACKWALK_MAX_NAMELEN, "OS-Version: %d.%d.%d (%s) 0x%x-0x%x\n",
ver.dwMajorVersion, ver.dwMinorVersion, ver.dwBuildNumber, ver.szCSDVersion,
ver.wSuiteMask, ver.wProductType);
OnOutput(buffer);
}
}

View File

@@ -336,7 +336,7 @@ void SketcherGui::removeRedundantHorizontalVertical(Sketcher::SketchObject* pske
std::vector<AutoConstraint> &sug1,
std::vector<AutoConstraint> &sug2)
{
if(!sug1.empty() && !sug2.empty()) {
if (!sug1.empty() && !sug2.empty()) {
bool rmvhorvert = false;
@@ -349,8 +349,9 @@ void SketcherGui::removeRedundantHorizontalVertical(Sketcher::SketchObject* pske
orig = false;
axis = false;
for(std::vector<AutoConstraint>::const_iterator it = sug.begin(); it!=sug.end(); ++it) {
if( (*it).Type == Sketcher::Coincident && ext == false) {
for (std::vector<AutoConstraint>::const_iterator it = sug.begin(); it != sug.end();
++it) {
if ((*it).Type == Sketcher::Coincident && !ext) {
const std::map<int, Sketcher::PointPos> coincidents = psketch->getAllCoincidentPoints((*it).GeoId, (*it).PosId);
if(!coincidents.empty()) {
@@ -371,8 +372,9 @@ void SketcherGui::removeRedundantHorizontalVertical(Sketcher::SketchObject* pske
orig = ((*it).GeoId == -1 && (*it).PosId == Sketcher::PointPos::start);
}
}
else if( (*it).Type == Sketcher::PointOnObject && axis == false) {
axis = (((*it).GeoId == -1 && (*it).PosId == Sketcher::PointPos::none) || ((*it).GeoId == -2 && (*it).PosId == Sketcher::PointPos::none));
else if ((*it).Type == Sketcher::PointOnObject && !axis) {
axis = (((*it).GeoId == -1 && (*it).PosId == Sketcher::PointPos::none)
|| ((*it).GeoId == -2 && (*it).PosId == Sketcher::PointPos::none));
}
}

View File

@@ -669,7 +669,7 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe
//Base::Console().Log("start dragging, point:%d\n",this->DragPoint);
Mode = STATUS_SELECT_Cross;
done = true;
} else if (preselection.PreselectConstraintSet.empty() != true) {
} else if (!preselection.PreselectConstraintSet.empty()) {
//Base::Console().Log("start dragging, point:%d\n",this->DragPoint);
Mode = STATUS_SELECT_Constraint;
done = true;
@@ -926,7 +926,7 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe
return true;
} else if (preselection.isPreselectCurveValid()) {
return true;
} else if (preselection.PreselectConstraintSet.empty() != true) {
} else if (!preselection.PreselectConstraintSet.empty()) {
return true;
} else {
Gui::MenuItem geom;
@@ -1053,7 +1053,7 @@ void ViewProviderSketch::editDoubleClicked()
else if (preselection.isCrossPreselected()) {
Base::Console().Log("double click cross:%d\n",preselection.PreselectCross);
}
else if (preselection.PreselectConstraintSet.empty() != true) {
else if (!preselection.PreselectConstraintSet.empty()) {
// Find the constraint
const std::vector<Sketcher::Constraint *> &constrlist = getSketchObject()->Constraints.getValues();
@@ -1735,7 +1735,7 @@ void ViewProviderSketch::onSelectionChanged(const Gui::SelectionChanges& msg)
}
}
bool ViewProviderSketch::detectAndShowPreselection(SoPickedPoint *Point, const SbVec2s &cursorPos)
bool ViewProviderSketch::detectAndShowPreselection(SoPickedPoint * Point, const SbVec2s &cursorPos)
{
assert(isInEditMode());
@@ -1846,7 +1846,7 @@ bool ViewProviderSketch::detectAndShowPreselection(SoPickedPoint *Point, const S
&& result.ConstrIndices.empty())
&& (preselection.isPreselectPointValid() || preselection.isPreselectCurveValid()
|| preselection.isCrossPreselected()
|| preselection.PreselectConstraintSet.empty() != true
|| !preselection.PreselectConstraintSet.empty()
|| preselection.blockedPreselection)) {
// we have just left a preselection
resetPreselectPoint();
@@ -1859,8 +1859,8 @@ bool ViewProviderSketch::detectAndShowPreselection(SoPickedPoint *Point, const S
Point->getPoint()[2]);
}
else if (preselection.isPreselectCurveValid() || preselection.isPreselectPointValid()
|| preselection.PreselectConstraintSet.empty() != true
|| preselection.isCrossPreselected() || preselection.blockedPreselection) {
|| !preselection.PreselectConstraintSet.empty() || preselection.isCrossPreselected()
|| preselection.blockedPreselection) {
resetPreselectPoint();
preselection.blockedPreselection = false;
if (sketchHandler)