Skip to content

Commit 70e71f2

Browse files
committed
修复一些AI评审出来的问题
1 parent e77fc91 commit 70e71f2

File tree

7 files changed

+25
-29
lines changed

7 files changed

+25
-29
lines changed

bee/lua/error.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace bee::lua {
2424
return "Windows";
2525
}
2626
std::string message(int error_code) const override {
27-
wchar_t* message = 0;
27+
wchar_t* message = nullptr;
2828
const unsigned long result = ::FormatMessageW(
2929
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS,
3030
NULL,

bee/net/endpoint.cpp

+16-16
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ namespace bee::net {
8585
}
8686
addrinfo* info = nullptr;
8787
};
88+
89+
const char* inet_ntop_wrapper(int af, const void* src, char* dst, socklen_t size) {
90+
#if !defined(__MINGW32__)
91+
return inet_ntop(af, src, dst, size);
92+
#else
93+
return inet_ntop(af, const_cast<void*>(src), dst, size);
94+
#endif
95+
}
8896
}
8997

9098
bool endpoint::ctor_hostname(endpoint& ep, zstring_view name, uint16_t port) noexcept {
@@ -106,13 +114,13 @@ namespace bee::net {
106114
if (info->ai_addrlen != sizeof(sockaddr_in)) {
107115
return false;
108116
}
109-
ep.assgin(*(const sockaddr_in*)info->ai_addr);
117+
ep.assign(*(const sockaddr_in*)info->ai_addr);
110118
return true;
111119
} else if (info->ai_family == AF_INET6) {
112120
if (info->ai_addrlen != sizeof(sockaddr_in6)) {
113121
return false;
114122
}
115-
ep.assgin(*(const sockaddr_in6*)info->ai_addr);
123+
ep.assign(*(const sockaddr_in6*)info->ai_addr);
116124
return true;
117125
} else {
118126
return false;
@@ -127,7 +135,7 @@ namespace bee::net {
127135
su.sun_family = AF_UNIX;
128136
memset(su.sun_path, 0, UNIX_PATH_MAX);
129137
memcpy(su.sun_path, path.data(), path.size() + 1);
130-
ep.assgin(su);
138+
ep.assign(su);
131139
return true;
132140
}
133141

@@ -136,7 +144,7 @@ namespace bee::net {
136144
if (1 == inet_pton(AF_INET, ip.data(), &sa4.sin_addr)) {
137145
sa4.sin_family = AF_INET;
138146
sa4.sin_port = htons(port);
139-
ep.assgin(sa4);
147+
ep.assign(sa4);
140148
return true;
141149
}
142150
return false;
@@ -147,7 +155,7 @@ namespace bee::net {
147155
if (1 == inet_pton(AF_INET6, ip.data(), &sa6.sin6_addr)) {
148156
sa6.sin6_family = AF_INET6;
149157
sa6.sin6_port = htons(port);
150-
ep.assgin(sa6);
158+
ep.assign(sa6);
151159
return true;
152160
}
153161
return false;
@@ -159,7 +167,7 @@ namespace bee::net {
159167
sa4.sin_port = htons(port);
160168
sa4.sin_addr = std::bit_cast<decltype(sa4.sin_addr)>(ip::inet_pton_v4("127.0.0.1"));
161169
endpoint ep;
162-
ep.assgin(sa4);
170+
ep.assign(sa4);
163171
return ep;
164172
}
165173

@@ -170,22 +178,14 @@ namespace bee::net {
170178
std::tuple<std::string, uint16_t> endpoint::get_inet() const noexcept {
171179
const sockaddr* sa = addr();
172180
char tmp[sizeof "255.255.255.255"];
173-
#if !defined(__MINGW32__)
174-
const char* s = inet_ntop(AF_INET, (const void*)&((struct sockaddr_in*)sa)->sin_addr, tmp, sizeof tmp);
175-
#else
176-
const char* s = inet_ntop(AF_INET, (void*)&((struct sockaddr_in*)sa)->sin_addr, tmp, sizeof tmp);
177-
#endif
181+
const char* s = inet_ntop_wrapper(AF_INET, &((struct sockaddr_in*)sa)->sin_addr, tmp, sizeof tmp);
178182
return { std::string(s), ntohs(((struct sockaddr_in*)sa)->sin_port) };
179183
}
180184

181185
std::tuple<std::string, uint16_t> endpoint::get_inet6() const noexcept {
182186
const sockaddr* sa = addr();
183187
char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"];
184-
#if !defined(__MINGW32__)
185-
const char* s = inet_ntop(AF_INET6, (const void*)&((const struct sockaddr_in6*)sa)->sin6_addr, tmp, sizeof tmp);
186-
#else
187-
const char* s = inet_ntop(AF_INET6, (void*)&((const struct sockaddr_in6*)sa)->sin6_addr, tmp, sizeof tmp);
188-
#endif
188+
const char* s = inet_ntop_wrapper(AF_INET6, &((const struct sockaddr_in6*)sa)->sin6_addr, tmp, sizeof tmp);
189189
return { std::string(s), ntohs(((struct sockaddr_in6*)sa)->sin6_port) };
190190
}
191191

bee/net/endpoint.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ namespace bee::net {
4646
socklen_t* out_addrlen() noexcept;
4747
bool operator==(const endpoint& o) const noexcept;
4848
template <typename SOCKADDR>
49-
void assgin(const SOCKADDR& v) noexcept {
49+
void assign(const SOCKADDR& v) noexcept {
5050
m_size = (socklen_t)sizeof(v);
5151
memcpy(m_data, &v, sizeof(v));
5252
}

bee/net/socket.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ namespace bee::net::socket {
4747
initialized = rc == 0;
4848
#else
4949
initialized = true;
50-
# if !defined(MSG_NOSIGNA) && !defined(SO_NOSIGPIPE)
50+
# if !defined(MSG_NOSIGNAL) && !defined(SO_NOSIGPIPE)
5151
struct sigaction sa;
5252
sa.sa_handler = SIG_IGN;
5353
sa.sa_flags = 0;

bee/subprocess/subprocess_posix.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include <bee/subprocess.h>
55
#include <bee/utility/dynarray.h>
66
#include <errno.h>
7-
#include <memory.h>
87
#include <signal.h>
98
#include <spawn.h>
109
#include <sys/socket.h>
@@ -13,6 +12,7 @@
1312
#include <unistd.h>
1413

1514
#include <cassert>
15+
#include <cstring>
1616

1717
#if defined(__APPLE__)
1818
# include <crt_externs.h>
@@ -69,7 +69,7 @@ namespace bee::subprocess {
6969
std::vector<char*> envs;
7070
for (; *es; ++es) {
7171
std::string str = *es;
72-
auto pos = str.find(L'=');
72+
auto pos = str.find('=');
7373
std::string key = str.substr(0, pos);
7474
std::string val = str.substr(pos + 1, str.length());
7575
auto it = set_env_.find(key);

bee/win/unicode.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <bee/win/unicode.h>
33

44
namespace bee::win {
5-
std::wstring u2w(zstring_view str) noexcept {
5+
static std::wstring u2w(zstring_view str) noexcept {
66
if (str.empty()) {
77
return L"";
88
}
@@ -15,7 +15,7 @@ namespace bee::win {
1515
return wresult;
1616
}
1717

18-
std::string w2u(wzstring_view wstr) noexcept {
18+
static std::string w2u(wzstring_view wstr) noexcept {
1919
if (wstr.empty()) {
2020
return "";
2121
}
@@ -28,7 +28,7 @@ namespace bee::win {
2828
return result;
2929
}
3030

31-
std::wstring a2w(zstring_view str) noexcept {
31+
static std::wstring a2w(zstring_view str) noexcept {
3232
if (str.empty()) {
3333
return L"";
3434
}
@@ -41,7 +41,7 @@ namespace bee::win {
4141
return wresult;
4242
}
4343

44-
std::string w2a(wzstring_view wstr) noexcept {
44+
static std::string w2a(wzstring_view wstr) noexcept {
4545
if (wstr.empty()) {
4646
return "";
4747
}

bee/win/unicode.h

-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
#include <string>
66

77
namespace bee::win {
8-
std::wstring u2w(zstring_view str) noexcept;
9-
std::string w2u(wzstring_view wstr) noexcept;
10-
std::wstring a2w(zstring_view str) noexcept;
11-
std::string w2a(wzstring_view wstr) noexcept;
128
std::string a2u(zstring_view str) noexcept;
139
std::string u2a(zstring_view str) noexcept;
1410
}

0 commit comments

Comments
 (0)