Skip to content

Enable cppcoreguidelines-pro-bounds-pointer-arithmetic #1900

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

Open
wants to merge 3 commits into
base: main
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake/common/clang-tidy.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"Checks": "-*, bugprone-*, -bugprone-easily-swappable-parameters,-bugprone-unchecked-optional-access, concurrency-*, cppcoreguidelines-avoid-const-or-ref-data-members, modernize-*, performance-*, portability-*",
"Checks": "-*, bugprone-*, -bugprone-easily-swappable-parameters,-bugprone-unchecked-optional-access, concurrency-*,cppcoreguidelines-pro-bounds-pointer-arithmetic, cppcoreguidelines-avoid-const-or-ref-data-members, modernize-*, performance-*, portability-*",
"WarningsAsErrors": "*",
"FormatStyle": "none",
"UseColor": true
Expand Down
1 change: 1 addition & 0 deletions src/core/json/include/sourcemeta/core/json_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ template <typename T> struct PropertyHashJSON {
hash_type result;
assert(!value.empty());
// Copy starting a byte 2
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
std::memcpy(reinterpret_cast<char *>(&result) + 1, value.data(), size);
return result;
}
Expand Down
19 changes: 10 additions & 9 deletions src/core/yaml/yaml.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <sourcemeta/core/json_error.h>
#include <sourcemeta/core/yaml.h>

#include <span> // std::span
#include <sstream> // std::ostringstream, std::istringstream
#include <string_view> // std::string_view

Expand Down Expand Up @@ -52,9 +53,10 @@ auto yaml_node_to_json(yaml_node_t *const node, yaml_document_t *const document)

case YAML_SEQUENCE_NODE: {
auto result{sourcemeta::core::JSON::make_array()};
for (yaml_node_item_t *item = node->data.sequence.items.start;
item < node->data.sequence.items.top; ++item) {
yaml_node_t *const child = yaml_document_get_node(document, *item);
auto item_span = std::span<yaml_node_item_t>(
node->data.sequence.items.start, node->data.sequence.items.top);
for (auto item : item_span) {
const auto child = yaml_document_get_node(document, item);
result.push_back(yaml_node_to_json(child, document));
}

Expand All @@ -63,12 +65,11 @@ auto yaml_node_to_json(yaml_node_t *const node, yaml_document_t *const document)

case YAML_MAPPING_NODE: {
auto result{sourcemeta::core::JSON::make_object()};
for (yaml_node_pair_t *pair = node->data.mapping.pairs.start;
pair < node->data.mapping.pairs.top; ++pair) {
yaml_node_t *const key_node =
yaml_document_get_node(document, pair->key);
yaml_node_t *const value_node =
yaml_document_get_node(document, pair->value);
auto pair_span = std::span<yaml_node_pair_t>(
node->data.mapping.pairs.start, node->data.mapping.pairs.top);
for (auto pair : pair_span) {
const auto key_node = yaml_document_get_node(document, pair.key);
const auto value_node = yaml_document_get_node(document, pair.value);
if (key_node && key_node->type == YAML_SCALAR_NODE) {
result.assign(reinterpret_cast<char *>(key_node->data.scalar.value),
yaml_node_to_json(value_node, document));
Expand Down
Loading