Skip to content
Permalink
Browse files

Cast NSInteger to long for formatting as %ld

In https://crbug.com/747643, a new version of Clang produces warnings
when attempting to format NSInteger as %zd (which is normally used for
ssize_t). Acquiesce by casting NSInteger to long and formatting using
%ld.

In the process, I audited all occurrences of %zd in GTM and found that
the remainder were being used to format size_t, which ought to use %zu,
so I’ve corrected those.

I also audited the existing uses of %zu and found them all to be
correct.
  • Loading branch information...
markmentovai authored and sergiocampama committed Jul 24, 2017
1 parent ec72a2b commit 3c3111d3aefe907c8c0f0e933029608d96ceefeb
Showing with 6 additions and 6 deletions.
  1. +2 −2 Foundation/GTMGeometryUtilsTest.m
  2. +1 −1 Foundation/GTMRegex.m
  3. +2 −2 UnitTesting/GTMSenTestCase.h
  4. +1 −1 iPhone/GTMUIImage+Resize.m
@@ -125,7 +125,7 @@ - (void)testGTMNSScaleRectangleToSize {
NSRect result = GTMNSScaleRectangleToSize(rect, tests[i].size_,
GTMScaleProportionally);
XCTAssertTrue(NSEqualRects(result, GTMNSRectOfSize(tests[i].newSize_)),
@"failed on test %zd", i);
@"failed on test %zu", i);
}

NSRect result = GTMNSScaleRectangleToSize(NSZeroRect, tests[0].size_,
@@ -288,7 +288,7 @@ - (void)testGTMCGScaleRectangleToSize {
CGRect result = GTMCGScaleRectangleToSize(rect, tests[i].size_,
GTMScaleProportionally);
XCTAssertTrue(CGRectEqualToRect(result, GTMCGRectOfSize(tests[i].newSize_)),
@"failed on test %zd", i);
@"failed on test %zu", i);
}

CGRect result = GTMCGScaleRectangleToSize(CGRectZero, tests[0].size_,
@@ -410,7 +410,7 @@ - (NSString *)stringByReplacingMatchesInString:(NSString *)str

- (NSString *)description {
NSMutableString *result =
[NSMutableString stringWithFormat:@"%@<%p> { pattern=\"%@\", rawNumSubPatterns=%zd, options=(",
[NSMutableString stringWithFormat:@"%@<%p> { pattern=\"%@\", rawNumSubPatterns=%zu, options=(",
[self class], self, pattern_, regexData_.re_nsub];
if (options_) {
if (options_ & kGTMRegexOptionIgnoreCase)
@@ -223,7 +223,7 @@
} else if (![_a2value isKindOfClass:[NSString class]]) { \
_failure = [NSString stringWithFormat:@"(%@) is not an NSString* (%@)", @#a2, [_a2value class]]; \
} else if ((_result = [_a1value compare:_a2value]) != NSOrderedSame) { \
_failure = [NSString stringWithFormat:@"(%@) vs (%@) == %zd", _a1value, _a2value, (long)_result]; \
_failure = [NSString stringWithFormat:@"(%@) vs (%@) == %ld", _a1value, _a2value, (long)_result]; \
} \
} \
@catch (NSException *_exception) { \
@@ -263,7 +263,7 @@
} else if (![_a2value isKindOfClass:[NSString class]]) { \
_failure = [NSString stringWithFormat:@"(%@) is not an NSString* (%@)", @#a2, [_a2value class]]; \
} else if ((_result = [_a1value compare:_a2value]) == NSOrderedSame) { \
_failure = [NSString stringWithFormat:@"(%@) vs (%@) == %zd", _a1value, _a2value, _result]; \
_failure = [NSString stringWithFormat:@"(%@) vs (%@) == %ld", _a1value, _a2value, (long)_result]; \
} \
} \
@catch (NSException *_exception) { \
@@ -152,7 +152,7 @@ - (UIImage *)gtm_imageByRotating:(UIImageOrientation)orientation {
break;

default:
_GTMDevAssert(false, @"Invalid orientation %zd", orientation);
_GTMDevAssert(false, @"Invalid orientation %ld", (long)orientation);
return nil;
}

0 comments on commit 3c3111d

Please sign in to comment.
You can’t perform that action at this time.