Skip to content

Commit 8ef2203

Browse files
Cleaned up DataRow class.
1 parent 65faa34 commit 8ef2203

File tree

1 file changed

+47
-30
lines changed

1 file changed

+47
-30
lines changed

src/lib/data/DataRow.cpp

Lines changed: 47 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
//
2222
//******************************************************************************************************
2323

24+
#pragma warning(disable:26444)
25+
// ReSharper disable CppExpressionWithoutSideEffects
2426
// ReSharper disable once CppUnusedIncludeDirective
2527
#include "../filterexpressions/FilterExpressions.h"
2628
#include "DataRow.h"
@@ -470,13 +472,16 @@ void DataRow::SetValue(const int32_t columnIndex, const Nullable<T>& value, Data
470472
if (value.HasValue())
471473
{
472474
uint8_t* copy = static_cast<uint8_t*>(malloc(sizeof(T)));
473-
memcpy(copy, &value.Value, sizeof(T)); //-V575
474-
m_values[columnIndex] = copy;
475-
}
476-
else
477-
{
478-
m_values[columnIndex] = nullptr;
475+
476+
if (copy)
477+
{
478+
memcpy(copy, &value.Value, sizeof(T)); //-V575
479+
m_values[columnIndex] = copy;
480+
return;
481+
}
479482
}
483+
484+
m_values[columnIndex] = nullptr;
480485
}
481486

482487
const DataTablePtr& DataRow::Parent() const
@@ -632,13 +637,16 @@ void DataRow::SetStringValue(const int32_t columnIndex, const Nullable<string>&
632637
const string& strval = value.GetValueOrDefault();
633638
const uint32_t length = ConvertUInt32(strval.size() + 1);
634639
char* copy = static_cast<char*>(malloc(length * sizeof(char)));
635-
strcpy_s(copy, length, strval.c_str());
636-
m_values[columnIndex] = copy;
637-
}
638-
else
639-
{
640-
m_values[columnIndex] = nullptr;
640+
641+
if (copy)
642+
{
643+
strcpy_s(copy, length, strval.c_str());
644+
m_values[columnIndex] = copy;
645+
return;
646+
}
641647
}
648+
649+
m_values[columnIndex] = nullptr;
642650
}
643651

644652
void DataRow::SetStringValue(const string& columnName, const Nullable<string>& value)
@@ -676,13 +684,16 @@ void DataRow::SetBooleanValue(const int32_t columnIndex, const Nullable<bool>& v
676684
if (value.HasValue())
677685
{
678686
uint8_t* copy = static_cast<uint8_t*>(malloc(1));
679-
*copy = value.GetValueOrDefault() ? 1 : 0; //-V522
680-
m_values[columnIndex] = copy;
681-
}
682-
else
683-
{
684-
m_values[columnIndex] = nullptr;
687+
688+
if (copy)
689+
{
690+
*copy = value.GetValueOrDefault() ? 1 : 0; //-V522
691+
m_values[columnIndex] = copy;
692+
return;
693+
}
685694
}
695+
696+
m_values[columnIndex] = nullptr;
686697
}
687698

688699
void DataRow::SetBooleanValue(const string& columnName, const Nullable<bool>& value)
@@ -784,13 +795,16 @@ void DataRow::SetDecimalValue(const int32_t columnIndex, const Nullable<decimal_
784795
const string& strval = value.GetValueOrDefault().str();
785796
const uint32_t length = ConvertUInt32(strval.size() + 1);
786797
char* copy = static_cast<char*>(malloc(length * sizeof(char)));
787-
strcpy_s(copy, length, strval.c_str());
788-
m_values[columnIndex] = copy;
789-
}
790-
else
791-
{
792-
m_values[columnIndex] = nullptr;
798+
799+
if (copy)
800+
{
801+
strcpy_s(copy, length, strval.c_str());
802+
m_values[columnIndex] = copy;
803+
return;
804+
}
793805
}
806+
807+
m_values[columnIndex] = nullptr;
794808
}
795809

796810
void DataRow::SetDecimalValue(const string& columnName, const Nullable<decimal_t>& value)
@@ -832,13 +846,16 @@ void DataRow::SetGuidValue(const int32_t columnIndex, const Nullable<sttp::Guid>
832846
if (value.HasValue())
833847
{
834848
int8_t* copy = static_cast<int8_t*>(malloc(16));
835-
memcpy(copy, value.GetValueOrDefault().data, 16); //-V575
836-
m_values[columnIndex] = copy;
837-
}
838-
else
839-
{
840-
m_values[columnIndex] = nullptr;
849+
850+
if (copy)
851+
{
852+
memcpy(copy, value.GetValueOrDefault().data, 16); //-V575
853+
m_values[columnIndex] = copy;
854+
return;
855+
}
841856
}
857+
858+
m_values[columnIndex] = nullptr;
842859
}
843860

844861
void DataRow::SetGuidValue(const string& columnName, const Nullable<sttp::Guid>& value)

0 commit comments

Comments
 (0)