5
5
#include " flutter/shell/platform/darwin/common/framework/Source/FlutterStandardCodecHelper.h"
6
6
#include < stdint.h>
7
7
8
+ #include < vector>
9
+
10
+ #include " flutter/fml/logging.h"
11
+
12
+ // The google-runtime-int lint suggests uint64_t in place of unsigned long,
13
+ // however these functions are frequently used with NSUInteger, which is
14
+ // defined as an unsigned long.
15
+ //
16
+ // NOLINTBEGIN(google-runtime-int)
17
+
8
18
void FlutterStandardCodecHelperReadAlignment (unsigned long * location,
9
19
uint8_t alignment) {
10
20
uint8_t mod = *location % alignment;
@@ -25,7 +35,7 @@ void FlutterStandardCodecHelperReadBytes(unsigned long* location,
25
35
void * destination,
26
36
CFDataRef data) {
27
37
CFRange range = CFRangeMake (*location, length);
28
- CFDataGetBytes (data , range , destination );
38
+ CFDataGetBytes (data, range, static_cast < UInt8 *>( destination) );
29
39
*location += length;
30
40
}
31
41
@@ -59,7 +69,7 @@ static CFDataRef ReadDataNoCopy(unsigned long* location,
59
69
kCFAllocatorDefault , CFDataGetBytePtr (data) + *location, length,
60
70
kCFAllocatorNull );
61
71
*location += length;
62
- return CFAutorelease (result );
72
+ return static_cast < CFDataRef >( CFAutorelease (result) );
63
73
}
64
74
65
75
CFStringRef FlutterStandardCodecHelperReadUTF8 (unsigned long * location,
@@ -68,7 +78,7 @@ CFStringRef FlutterStandardCodecHelperReadUTF8(unsigned long* location,
68
78
CFDataRef bytes = ReadDataNoCopy (location, size, data);
69
79
CFStringRef result = CFStringCreateFromExternalRepresentation (
70
80
kCFAllocatorDefault , bytes, kCFStringEncodingUTF8 );
71
- return CFAutorelease (result );
81
+ return static_cast < CFStringRef >( CFAutorelease (result) );
72
82
}
73
83
74
84
// Peeks ahead to see if we are reading a standard type. If so, recurse
@@ -161,7 +171,7 @@ CFTypeRef FlutterStandardCodecHelperReadValueOfType(
161
171
}
162
172
default :
163
173
// Malformed message.
164
- assert (false);
174
+ FML_DCHECK (false );
165
175
}
166
176
}
167
177
@@ -172,7 +182,7 @@ void FlutterStandardCodecHelperWriteByte(CFMutableDataRef data, uint8_t value) {
172
182
void FlutterStandardCodecHelperWriteBytes (CFMutableDataRef data,
173
183
const void * bytes,
174
184
unsigned long length) {
175
- CFDataAppendBytes (data , bytes , length );
185
+ CFDataAppendBytes (data, static_cast < const UInt8 *>( bytes) , length);
176
186
}
177
187
178
188
void FlutterStandardCodecHelperWriteSize (CFMutableDataRef data, uint32_t size) {
@@ -210,12 +220,12 @@ void FlutterStandardCodecHelperWriteUTF8(CFMutableDataRef data,
210
220
CFIndex used_length = 0 ;
211
221
// UTF16 length times 3 will fit all UTF8.
212
222
CFIndex buffer_length = length * 3 ;
213
- UInt8 * buffer = (UInt8 * )malloc (buffer_length * sizeof (UInt8 ));
223
+ std::vector<UInt8 > buffer;
224
+ buffer.reserve (buffer_length);
214
225
CFStringGetBytes (value, CFRangeMake (0 , length), kCFStringEncodingUTF8 , 0 ,
215
- false, buffer , buffer_length , & used_length );
226
+ false , buffer. data () , buffer_length, &used_length);
216
227
FlutterStandardCodecHelperWriteSize (data, used_length);
217
- FlutterStandardCodecHelperWriteBytes (data , buffer , used_length );
218
- free (buffer );
228
+ FlutterStandardCodecHelperWriteBytes (data, buffer.data (), used_length);
219
229
}
220
230
}
221
231
@@ -259,3 +269,5 @@ bool FlutterStandardCodecHelperWriteNumber(CFMutableDataRef data,
259
269
}
260
270
return success;
261
271
}
272
+
273
+ // NOLINTEND(google-runtime-int)
0 commit comments