[google-toolbox-for-mac] r692 committed - Fix support for file extensions, due to off-by-1 error from not taking...

38 views
Skip to first unread message

google-tool...@googlecode.com

unread,
Oct 10, 2014, 4:00:20 PM10/10/14
to google-tool...@googlegroups.com
Revision: 692
Author: gtm.daemon
Date: Fri Oct 10 20:00:07 2014 UTC
Log: 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
https://code.google.com/p/google-toolbox-for-mac/source/detail?r=692

Modified:
/trunk/Foundation/GTMNSFileHandle+UniqueName.m

=======================================
--- /trunk/Foundation/GTMNSFileHandle+UniqueName.m Thu Jun 21 23:30:12 2012
UTC
+++ /trunk/Foundation/GTMNSFileHandle+UniqueName.m Fri Oct 10 20:00:07 2014
UTC
@@ -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;
Reply all
Reply to author
Forward
0 new messages