Skip to content

Commit 84b0a3d

Browse files
author
Rob Rix
committed
Copy configuration strings out into a buffer.
1 parent 9539a4f commit 84b0a3d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

ObjectiveGit/GTConfiguration.m

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#import "git2/config.h"
1717
#import "git2/errors.h"
18+
#import "git2/buffer.h"
1819

1920
@interface GTConfiguration ()
2021
@property (nonatomic, readonly, assign) git_config *git_config;
@@ -58,11 +59,13 @@ - (void)setString:(NSString *)s forKey:(NSString *)key {
5859
}
5960

6061
- (NSString *)stringForKey:(NSString *)key {
61-
const char *string = NULL;
62-
git_config_get_string(&string, self.git_config, key.UTF8String);
63-
if (string == NULL) return nil;
62+
git_buf buffer = {};
63+
if (git_config_get_string_buf(&buffer, self.git_config, key.UTF8String) != 0) return nil;
6464

65-
return [NSString stringWithUTF8String:string];
65+
NSString *string = [[NSString alloc] initWithBytes:buffer.ptr length:buffer.size encoding:NSUTF8StringEncoding];
66+
git_buf_free(&buffer);
67+
68+
return string;
6669
}
6770

6871
- (void)setBool:(BOOL)b forKey:(NSString *)key {

0 commit comments

Comments
 (0)