@@ -66,7 +66,7 @@ impl SyncRootIdBuilder {
6666 name. len( )
6767 ) ;
6868 assert ! (
69- !name. as_slice( ) . iter ( ) . any ( |c| * c == SyncRootId :: SEPARATOR ) ,
69+ !name. as_slice( ) . contains ( & SyncRootId :: SEPARATOR ) ,
7070 "provider name must not contain exclamation points"
7171 ) ;
7272
@@ -245,7 +245,7 @@ impl SecurityId {
245245 pub fn new ( id : impl AsRef < OsStr > ) -> Self {
246246 let id = U16String :: from_os_str ( & id) ;
247247 assert ! (
248- !id. as_slice( ) . iter ( ) . any ( |x| * x == SyncRootId :: SEPARATOR ) ,
248+ !id. as_slice( ) . contains ( & SyncRootId :: SEPARATOR ) ,
249249 "security id cannot contain exclamation points"
250250 ) ;
251251
@@ -256,31 +256,36 @@ impl SecurityId {
256256 pub fn current_user ( ) -> core:: Result < Self > {
257257 unsafe {
258258 let mut token_size = 0 ;
259- let mut token = MaybeUninit :: < TOKEN_USER > :: uninit ( ) ;
260259
261260 // get the token size
262- if let Err ( e ) = GetTokenInformation (
261+ let info = GetTokenInformation (
263262 Self :: CURRENT_THREAD_EFFECTIVE_TOKEN ,
264263 Security :: TokenUser ,
265264 None ,
266265 0 ,
267266 & mut token_size,
268- ) {
267+ ) ;
268+
269+ if let Err ( e) = info {
269270 if e. code ( ) != ERROR_INSUFFICIENT_BUFFER . to_hresult ( ) {
270271 Err ( e) ?;
271272 }
272- GetTokenInformation (
273- Self :: CURRENT_THREAD_EFFECTIVE_TOKEN ,
274- Security :: TokenUser ,
275- Some ( & mut token as * mut _ as * mut _ ) ,
276- token_size,
277- & mut token_size,
278- ) ?;
279273 }
280274
281- let token = token. assume_init ( ) ;
275+ let mut buffer = Vec :: < MaybeUninit < u8 > > :: with_capacity ( token_size as usize ) ;
276+ buffer. set_len ( token_size as usize ) ;
277+
278+ GetTokenInformation (
279+ Self :: CURRENT_THREAD_EFFECTIVE_TOKEN ,
280+ Security :: TokenUser ,
281+ Some ( buffer. as_mut_ptr ( ) as * mut _ ) ,
282+ token_size,
283+ & mut token_size,
284+ ) ?;
285+
286+ let token_user = & * ( buffer. as_ptr ( ) as * const TOKEN_USER ) ;
282287 let mut sid = PWSTR ( ptr:: null_mut ( ) ) ;
283- ConvertSidToStringSidW ( token . User . Sid , & mut sid as * mut _ ) ?;
288+ ConvertSidToStringSidW ( token_user . User . Sid , & mut sid as * mut _ ) ?;
284289
285290 let string_sid = U16CStr :: from_ptr_str ( sid. 0 ) . to_os_string ( ) ;
286291 LocalFree ( HLOCAL ( sid. 0 as * mut _ ) ) ;
0 commit comments