@@ -215,7 +215,7 @@ impl Log for AndroidLogger {
215
215
// tag longer than LOGGING_TAG_MAX_LEN causes allocation
216
216
let mut tag_bytes: [ MaybeUninit < u8 > ; LOGGING_TAG_MAX_LEN + 1 ] = uninit_array ( ) ;
217
217
218
- let module_path = record. module_path ( ) . unwrap_or_default ( ) . to_owned ( ) ;
218
+ let module_path = record. module_path ( ) . unwrap_or_default ( ) ;
219
219
220
220
// If no tag was specified, use module name
221
221
let custom_tag = & config. tag ;
@@ -225,18 +225,21 @@ impl Log for AndroidLogger {
225
225
. unwrap_or_else ( || module_path. as_bytes ( ) ) ;
226
226
227
227
// In case we end up allocating, keep the CString alive.
228
- let mut _owned_tag = None ;
228
+ let _owned_tag;
229
229
let tag: & CStr = if tag. len ( ) < tag_bytes. len ( ) {
230
230
// use stack array as C string
231
231
self . fill_tag_bytes ( & mut tag_bytes, tag) ;
232
232
// SAFETY: fill_tag_bytes always puts a nullbyte in tag_bytes.
233
233
unsafe { CStr :: from_ptr ( mem:: transmute ( tag_bytes. as_ptr ( ) ) ) }
234
234
} else {
235
235
// Tag longer than available stack buffer; allocate.
236
- // SAFETY: if tag contains nullbytes, the Android logger will just ignore any
237
- // characters that follow it.
238
- _owned_tag = Some ( unsafe { CString :: from_vec_unchecked ( tag. to_vec ( ) ) } ) ;
239
- _owned_tag. as_ref ( ) . unwrap ( )
236
+ // We're using either
237
+ // - CString::as_bytes on config.tag, or
238
+ // - str::as_bytes on record.module_path()
239
+ // Neither of those include the terminating nullbyte.
240
+ _owned_tag = CString :: new ( tag)
241
+ . expect ( "config.tag or record.module_path() should never contain nullbytes" ) ;
242
+ _owned_tag. as_ref ( )
240
243
} ;
241
244
242
245
// message must not exceed LOGGING_MSG_MAX_LEN
0 commit comments