Skip to content
This repository was archived by the owner on Aug 5, 2024. It is now read-only.

Commit 3a00a83

Browse files
committed
ObjectiveC: Stop doing bounds checking and rely on exception-catching
1 parent 8e5241b commit 3a00a83

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

objectivec/DiffMatchPatch.m

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,13 +1368,7 @@ - (int)diff_digit16:(unichar)c
13681368

13691369
- (NSString *)diff_decodeURIWithText:(NSString *)percentEncoded
13701370
{
1371-
NSInteger inputLength = [percentEncoded length];
1372-
1373-
if (0 == inputLength) {
1374-
return @"";
1375-
}
1376-
1377-
unichar decoded[inputLength];
1371+
unichar decoded[[percentEncoded length]];
13781372
NSInteger input = 0;
13791373
NSInteger output = 0;
13801374

@@ -1388,10 +1382,6 @@ - (NSString *)diff_decodeURIWithText:(NSString *)percentEncoded
13881382
continue;
13891383
}
13901384

1391-
if (inputLength < input + 3) {
1392-
return nil;
1393-
}
1394-
13951385
int byte1 = ([self diff_digit16:[percentEncoded characterAtIndex:(input+1)]] << 4) +
13961386
[self diff_digit16:[percentEncoded characterAtIndex:(input+2)]];
13971387

@@ -1401,7 +1391,7 @@ - (NSString *)diff_decodeURIWithText:(NSString *)percentEncoded
14011391
continue;
14021392
}
14031393

1404-
if (inputLength < input + 6 || '%' != [percentEncoded characterAtIndex:(input + 3)]) {
1394+
if ('%' != [percentEncoded characterAtIndex:(input + 3)]) {
14051395
return nil;
14061396
}
14071397

@@ -1420,7 +1410,7 @@ - (NSString *)diff_decodeURIWithText:(NSString *)percentEncoded
14201410
continue;
14211411
}
14221412

1423-
if (inputLength < input + 9 || '%' != [percentEncoded characterAtIndex:(input + 6)]) {
1413+
if ('%' != [percentEncoded characterAtIndex:(input + 6)]) {
14241414
return nil;
14251415
}
14261416

@@ -1439,7 +1429,7 @@ - (NSString *)diff_decodeURIWithText:(NSString *)percentEncoded
14391429
continue;
14401430
}
14411431

1442-
if (inputLength < input + 12 || '%' != [percentEncoded characterAtIndex:(input + 9)]) {
1432+
if ('%' != [percentEncoded characterAtIndex:(input + 9)]) {
14431433
return nil;
14441434
}
14451435

0 commit comments

Comments
 (0)