Overview
Context
Changes
Modified src/OFData.m
from [6b96716473]
to [753e5c551b].
︙ | | |
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
|
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
|
-
-
-
-
-
+
-
-
-
+
-
-
-
-
+
-
-
-
+
-
-
-
-
-
+
-
-
-
-
-
-
+
+
|
{
OF_INVALID_INIT_METHOD
}
#ifdef OF_HAVE_FILES
- (instancetype)initWithContentsOfFile: (OFString *)path
{
char *buffer = NULL;
OFStreamOffset fileSize;
@try {
void *pool = objc_autoreleasePoolPush();
void *pool = objc_autoreleasePoolPush();
OFFile *file = [OFFile fileWithPath: path mode: @"r"];
fileSize = [file seekToOffset: 0 whence: OFSeekEnd];
OFIRI *IRI;
if (fileSize < 0 || (unsigned long long)fileSize > SIZE_MAX)
@throw [OFOutOfRangeException exception];
[file seekToOffset: 0 whence: OFSeekSet];
@try {
buffer = OFAllocMemory((size_t)fileSize, 1);
[file readIntoBuffer: buffer exactLength: (size_t)fileSize];
IRI = [OFIRI fileIRIWithPath: path];
objc_autoreleasePoolPop(pool);
} @catch (id e) {
OFFreeMemory(buffer);
[self release];
@throw e;
}
@try {
self = [self initWithItemsNoCopy: buffer
self = [self initWithContentsOfIRI: IRI];
count: (size_t)fileSize
freeWhenDone: true];
} @catch (id e) {
OFFreeMemory(buffer);
@throw e;
}
objc_autoreleasePoolPop(pool);
return self;
}
#endif
- (instancetype)initWithContentsOfIRI: (OFIRI *)IRI
{
|
︙ | | |
Modified src/OFString.m
from [ed5e3faeac]
to [c29f20e2b2].
︙ | | |
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
|
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
|
-
-
-
-
-
+
-
-
-
+
-
-
-
-
-
-
-
-
-
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
+
-
+
|
return [self initWithContentsOfFile: path
encoding: OFStringEncodingUTF8];
}
- (instancetype)initWithContentsOfFile: (OFString *)path
encoding: (OFStringEncoding)encoding
{
char *buffer = NULL;
OFStreamOffset fileSize;
@try {
void *pool = objc_autoreleasePoolPush();
void *pool = objc_autoreleasePoolPush();
OFFile *file = [OFFile fileWithPath: path mode: @"r"];
fileSize = [file seekToOffset: 0 whence: OFSeekEnd];
OFIRI *IRI;
if (fileSize < 0 || (unsigned long long)fileSize > SIZE_MAX)
@throw [OFOutOfRangeException exception];
/*
* We need one extra byte for the terminating zero if we want
* to use -[initWithUTF8StringNoCopy:length:freeWhenDone:].
*/
if (SIZE_MAX - (size_t)fileSize < 1)
@throw [OFOutOfRangeException exception];
@try {
[file seekToOffset: 0 whence: OFSeekSet];
IRI = [OFIRI fileIRIWithPath: path];
buffer = OFAllocMemory((size_t)fileSize + 1, 1);
[file readIntoBuffer: buffer exactLength: (size_t)fileSize];
buffer[(size_t)fileSize] = '\0';
objc_autoreleasePoolPop(pool);
} @catch (id e) {
OFFreeMemory(buffer);
[self release];
@throw e;
}
if (encoding == OFStringEncodingUTF8) {
@try {
self = [self initWithUTF8StringNoCopy: buffer
length: (size_t)fileSize
freeWhenDone: true];
} @catch (id e) {
OFFreeMemory(buffer);
@throw e;
}
} else {
@try {
self = [self initWithCString: buffer
self = [self initWithContentsOfIRI: IRI encoding: encoding];
encoding: encoding
length: (size_t)fileSize];
} @finally {
OFFreeMemory(buffer);
}
}
objc_autoreleasePoolPop(pool);
return self;
}
#endif
- (instancetype)initWithContentsOfIRI: (OFIRI *)IRI
{
|
︙ | | |