src: use arraysize instead of hardcode number
PR-URL: https://github.com/nodejs/node/pull/24473 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Refael Ackermann <refack@gmail.com>
This commit is contained in:
parent
82ceb5e4b1
commit
adbf9477eb
@ -22,6 +22,7 @@
|
|||||||
#include "node_internals.h"
|
#include "node_internals.h"
|
||||||
#include "string_bytes.h"
|
#include "string_bytes.h"
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@ -219,7 +220,7 @@ static void GetInterfaceAddresses(const FunctionCallbackInfo<Value>& args) {
|
|||||||
int count, i;
|
int count, i;
|
||||||
char ip[INET6_ADDRSTRLEN];
|
char ip[INET6_ADDRSTRLEN];
|
||||||
char netmask[INET6_ADDRSTRLEN];
|
char netmask[INET6_ADDRSTRLEN];
|
||||||
char mac[18];
|
std::array<char, 18> mac;
|
||||||
Local<Object> ret, o;
|
Local<Object> ret, o;
|
||||||
Local<String> name, family;
|
Local<String> name, family;
|
||||||
Local<Array> ifarr;
|
Local<Array> ifarr;
|
||||||
@ -256,8 +257,8 @@ static void GetInterfaceAddresses(const FunctionCallbackInfo<Value>& args) {
|
|||||||
ret->Set(env->context(), name, ifarr).FromJust();
|
ret->Set(env->context(), name, ifarr).FromJust();
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(mac,
|
snprintf(mac.data(),
|
||||||
18,
|
mac.size(),
|
||||||
"%02x:%02x:%02x:%02x:%02x:%02x",
|
"%02x:%02x:%02x:%02x:%02x:%02x",
|
||||||
static_cast<unsigned char>(interfaces[i].phys_addr[0]),
|
static_cast<unsigned char>(interfaces[i].phys_addr[0]),
|
||||||
static_cast<unsigned char>(interfaces[i].phys_addr[1]),
|
static_cast<unsigned char>(interfaces[i].phys_addr[1]),
|
||||||
|
@ -787,10 +787,11 @@ inline bool ToASCII(const std::string& input, std::string* output) {
|
|||||||
|
|
||||||
void URLHost::ParseIPv6Host(const char* input, size_t length) {
|
void URLHost::ParseIPv6Host(const char* input, size_t length) {
|
||||||
CHECK_EQ(type_, HostType::H_FAILED);
|
CHECK_EQ(type_, HostType::H_FAILED);
|
||||||
for (unsigned n = 0; n < 8; n++)
|
unsigned size = arraysize(value_.ipv6);
|
||||||
|
for (unsigned n = 0; n < size; n++)
|
||||||
value_.ipv6[n] = 0;
|
value_.ipv6[n] = 0;
|
||||||
uint16_t* piece_pointer = &value_.ipv6[0];
|
uint16_t* piece_pointer = &value_.ipv6[0];
|
||||||
uint16_t* const buffer_end = piece_pointer + 8;
|
uint16_t* const buffer_end = piece_pointer + size;
|
||||||
uint16_t* compress_pointer = nullptr;
|
uint16_t* compress_pointer = nullptr;
|
||||||
const char* pointer = input;
|
const char* pointer = input;
|
||||||
const char* end = pointer + length;
|
const char* end = pointer + length;
|
||||||
@ -952,7 +953,7 @@ void URLHost::ParseIPv4Host(const char* input, size_t length, bool* is_ipv4) {
|
|||||||
const char ch = pointer < end ? pointer[0] : kEOL;
|
const char ch = pointer < end ? pointer[0] : kEOL;
|
||||||
const int remaining = end - pointer - 1;
|
const int remaining = end - pointer - 1;
|
||||||
if (ch == '.' || ch == kEOL) {
|
if (ch == '.' || ch == kEOL) {
|
||||||
if (++parts > 4)
|
if (++parts > static_cast<int>(arraysize(numbers)))
|
||||||
return;
|
return;
|
||||||
if (pointer == mark)
|
if (pointer == mark)
|
||||||
return;
|
return;
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
#include <functional> // std::function
|
#include <functional> // std::function
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <array>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
namespace node {
|
namespace node {
|
||||||
@ -223,6 +224,14 @@ inline v8::Local<v8::String> FIXED_ONE_BYTE_STRING(
|
|||||||
return OneByteString(isolate, data, N - 1);
|
return OneByteString(isolate, data, N - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <std::size_t N>
|
||||||
|
inline v8::Local<v8::String> FIXED_ONE_BYTE_STRING(
|
||||||
|
v8::Isolate* isolate,
|
||||||
|
const std::array<char, N>& arr) {
|
||||||
|
return OneByteString(isolate, arr.data(), N - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Swaps bytes in place. nbytes is the number of bytes to swap and must be a
|
// Swaps bytes in place. nbytes is the number of bytes to swap and must be a
|
||||||
// multiple of the word size (checked by function).
|
// multiple of the word size (checked by function).
|
||||||
|
Loading…
x
Reference in New Issue
Block a user