Be more consistent about using .data() for gettng C arrays

It's safer than &var[0] as that will invoke undefined behaviour if var
is empty.
This commit is contained in:
Oliver Hamlet
2022-02-07 20:25:13 +00:00
parent 9e0ac81d66
commit 2e8230f063
3 changed files with 7 additions and 7 deletions
+5 -5
View File
@@ -143,8 +143,8 @@ std::wstring ToWinWide(const std::string& str) {
0,
str.c_str(),
static_cast<int>(str.length()),
&wstr[0],
static_cast<int>(len));
wstr.data(),
static_cast<int>(wstr.length()));
return wstr;
}
@@ -167,8 +167,8 @@ std::string FromWinWide(const std::wstring& wstr) {
0,
wstr.c_str(),
static_cast<int>(wstr.length()),
&str[0],
static_cast<int>(len),
str.data(),
static_cast<int>(str.length()),
NULL,
NULL);
return str;
@@ -208,7 +208,7 @@ std::string NormalizeFilename(const std::string& filename) {
return std::string();
}
CharUpperBuffW(&wideString[0], static_cast<int>(wideString.length()));
CharUpperBuffW(wideString.data(), static_cast<int>(wideString.length()));
return FromWinWide(wideString);
#else
std::string normalizedFilename;
+1 -1
View File
@@ -204,7 +204,7 @@ size_t Plugin::GetOverlapSize(
size_t overlapSize = 0;
auto ret = esp_plugin_records_overlap_size(
esPlugin.get(), &esPlugins[0], esPlugins.size(), &overlapSize);
esPlugin.get(), esPlugins.data(), esPlugins.size(), &overlapSize);
if (ret != ESP_OK) {
throw FileAccessError("Error getting overlap size for \"" + name_ +
"\". esplugin error code: " + std::to_string(ret));
+1 -1
View File
@@ -269,7 +269,7 @@ std::vector<Vertex> GetGroupsPath(const std::vector<Group>& masterlistGroups,
boost::weight_map(edge_map_t(weightMap))
.predecessor_map(boost::make_iterator_property_map(
predecessors.begin(), get(boost::vertex_index, graph)))
.distance_map(&distance[0])
.distance_map(distance.data())
.root_vertex(toVertex));
std::vector<Vertex> path;