From 2a4ad8217dbef3afb7ae2cda8cdacdbbf7f0471b Mon Sep 17 00:00:00 2001 From: Eric Budai Date: Sat, 11 May 2019 13:45:45 -0400 Subject: [PATCH] static analysis fixes --- Examples/Extensibility/CPP/Main.cpp | 4 ++-- Source/CNTK/BrainScript/BrainScriptParser.cpp | 2 +- Source/CNTKv2LibraryDll/API/Internals/EvaluatorWrapper.h | 2 +- Source/CNTKv2LibraryDll/API/Internals/PrimitiveFunction.h | 2 +- Source/CNTKv2LibraryDll/EvaluatorWrapper.cpp | 2 +- Source/CNTKv2LibraryDll/Utils.cpp | 2 +- Source/CNTKv2LibraryDll/proto/onnx/CNTKToONNX.cpp | 4 ++-- Source/CNTKv2LibraryDll/proto/onnx/ONNXToCNTK.cpp | 5 ----- Source/CNTKv2LibraryDll/proto/onnx/RNNHelper.cpp | 2 +- Source/ComputationNetworkLib/ConvolutionalNodes.h | 2 +- Source/Math/CuDnnRNN.h | 2 +- Source/Readers/BinaryReader/BinaryWriter.cpp | 2 +- Source/Readers/LibSVMBinaryReader/LibSVMBinaryReader.cpp | 2 ++ Source/Readers/UCIFastReader/UCIFastReader.cpp | 2 +- Source/SGDLib/ASGDHelper.cpp | 7 ++++--- 15 files changed, 20 insertions(+), 22 deletions(-) diff --git a/Examples/Extensibility/CPP/Main.cpp b/Examples/Extensibility/CPP/Main.cpp index da12e4549050..27fcacad3d51 100644 --- a/Examples/Extensibility/CPP/Main.cpp +++ b/Examples/Extensibility/CPP/Main.cpp @@ -53,10 +53,10 @@ void UserTimesFunctionExample() const double absoluteTolerance = 0.000001f; if (!Internal::AreEqual(*userDefinedTimesOutputValue, *builtInTimesOutputValue, relativeTolerance, absoluteTolerance)) - std::runtime_error("UserTimesOp's Forward result does not match built-in result"); + throw std::runtime_error("UserTimesOp's Forward result does not match built-in result"); if (!Internal::AreEqual(*userDefinedTimesInputGradientValue, *builtInTimesInputGradientValue, relativeTolerance, absoluteTolerance)) - std::runtime_error("UserTimesOp's Forward result does not match built-in result"); + throw std::runtime_error("UserTimesOp's Forward result does not match built-in result"); }; diff --git a/Source/CNTK/BrainScript/BrainScriptParser.cpp b/Source/CNTK/BrainScript/BrainScriptParser.cpp index 53d41c5818a1..bdbf612d8d3f 100644 --- a/Source/CNTK/BrainScript/BrainScriptParser.cpp +++ b/Source/CNTK/BrainScript/BrainScriptParser.cpp @@ -580,7 +580,7 @@ void Expression::DumpToStream(wstringstream & treeStream, int indent) else if (op == L"d") treeStream << std::fixed << std::setprecision(0) << d; else if (op == L"b") - treeStream << b ? "true" : "false"; + treeStream << (b ? "true" : "false"); else if (op == L"id") treeStream << id.c_str(); else if (op == L"new" || op == L"array" || op == L".") diff --git a/Source/CNTKv2LibraryDll/API/Internals/EvaluatorWrapper.h b/Source/CNTKv2LibraryDll/API/Internals/EvaluatorWrapper.h index c74b33dffa41..34952cae2893 100644 --- a/Source/CNTKv2LibraryDll/API/Internals/EvaluatorWrapper.h +++ b/Source/CNTKv2LibraryDll/API/Internals/EvaluatorWrapper.h @@ -136,7 +136,7 @@ namespace CNTK resultVar.shape = FromNDShape(var.Shape()); result.get()[i] = resultVar; - varCleaner.release(); + varCleaner.reset(nullptr); } *numResultVars = (uint32_t)vars.size(); diff --git a/Source/CNTKv2LibraryDll/API/Internals/PrimitiveFunction.h b/Source/CNTKv2LibraryDll/API/Internals/PrimitiveFunction.h index 8c22dbd28d5c..d96d3df971a9 100644 --- a/Source/CNTKv2LibraryDll/API/Internals/PrimitiveFunction.h +++ b/Source/CNTKv2LibraryDll/API/Internals/PrimitiveFunction.h @@ -592,7 +592,7 @@ namespace CNTK } else if (rightOperandShape[i] == NDShape::InferredDimension || rightOperandShape[i] == NDShape::FreeDimension) { - if (leftOperandShape[outputRank + i] == NDShape::FreeDimension && leftOperandShape[outputRank + i] == NDShape::InferredDimension) + if (leftOperandShape[outputRank + i] == NDShape::FreeDimension || leftOperandShape[outputRank + i] == NDShape::InferredDimension) InvalidArgument("Times: %s operand '%S' shape '%S' dimension cannot be inferred from a %s operand '%S' shape '%S' free dimension.", Internal::IsReversingTensorShapesInErrorMessagesEnabled() ? "left" : "right", rightOperand.AsString().c_str(), diff --git a/Source/CNTKv2LibraryDll/EvaluatorWrapper.cpp b/Source/CNTKv2LibraryDll/EvaluatorWrapper.cpp index b936326160ba..ca1b8603ab9e 100644 --- a/Source/CNTKv2LibraryDll/EvaluatorWrapper.cpp +++ b/Source/CNTKv2LibraryDll/EvaluatorWrapper.cpp @@ -130,7 +130,7 @@ namespace CNTK } std::copy(data->DataBuffer(), data->DataBuffer() + size, v.data); result.get()[i] = v; - valCleaner.release(); + valCleaner.reset(nullptr); } } diff --git a/Source/CNTKv2LibraryDll/Utils.cpp b/Source/CNTKv2LibraryDll/Utils.cpp index ade645825ed8..46e0cea2120c 100644 --- a/Source/CNTKv2LibraryDll/Utils.cpp +++ b/Source/CNTKv2LibraryDll/Utils.cpp @@ -973,7 +973,7 @@ namespace CNTK axes.push_back(Axis(staticIdx)); } - if (inputShape[i] != NDShape::FreeDimension || inputShape[i] != NDShape::InferredDimension) + if (inputShape[i] != NDShape::FreeDimension && inputShape[i] != NDShape::InferredDimension) { staticIdx++; } diff --git a/Source/CNTKv2LibraryDll/proto/onnx/CNTKToONNX.cpp b/Source/CNTKv2LibraryDll/proto/onnx/CNTKToONNX.cpp index 3564405e2465..762354f80fed 100644 --- a/Source/CNTKv2LibraryDll/proto/onnx/CNTKToONNX.cpp +++ b/Source/CNTKv2LibraryDll/proto/onnx/CNTKToONNX.cpp @@ -7103,7 +7103,7 @@ bool CNTKToONNXHelper::IsPadValueValid(const std::vector& lowerPad, con // If this node has explicitly set the lowerPad and upperPad values(i.e. nodes that are constructed with lowerPad/upperPad values and autoPadding=False), // export these values directly. Otherwise, check autoPadding and export accordingly. bool isAllPadsZero = std::all_of(lowerPad.begin(), lowerPad.end(), [](int64_t i) { return i == 0; }); - isAllPadsZero = isAllPadsZero & std::all_of(upperPad.begin(), upperPad.end(), [](int64_t i) { return i == 0; }); + isAllPadsZero &= std::all_of(upperPad.begin(), upperPad.end(), [](int64_t i) { return i == 0; }); bool isAnyAutoPadTrue = std::any_of(autoPadding.begin(), autoPadding.end(), [](bool i) { return i; }); return lowerPad.size() > 0 && upperPad.size() > 0 && !(lowerPad.size() == 1 && upperPad.size() == 1 && lowerPad[0] == 0 && upperPad[0] == 0) && !(isAllPadsZero && ceilOutDim) && !isAnyAutoPadTrue; } @@ -7160,7 +7160,7 @@ onnxruntime::Node* FindByName(onnxruntime::Graph* graph, const std::string &name { GraphNodes &nodes = graph->Nodes(); - for (onnxruntime::GraphNodes::MutableNodeIterator it = nodes.begin(); it != nodes.begin(); ++it) + for (onnxruntime::GraphNodes::MutableNodeIterator it = nodes.begin(); it != nodes.end(); ++it) { onnxruntime::Node &node = *it; diff --git a/Source/CNTKv2LibraryDll/proto/onnx/ONNXToCNTK.cpp b/Source/CNTKv2LibraryDll/proto/onnx/ONNXToCNTK.cpp index 8f25602b80ae..11babb4c57a0 100644 --- a/Source/CNTKv2LibraryDll/proto/onnx/ONNXToCNTK.cpp +++ b/Source/CNTKv2LibraryDll/proto/onnx/ONNXToCNTK.cpp @@ -2576,11 +2576,6 @@ FunctionPtr ONNXToCNTKHelper::CreateFunction(const Node *node, const std::vector return ElementMin(inputs[0], inputs[0], ToFixedWStringFromMultiByte(node->Name())); } } - else if (onnxOpName == "Sum") - { - // not specified in Operators.cpp - return nullptr; - } else if (onnxOpName == "Softmax" || onnxOpName == "LogSoftmax" || onnxOpName == "Hardmax") { int64_t onnxAxis = GetNamedAttributeAsInt64(node, "axis", 1); diff --git a/Source/CNTKv2LibraryDll/proto/onnx/RNNHelper.cpp b/Source/CNTKv2LibraryDll/proto/onnx/RNNHelper.cpp index 42d235cd008d..1705a2420e7a 100644 --- a/Source/CNTKv2LibraryDll/proto/onnx/RNNHelper.cpp +++ b/Source/CNTKv2LibraryDll/proto/onnx/RNNHelper.cpp @@ -459,7 +459,7 @@ Variable ToBatchAndSequence(Variable input, VariableToFunctionPtr &sequenceWrapp if (sequenceWrapperInputToFunctionPtr.find(input) != sequenceWrapperInputToFunctionPtr.end()) return sequenceWrapperInputToFunctionPtr[input]; - if (input.DynamicAxes().size() != 0) + if (input.DynamicAxes().size() == 0) return input; if(input.DynamicAxes().size() != 0) diff --git a/Source/ComputationNetworkLib/ConvolutionalNodes.h b/Source/ComputationNetworkLib/ConvolutionalNodes.h index 1b5c4ba3cbb8..2b1ffe1fe530 100644 --- a/Source/ComputationNetworkLib/ConvolutionalNodes.h +++ b/Source/ComputationNetworkLib/ConvolutionalNodes.h @@ -1388,7 +1388,7 @@ class MaxUnpoolingNode : public ConvolutionNodeBase, public NumInputs< { if (m_transforms.empty()) { - m_transforms[0] = ComputeFilterTransform(); + m_transforms.emplace_back(ComputeFilterTransform()); } // else: transform already computed, no need to do it again. } diff --git a/Source/Math/CuDnnRNN.h b/Source/Math/CuDnnRNN.h index e32d1137906a..c57fb8bbb577 100644 --- a/Source/Math/CuDnnRNN.h +++ b/Source/Math/CuDnnRNN.h @@ -159,7 +159,7 @@ class CuDnnFilter int dimW[3] = { (int)m_filterSize, 1, 1 }; CUDNN_CALL(cudnnSetFilterNdDescriptor(m_filterDesc, m_dataType, CUDNN_TENSOR_NCHW, 3, dimW)); } - catch (exception e) + catch (exception& e) { cudnnDestroyFilterDescriptor(m_filterDesc); m_filterDesc = nullptr; diff --git a/Source/Readers/BinaryReader/BinaryWriter.cpp b/Source/Readers/BinaryReader/BinaryWriter.cpp index 5a103f551bfa..51d35569d944 100644 --- a/Source/Readers/BinaryReader/BinaryWriter.cpp +++ b/Source/Readers/BinaryReader/BinaryWriter.cpp @@ -168,7 +168,7 @@ Section* BinaryWriter::CreateSection(const ConfigParameters& config, S initialSize = dataSize * 5 / 4; // make the initalSize slightly larger than needed for data file = new SectionFile(wfile, fileOptionsReadWrite, initialSize); m_secFiles[wfile] = file; - parentSection = file->FileSection(); + *parentSection = *file->FileSection(); parentSection->SetElementCount(records); parentSection->SetFileUniqueId(this->m_uniqueID); } diff --git a/Source/Readers/LibSVMBinaryReader/LibSVMBinaryReader.cpp b/Source/Readers/LibSVMBinaryReader/LibSVMBinaryReader.cpp index 2e2f4f305fbb..11390973bd4e 100644 --- a/Source/Readers/LibSVMBinaryReader/LibSVMBinaryReader.cpp +++ b/Source/Readers/LibSVMBinaryReader/LibSVMBinaryReader.cpp @@ -217,6 +217,8 @@ SparseBinaryInput::SparseBinaryInput(std::wstring fileName) template SparseBinaryInput::~SparseBinaryInput() { + free(m_readOrder); + free(m_tempValues); } template diff --git a/Source/Readers/UCIFastReader/UCIFastReader.cpp b/Source/Readers/UCIFastReader/UCIFastReader.cpp index 7c7f0e70c421..8ef7a31acd5b 100644 --- a/Source/Readers/UCIFastReader/UCIFastReader.cpp +++ b/Source/Readers/UCIFastReader/UCIFastReader.cpp @@ -522,7 +522,7 @@ void UCIFastReader::InitCache(const ConfigParameters& readerConfig) } } } - catch (runtime_error err) + catch (runtime_error& err) { // In case caching reader/writer cannot be created, we gracefully fail over and disable caching. fprintf(stderr, "Error attemping to create Binary%s\n%s\n", found ? "Reader" : "Writer", err.what()); diff --git a/Source/SGDLib/ASGDHelper.cpp b/Source/SGDLib/ASGDHelper.cpp index 4ae5238d728c..cb83f73f87ec 100644 --- a/Source/SGDLib/ASGDHelper.cpp +++ b/Source/SGDLib/ASGDHelper.cpp @@ -143,7 +143,8 @@ class MultiversoHelper : public ASGDHelper if (m_useAsyncBuffer && m_aysncBufferThread != nullptr && m_aysncBufferThread->joinable()) m_aysncBufferThread->join(); - delete m_bufferSwapIndex, m_deltaArray; + delete m_bufferSwapIndex; + delete m_deltaArray; for (size_t i = 0; i < m_localBufferNum; i++) { @@ -517,8 +518,8 @@ class MultiversoHelper : public ASGDHelper { factor = (samplesSinceLastSync + 0.0f) / nTotalSamples; } - factor = 1.0f / m_pMPI->NumNodesInUse(); - return factor; + + return factor; } inline void transpose(ElemType *src, ElemType *dst, const int N, const int M)