|
@@ -209,14 +209,15 @@ RCT_EXPORT_METHOD(createFileASCII:(NSString *)path data:(NSArray *)dataArray cal
|
209
|
209
|
|
210
|
210
|
NSFileManager * fm = [NSFileManager defaultManager];
|
211
|
211
|
NSMutableData * fileContent = [NSMutableData alloc];
|
212
|
|
-
|
213
|
|
- char bytes[[dataArray count]];
|
|
212
|
+ // prevent stack overflow, alloc on heap
|
|
213
|
+ char * bytes = (char*) malloc([dataArray count]);
|
|
214
|
+// char bytes[[dataArray count]];
|
214
|
215
|
for(int i = 0; i < dataArray.count; i++) {
|
215
|
216
|
bytes[i] = [[dataArray objectAtIndex:i] charValue];
|
216
|
217
|
}
|
217
|
218
|
[fileContent appendBytes:bytes length:dataArray.count];
|
218
|
219
|
BOOL success = [fm createFileAtPath:path contents:fileContent attributes:NULL];
|
219
|
|
-
|
|
220
|
+ free(bytes);
|
220
|
221
|
if(success == YES)
|
221
|
222
|
callback(@[[NSNull null]]);
|
222
|
223
|
else
|
|
@@ -259,13 +260,15 @@ RCT_EXPORT_METHOD(writeStream:(NSString *)path withEncoding:(NSString *)encoding
|
259
|
260
|
|
260
|
261
|
RCT_EXPORT_METHOD(writeArrayChunk:(NSString *)streamId withArray:(NSArray *)dataArray callback:(RCTResponseSenderBlock) callback) {
|
261
|
262
|
RNFetchBlobFS *fs = [[RNFetchBlobFS getFileStreams] valueForKey:streamId];
|
262
|
|
- char bytes[[dataArray count]];
|
|
263
|
+// char bytes[[dataArray count]];
|
|
264
|
+ char * bytes = (char *) malloc([dataArray count]);
|
263
|
265
|
for(int i = 0; i < dataArray.count; i++) {
|
264
|
266
|
bytes[i] = [[dataArray objectAtIndex:i] charValue];
|
265
|
267
|
}
|
266
|
268
|
NSMutableData * data = [NSMutableData alloc];
|
267
|
269
|
[data appendBytes:bytes length:dataArray.count];
|
268
|
270
|
[fs write:data];
|
|
271
|
+ free(bytes);
|
269
|
272
|
callback(@[[NSNull null]]);
|
270
|
273
|
}
|
271
|
274
|
|