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

static analysis fixes #3662

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions Examples/Extensibility/CPP/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");

};

Expand Down
2 changes: 1 addition & 1 deletion Source/CNTK/BrainScript/BrainScriptParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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".")
Expand Down
2 changes: 1 addition & 1 deletion Source/CNTKv2LibraryDll/API/Internals/EvaluatorWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion Source/CNTKv2LibraryDll/API/Internals/PrimitiveFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion Source/CNTKv2LibraryDll/EvaluatorWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ namespace CNTK
}
std::copy(data->DataBuffer<float>(), data->DataBuffer<float>() + size, v.data);
result.get()[i] = v;
valCleaner.release();
valCleaner.reset(nullptr);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Source/CNTKv2LibraryDll/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
Expand Down
4 changes: 2 additions & 2 deletions Source/CNTKv2LibraryDll/proto/onnx/CNTKToONNX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7103,7 +7103,7 @@ bool CNTKToONNXHelper::IsPadValueValid(const std::vector<int64_t>& 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;
}
Expand Down Expand Up @@ -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;

Expand Down
5 changes: 0 additions & 5 deletions Source/CNTKv2LibraryDll/proto/onnx/ONNXToCNTK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Source/CNTKv2LibraryDll/proto/onnx/RNNHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Source/ComputationNetworkLib/ConvolutionalNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -1388,7 +1388,7 @@ class MaxUnpoolingNode : public ConvolutionNodeBase<ElemType>, 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.
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Math/CuDnnRNN.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Source/Readers/BinaryReader/BinaryWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ Section* BinaryWriter<ElemType>::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);
}
Expand Down
2 changes: 2 additions & 0 deletions Source/Readers/LibSVMBinaryReader/LibSVMBinaryReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ SparseBinaryInput<ElemType>::SparseBinaryInput(std::wstring fileName)
template <class ElemType>
SparseBinaryInput<ElemType>::~SparseBinaryInput()
{
free(m_readOrder);
free(m_tempValues);
}

template <class ElemType>
Expand Down
2 changes: 1 addition & 1 deletion Source/Readers/UCIFastReader/UCIFastReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ void UCIFastReader<ElemType>::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());
Expand Down
7 changes: 4 additions & 3 deletions Source/SGDLib/ASGDHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ class MultiversoHelper : public ASGDHelper<ElemType>
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++)
{
Expand Down Expand Up @@ -517,8 +518,8 @@ class MultiversoHelper : public ASGDHelper<ElemType>
{
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)
Expand Down