aboutsummaryrefslogtreecommitdiff
path: root/Foundation
diff options
context:
space:
mode:
authorGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2014-10-10 20:00:07 +0000
committerGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2014-10-10 20:00:07 +0000
commitfc407a14bdcddb41db5804962b496c4e3e860f78 (patch)
tree932b75ecb43a812b548171f9e178d5c948d17847 /Foundation
parent79de9414ada9b15d2346595501fecb01ce5a1ec6 (diff)
Fix support for file extensions, due to off-by-1 error from not taking the period into account for the total suffix-length to pass to mkstemps.
Example failure: template = myTempXXX.ext pathExtension = "ext" [pathExtension length] = 3 Need for mkstemps: suffix-length = 4 (".ext") DELTA=6 (5 added, 0 deleted, 1 changed) DELTA_BY_EXTENSION=m=6
Diffstat (limited to 'Foundation')
-rw-r--r--Foundation/GTMNSFileHandle+UniqueName.m7
1 files changed, 6 insertions, 1 deletions
diff --git a/Foundation/GTMNSFileHandle+UniqueName.m b/Foundation/GTMNSFileHandle+UniqueName.m
index 536e154..d373159 100644
--- a/Foundation/GTMNSFileHandle+UniqueName.m
+++ b/Foundation/GTMNSFileHandle+UniqueName.m
@@ -28,7 +28,12 @@
NSString *extension = [pathTemplate pathExtension];
char *pathTemplateCString = strdup([pathTemplate fileSystemRepresentation]);
if (!pathTemplateCString) return nil;
- int fileDescriptor = mkstemps(pathTemplateCString, (int)[extension length]);
+ int len = (int)[extension length];
+ if (len > 0) {
+ // Suffix length needs to include a period.
+ len++;
+ }
+ int fileDescriptor = mkstemps(pathTemplateCString, len);
if (fileDescriptor == -1) {
free(pathTemplateCString);
return nil;