Skip to content

Commit 0ebe314

Browse files
JakeChampionelliottt
authored andcommitted
Apply suggestions from code review
Co-authored-by: Trevor Elliott <[email protected]>
1 parent f4fdc49 commit 0ebe314

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

c-dependencies/js-compute-runtime/builtins/backend.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ bool isValidIPv4(std::string_view ip) {
111111
return false;
112112
}
113113
int value;
114-
const std::from_chars_result result =
114+
const auto result =
115115
std::from_chars(digits.data(), digits.data() + digits.size(), value);
116116
if (result.ec == std::errc::invalid_argument || result.ec == std::errc::result_out_of_range) {
117117
return false;
@@ -188,15 +188,15 @@ bool isValidHost(std::string_view host) {
188188

189189
auto labels = split(hostname, '.');
190190

191-
for (auto label : labels) {
191+
for (auto &label : labels) {
192192
// Each label in a hostname can not be longer than 63 characters
193193
// https://www.rfc-editor.org/rfc/rfc2181#section-11
194194
if (label.length() > 63) {
195195
return false;
196196
}
197197

198198
// Each label can only contain the characters in the regex [a-zA-Z0-9\-]
199-
auto it = std::find_if_not(label.begin(), label.end(), [&](auto character) {
199+
auto it = std::find_if_not(label.begin(), label.end(), [](auto character) {
200200
return std::isalnum(character) || character == '-';
201201
});
202202
if (it != label.end()) {
@@ -209,7 +209,7 @@ bool isValidHost(std::string_view host) {
209209
// https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml
210210
if (pos != std::string::npos) {
211211
std::string_view port = host.substr(pos + 1);
212-
if (!std::all_of(port.begin(), port.end(), ::isdigit)) {
212+
if (!std::all_of(port.begin(), port.end(), [](auto c) { return std::isdigit(c); })) {
213213
return false;
214214
}
215215
int value;
@@ -231,6 +231,7 @@ JS::Result<mozilla::Ok> Backend::register_dynamic_backend(JSContext *cx, JS::Han
231231
MOZ_ASSERT(is_instance(backend));
232232

233233
DynamicBackendConfig definition;
234+
std::memset(&definition, 0, sizeof(definition));
234235

235236
unsigned int backend_config_mask = 0u;
236237

@@ -471,7 +472,7 @@ bool Backend::set_target(JSContext *cx, JSObject *backend, JS::HandleValue targe
471472
return false;
472473
}
473474

474-
std::string_view targetString((char *)targetStringSlice.data, targetStringSlice.len);
475+
std::string_view targetString(reinterpret_cast<char*>(targetStringSlice.data), targetStringSlice.len);
475476
auto length = targetString.length();
476477
if (length == 0) {
477478
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_BACKEND_TARGET_EMPTY);

0 commit comments

Comments
 (0)