Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4405fc8

Browse filesBrowse files
tniessenRafaelGSS
authored andcommitted
src: use stricter compile-time guidance
SnapshotSerializerDeserializer::GetName() appears to confuse static analysis such as Coverity. This changes the function structure to a sequence of if-else blocks and marks all branch conditions as constexpr. (Unfortunately, this results in a dangling 'else' keyword in the V macro.) As per a request in the PR discussion, this change does _not_ ensure that GetName<T>() can only be called for known types T and instead still returns an empty string in that case. Also use std::is_unsigned_v instead of !std::is_signed_v. PR-URL: #46509 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com>
1 parent db95ed0 commit 4405fc8
Copy full SHA for 4405fc8

File tree

Expand file treeCollapse file tree

1 file changed

+8
-11
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+8
-11
lines changed
Open diff view settings
Collapse file

‎src/node_snapshotable.cc‎

Copy file name to clipboardExpand all lines: src/node_snapshotable.cc
+8-11Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -166,22 +166,19 @@ class SnapshotSerializerDeserializer {
166166
V(std::string)
167167

168168
#define V(TypeName) \
169-
if (std::is_same_v<T, TypeName>) { \
169+
if constexpr (std::is_same_v<T, TypeName>) { \
170170
return #TypeName; \
171-
}
171+
} else // NOLINT(readability/braces)
172172
TYPE_LIST(V)
173173
#undef V
174174

175-
std::string name;
176-
if (std::is_arithmetic_v<T>) {
177-
if (!std::is_signed_v<T>) {
178-
name += "u";
179-
}
180-
name += std::is_integral_v<T> ? "int" : "float";
181-
name += std::to_string(sizeof(T) * 8);
182-
name += "_t";
175+
if constexpr (std::is_arithmetic_v<T>) {
176+
return (std::is_unsigned_v<T> ? "uint"
177+
: std::is_integral_v<T> ? "int"
178+
: "float") +
179+
std::to_string(sizeof(T) * 8) + "_t";
183180
}
184-
return name;
181+
return "";
185182
}
186183

187184
bool is_debug = false;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.