Skip to content

Commit 0fbfb28

Browse files
tniessenMoLow
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 <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
1 parent 116df2a commit 0fbfb28

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

src/node_snapshotable.cc

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -163,22 +163,19 @@ class SnapshotSerializerDeserializer {
163163
V(std::string)
164164

165165
#define V(TypeName) \
166-
if (std::is_same_v<T, TypeName>) { \
166+
if constexpr (std::is_same_v<T, TypeName>) { \
167167
return #TypeName; \
168-
}
168+
} else // NOLINT(readability/braces)
169169
TYPE_LIST(V)
170170
#undef V
171171

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

184181
bool is_debug = false;

0 commit comments

Comments
 (0)