Skip to content

Commit 5356eb9

Browse files
committed
format
1 parent 78b61a6 commit 5356eb9

14 files changed

+81
-24
lines changed

Diff for: .DS_Store

-6 KB
Binary file not shown.

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ Pods/
2727
Podfile.lock
2828

2929
.DS_Store
30+
31+
__MACOSX/

Diff for: CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#Changelog
22

3+
## 0.0.6 (2018-02-21)
4+
### 修正
5+
* 增加一些null检查
6+
37
## 0.0.6 (2017-08-1)
48
### 修正
59
* xcode 9 编译错误

Diff for: NetDiag.xcodeproj/project.pbxproj

+17-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@
243243
DFCEC63D1C2EC01D0058EE65 /* Project object */ = {
244244
isa = PBXProject;
245245
attributes = {
246-
LastUpgradeCheck = 0720;
246+
LastUpgradeCheck = 0920;
247247
ORGANIZATIONNAME = "Qiniu Cloud Storage";
248248
TargetAttributes = {
249249
DF8DFFCE1C61DA1B00174DA9 = {
@@ -456,13 +456,21 @@
456456
CLANG_CXX_LIBRARY = "libc++";
457457
CLANG_ENABLE_MODULES = YES;
458458
CLANG_ENABLE_OBJC_ARC = YES;
459+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
459460
CLANG_WARN_BOOL_CONVERSION = YES;
461+
CLANG_WARN_COMMA = YES;
460462
CLANG_WARN_CONSTANT_CONVERSION = YES;
461463
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
462464
CLANG_WARN_EMPTY_BODY = YES;
463465
CLANG_WARN_ENUM_CONVERSION = YES;
466+
CLANG_WARN_INFINITE_RECURSION = YES;
464467
CLANG_WARN_INT_CONVERSION = YES;
468+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
469+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
465470
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
471+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
472+
CLANG_WARN_STRICT_PROTOTYPES = YES;
473+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
466474
CLANG_WARN_UNREACHABLE_CODE = YES;
467475
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
468476
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -499,13 +507,21 @@
499507
CLANG_CXX_LIBRARY = "libc++";
500508
CLANG_ENABLE_MODULES = YES;
501509
CLANG_ENABLE_OBJC_ARC = YES;
510+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
502511
CLANG_WARN_BOOL_CONVERSION = YES;
512+
CLANG_WARN_COMMA = YES;
503513
CLANG_WARN_CONSTANT_CONVERSION = YES;
504514
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
505515
CLANG_WARN_EMPTY_BODY = YES;
506516
CLANG_WARN_ENUM_CONVERSION = YES;
517+
CLANG_WARN_INFINITE_RECURSION = YES;
507518
CLANG_WARN_INT_CONVERSION = YES;
519+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
520+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
508521
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
522+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
523+
CLANG_WARN_STRICT_PROTOTYPES = YES;
524+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
509525
CLANG_WARN_UNREACHABLE_CODE = YES;
510526
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
511527
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";

Diff for: NetDiag.xcodeproj/xcshareddata/xcschemes/NetDiag.xcscheme

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0720"
3+
LastUpgradeVersion = "0920"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -26,6 +26,7 @@
2626
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
language = ""
2930
shouldUseLaunchSchemeArgsEnv = "YES">
3031
<Testables>
3132
<TestableReference
@@ -55,6 +56,7 @@
5556
buildConfiguration = "Debug"
5657
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
5758
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
59+
language = ""
5860
launchStyle = "0"
5961
useCustomWorkingDirectory = "NO"
6062
ignoresPersistentStateOnLaunch = "NO"

Diff for: NetDiag.xcodeproj/xcshareddata/xcschemes/NetDiagTests.xcscheme

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0720"
3+
LastUpgradeVersion = "0920"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -26,6 +26,7 @@
2626
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
language = ""
2930
shouldUseLaunchSchemeArgsEnv = "YES">
3031
<Testables>
3132
<TestableReference
@@ -46,6 +47,7 @@
4647
buildConfiguration = "Debug"
4748
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
4849
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
50+
language = ""
4951
launchStyle = "0"
5052
useCustomWorkingDirectory = "NO"
5153
ignoresPersistentStateOnLaunch = "NO"

Diff for: NetDiag/QNNHttp.m

+16-6
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ - (instancetype)init:(NSString *)url
5353
output:(id<QNNOutputDelegate>)output
5454
complete:(QNNHttpCompleteHandler)complete {
5555
if (self = [super init]) {
56-
_url = url;
56+
_url = url == nil ? @"" : url;
5757
_output = output;
5858
_complete = complete;
5959
}
@@ -62,16 +62,23 @@ - (instancetype)init:(NSString *)url
6262

6363
- (NSString *)reserveUrlToIp {
6464
NSString *ip = nil;
65-
NSString *urlStr = [[_url componentsSeparatedByString:@"//"] lastObject];
66-
65+
NSURL *url = [NSURL URLWithString:_url];
66+
NSString *domain = url.host;
67+
if (domain == nil) {
68+
domain = @"";
69+
}
70+
const char *d = [domain UTF8String];
71+
if (d == NULL) {
72+
d = "\0";
73+
}
6774
struct sockaddr_in addr;
6875
memset(&addr, 0, sizeof(addr));
6976
addr.sin_len = sizeof(addr);
7077
addr.sin_family = AF_INET;
7178
addr.sin_port = htons(80);
72-
addr.sin_addr.s_addr = inet_addr([urlStr UTF8String]);
79+
addr.sin_addr.s_addr = inet_addr(d);
7380
if (addr.sin_addr.s_addr == INADDR_NONE) {
74-
struct hostent *host = gethostbyname([urlStr UTF8String]);
81+
struct hostent *host = gethostbyname(d);
7582
if (host == NULL || host->h_addr == NULL) {
7683
return ip;
7784
}
@@ -123,6 +130,9 @@ - (void)run {
123130
+ (instancetype)start:(NSString *)url
124131
output:(id<QNNOutputDelegate>)output
125132
complete:(QNNHttpCompleteHandler)complete {
133+
if (url == nil) {
134+
url = @"";
135+
}
126136
QNNHttp *http = [[QNNHttp alloc] init:url output:output complete:complete];
127137
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
128138
[http run];
@@ -133,4 +143,4 @@ + (instancetype)start:(NSString *)url
133143
- (void)stop {
134144
}
135145

136-
@end
146+
@end

Diff for: NetDiag/QNNNslookup.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ - (instancetype)init:(NSString *)domain
124124
output:(id<QNNOutputDelegate>)output
125125
complete:(QNNNslookupCompleteHandler)complete {
126126
if (self = [super init]) {
127-
_domain = domain;
127+
_domain = domain == nil ? @"" : domain;
128128
_dnsServer = dnsServer;
129129
_output = output;
130130
_complete = complete;

Diff for: NetDiag/QNNPing.m

+11-2
Original file line numberDiff line numberDiff line change
@@ -312,15 +312,21 @@ - (QNNPingResult *)buildResult:(NSInteger)code
312312
}
313313

314314
- (void)run {
315+
const char *hostaddr = [_host UTF8String];
316+
if (hostaddr == NULL) {
317+
hostaddr = "\0";
318+
}
319+
315320
NSDate *begin = [NSDate date];
316321
struct sockaddr_in addr;
317322
memset(&addr, 0, sizeof(addr));
318323
addr.sin_len = sizeof(addr);
319324
addr.sin_family = AF_INET;
320325
addr.sin_port = htons(30002);
321-
addr.sin_addr.s_addr = inet_addr([_host UTF8String]);
326+
addr.sin_addr.s_addr = inet_addr(hostaddr);
327+
322328
if (addr.sin_addr.s_addr == INADDR_NONE) {
323-
struct hostent *host = gethostbyname([_host UTF8String]);
329+
struct hostent *host = gethostbyname(hostaddr);
324330
if (host == NULL || host->h_addr == NULL) {
325331
[self.output write:@"Problem accessing the DNS"];
326332
if (_complete != nil) {
@@ -415,6 +421,9 @@ + (instancetype)start:(NSString *)host
415421
complete:(QNNPingCompleteHandler)complete
416422
interval:(NSInteger)interval
417423
count:(NSInteger)count {
424+
if (host == nil) {
425+
host = @"";
426+
}
418427
QNNPing *ping = [[QNNPing alloc] init:host size:size output:output complete:complete interval:interval count:count];
419428
[QNNQue async_run_serial:^{
420429
[ping run];

Diff for: NetDiag/QNNRtmp.m

+7-3
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ - (instancetype)init:(NSString*)host
200200
complete:(QNNRtmpHandshakeCompleteHandler)complete
201201
count:(NSInteger)count {
202202
if (self = [super init]) {
203-
_host = host;
203+
_host = host == nil ? @"" : host;
204204
_port = port;
205205
_output = output;
206206
_complete = complete;
@@ -217,7 +217,11 @@ - (void)run {
217217
addr.sin_len = sizeof(addr);
218218
addr.sin_family = AF_INET;
219219
addr.sin_port = htons(_port);
220-
addr.sin_addr.s_addr = inet_addr([_host UTF8String]);
220+
const char* hostaddr = [_host UTF8String];
221+
if (hostaddr == NULL) {
222+
hostaddr = "\0";
223+
}
224+
addr.sin_addr.s_addr = inet_addr(hostaddr);
221225
if (addr.sin_addr.s_addr == INADDR_NONE) {
222226
struct hostent* host = gethostbyname([_host UTF8String]);
223227
if (host == NULL || host->h_addr == NULL) {
@@ -368,4 +372,4 @@ - (void)stop {
368372
_stopped = YES;
369373
}
370374

371-
@end
375+
@end

Diff for: NetDiag/QNNTcpPing.m

+7-3
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ - (instancetype)init:(NSString *)host
8383
complete:(QNNTcpPingCompleteHandler)complete
8484
count:(NSInteger)count {
8585
if (self = [super init]) {
86-
_host = host;
86+
_host = host == nil ? @"" : host;
8787
_port = port;
8888
_output = output;
8989
_complete = complete;
@@ -101,9 +101,13 @@ - (void)run {
101101
addr.sin_len = sizeof(addr);
102102
addr.sin_family = AF_INET;
103103
addr.sin_port = htons(_port);
104-
addr.sin_addr.s_addr = inet_addr([_host UTF8String]);
104+
const char *hostaddr = [_host UTF8String];
105+
if (hostaddr == NULL) {
106+
hostaddr = "\0";
107+
}
108+
addr.sin_addr.s_addr = inet_addr(hostaddr);
105109
if (addr.sin_addr.s_addr == INADDR_NONE) {
106-
struct hostent *host = gethostbyname([_host UTF8String]);
110+
struct hostent *host = gethostbyname(hostaddr);
107111
if (host == NULL || host->h_addr == NULL) {
108112
[self.output write:@"Problem accessing the DNS"];
109113
if (_complete != nil) {

Diff for: NetDiag/QNNTraceRoute.m

+7-3
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ - (instancetype)init:(NSString*)host
9797
complete:(QNNTraceRouteCompleteHandler)complete
9898
maxTtl:(NSInteger)maxTtl {
9999
if (self = [super init]) {
100-
_host = host;
100+
_host = host == nil ? @"" : host;
101101
_output = output;
102102
_complete = complete;
103103
_maxTtl = maxTtl;
@@ -171,10 +171,14 @@ - (void)run {
171171
addr.sin_len = sizeof(addr);
172172
addr.sin_family = AF_INET;
173173
addr.sin_port = htons(30002);
174-
addr.sin_addr.s_addr = inet_addr([_host UTF8String]);
174+
const char* hostaddr = [_host UTF8String];
175+
if (hostaddr == NULL) {
176+
hostaddr = "\0";
177+
}
178+
addr.sin_addr.s_addr = inet_addr(hostaddr);
175179
[self.output write:[NSString stringWithFormat:@"traceroute to %@ ...\n", _host]];
176180
if (addr.sin_addr.s_addr == INADDR_NONE) {
177-
struct hostent* host = gethostbyname([_host UTF8String]);
181+
struct hostent* host = gethostbyname(hostaddr);
178182
if (host == NULL || host->h_addr == NULL) {
179183
[self.output write:@"Problem accessing the DNS"];
180184
if (_complete != nil) {

Diff for: QNNetDiag.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'QNNetDiag'
3-
s.version = '0.0.6'
3+
s.version = '0.0.7'
44
s.summary = 'Qiniu Net Diagnostic library'
55
s.homepage = 'https://github.com/qiniu/iOS-netdiag'
66
s.social_media_url = 'http://weibo.com/qiniutek'

Diff for: format.sh

100644100755
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
22
# Change this if your clang-format executable is somewhere else
3-
CLANG_FORMAT="$HOME/Library/Application Support/Alcatraz/Plug-ins/ClangFormat/bin/clang-format"
4-
3+
#CLANG_FORMAT="$HOME/Library/Application Support/Alcatraz/Plug-ins/ClangFormat/bin/clang-format"
4+
CLANG_FORMAT=./clang-format
55
find . \( -name '*.h' -or -name '*.m' -or -name '*.mm' \) -print0 | xargs -0 "$CLANG_FORMAT" -i

0 commit comments

Comments
 (0)