5
5
#include " flutter/shell/platform/darwin/common/framework/Source/FlutterStandardCodecHelper.h"
6
6
#include < stdint.h>
7
7
8
+ #include < vector>
9
+
8
10
void FlutterStandardCodecHelperReadAlignment (unsigned long * location,
9
11
uint8_t alignment) {
10
12
uint8_t mod = *location % alignment;
@@ -25,7 +27,7 @@ void FlutterStandardCodecHelperReadBytes(unsigned long* location,
25
27
void * destination,
26
28
CFDataRef data) {
27
29
CFRange range = CFRangeMake (*location, length);
28
- CFDataGetBytes (data , range , destination );
30
+ CFDataGetBytes (data, range, static_cast < UInt8 *>( destination) );
29
31
*location += length;
30
32
}
31
33
@@ -59,7 +61,7 @@ static CFDataRef ReadDataNoCopy(unsigned long* location,
59
61
kCFAllocatorDefault , CFDataGetBytePtr (data) + *location, length,
60
62
kCFAllocatorNull );
61
63
*location += length;
62
- return CFAutorelease (result );
64
+ return static_cast < CFDataRef >( CFAutorelease (result) );
63
65
}
64
66
65
67
CFStringRef FlutterStandardCodecHelperReadUTF8 (unsigned long * location,
@@ -68,7 +70,7 @@ CFStringRef FlutterStandardCodecHelperReadUTF8(unsigned long* location,
68
70
CFDataRef bytes = ReadDataNoCopy (location, size, data);
69
71
CFStringRef result = CFStringCreateFromExternalRepresentation (
70
72
kCFAllocatorDefault , bytes, kCFStringEncodingUTF8 );
71
- return CFAutorelease (result );
73
+ return static_cast < CFStringRef >( CFAutorelease (result) );
72
74
}
73
75
74
76
// Peeks ahead to see if we are reading a standard type. If so, recurse
@@ -172,7 +174,7 @@ void FlutterStandardCodecHelperWriteByte(CFMutableDataRef data, uint8_t value) {
172
174
void FlutterStandardCodecHelperWriteBytes (CFMutableDataRef data,
173
175
const void * bytes,
174
176
unsigned long length) {
175
- CFDataAppendBytes (data , bytes , length );
177
+ CFDataAppendBytes (data, static_cast < const UInt8 *>( bytes) , length);
176
178
}
177
179
178
180
void FlutterStandardCodecHelperWriteSize (CFMutableDataRef data, uint32_t size) {
@@ -210,12 +212,12 @@ void FlutterStandardCodecHelperWriteUTF8(CFMutableDataRef data,
210
212
CFIndex used_length = 0 ;
211
213
// UTF16 length times 3 will fit all UTF8.
212
214
CFIndex buffer_length = length * 3 ;
213
- UInt8 * buffer = (UInt8 * )malloc (buffer_length * sizeof (UInt8 ));
215
+ std::vector<UInt8 > buffer;
216
+ buffer.reserve (buffer_length);
214
217
CFStringGetBytes (value, CFRangeMake (0 , length), kCFStringEncodingUTF8 , 0 ,
215
- false, buffer , buffer_length , & used_length );
218
+ false , buffer. data () , buffer_length, &used_length);
216
219
FlutterStandardCodecHelperWriteSize (data, used_length);
217
- FlutterStandardCodecHelperWriteBytes (data , buffer , used_length );
218
- free (buffer );
220
+ FlutterStandardCodecHelperWriteBytes (data, buffer.data (), used_length);
219
221
}
220
222
}
221
223
0 commit comments