Skip to content
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.

Make GTMStringEncoding ARC compliant #98

Open
wants to merge 1 commit into
base: mdh_decode_fix
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion venmo-sdk.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
2D36011F1B8E421A0025196D /* libCMDQueryStringSerialization.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 2D36011E1B8E421A0025196D /* libCMDQueryStringSerialization.a */; };
2D3601211B8E42290025196D /* libSSKeychain.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 2D3601201B8E42290025196D /* libSSKeychain.a */; };
2D3601231B8E429E0025196D /* VENRequestDecoderSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D3601221B8E429E0025196D /* VENRequestDecoderSpec.m */; };
2D3601261B8E55930025196D /* GTMStringEncoding.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D3601241B8E55930025196D /* GTMStringEncoding.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
2D3601261B8E55930025196D /* GTMStringEncoding.m in Sources */ = {isa = PBXBuildFile; fileRef = 2D3601241B8E55930025196D /* GTMStringEncoding.m */; };
2D3601271B8E55930025196D /* GTMStringEncoding.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D3601251B8E55930025196D /* GTMStringEncoding.h */; };
2D3601291B8E592E0025196D /* GTMDefines.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D3601281B8E592E0025196D /* GTMDefines.h */; };
2D5EF54617EF41B100DDD15A /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2D5EF54517EF41B100DDD15A /* Foundation.framework */; };
Expand Down
20 changes: 6 additions & 14 deletions venmo-sdk/Encryption/GTMStringEncoding.m
Original file line number Diff line number Diff line change
Expand Up @@ -89,30 +89,27 @@ GTM_INLINE int lcm(int a, int b) {
}

+ (id)stringEncodingWithString:(NSString *)string {
return [[[self alloc] initWithString:string] autorelease];
return [[self alloc] initWithString:string];
}

- (id)initWithString:(NSString *)string {
if ((self = [super init])) {
charMapData_ = [[string dataUsingEncoding:NSASCIIStringEncoding] retain];
charMapData_ = [string dataUsingEncoding:NSASCIIStringEncoding];
if (!charMapData_) {
_GTMDevLog(@"Unable to convert string to ASCII");
[self release];
return nil;
}
charMap_ = (char *)[charMapData_ bytes];
NSUInteger length = [charMapData_ length];
if (length < 2 || length > 128 || length & (length - 1)) {
_GTMDevLog(@"Length not a power of 2 between 2 and 128");
[self release];
return nil;
}

memset(reverseCharMap_, kUnknownChar, sizeof(reverseCharMap_));
for (unsigned int i = 0; i < length; i++) {
if (reverseCharMap_[(int)charMap_[i]] != kUnknownChar) {
_GTMDevLog(@"Duplicate character at pos %d", i);
[self release];
return nil;
}
reverseCharMap_[(int)charMap_[i]] = i;
Expand All @@ -126,11 +123,6 @@ - (id)initWithString:(NSString *)string {
return self;
}

- (void)dealloc {
[charMapData_ release];
[super dealloc];
}

- (NSString *)description {
// TODO(iwade) track synonyms
return [NSString stringWithFormat:@"<Base%d StringEncoder: %@>",
Expand Down Expand Up @@ -217,8 +209,8 @@ - (NSString *)encode:(NSData *)inData {
_GTMDevAssert(outPos == outLen, @"Underflowed output buffer");
[outData setLength:outPos];

return [[[NSString alloc] initWithData:outData
encoding:NSASCIIStringEncoding] autorelease];
return [[NSString alloc] initWithData:outData
encoding:NSASCIIStringEncoding];
}

- (NSString *)encodeString:(NSString *)inString {
Expand Down Expand Up @@ -282,8 +274,8 @@ - (NSData *)decode:(NSString *)inString {

- (NSString *)stringByDecoding:(NSString *)inString {
NSData *ret = [self decode:inString];
return [[[NSString alloc] initWithData:ret
encoding:NSUTF8StringEncoding] autorelease];
return [[NSString alloc] initWithData:ret
encoding:NSUTF8StringEncoding];
}

@end