@@ -69,7 +69,7 @@ impl<'tcx> EnvVars<'tcx> {
69
69
}
70
70
// Deallocate environ var list.
71
71
let environ = ecx. machine . env_vars . environ . unwrap ( ) ;
72
- let old_vars_ptr = ecx. read_scalar ( environ. into ( ) ) ?. not_undef ( ) ?;
72
+ let old_vars_ptr = ecx. read_scalar ( environ. into ( ) ) ?. check_init ( ) ?;
73
73
ecx. memory . deallocate ( ecx. force_ptr ( old_vars_ptr) ?, None , MiriMemoryKind :: Env . into ( ) ) ?;
74
74
Ok ( ( ) )
75
75
}
@@ -104,7 +104,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
104
104
let target_os = & this. tcx . sess . target . target . target_os ;
105
105
assert ! ( target_os == "linux" || target_os == "macos" , "`getenv` is only available for the UNIX target family" ) ;
106
106
107
- let name_ptr = this. read_scalar ( name_op) ?. not_undef ( ) ?;
107
+ let name_ptr = this. read_scalar ( name_op) ?. check_init ( ) ?;
108
108
let name = this. read_os_str_from_c_str ( name_ptr) ?;
109
109
Ok ( match this. machine . env_vars . map . get ( name) {
110
110
Some ( var_ptr) => {
@@ -125,7 +125,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
125
125
let this = self . eval_context_mut ( ) ;
126
126
this. assert_target_os ( "windows" , "GetEnvironmentVariableW" ) ;
127
127
128
- let name_ptr = this. read_scalar ( name_op) ?. not_undef ( ) ?;
128
+ let name_ptr = this. read_scalar ( name_op) ?. check_init ( ) ?;
129
129
let name = this. read_os_str_from_wide_str ( name_ptr) ?;
130
130
Ok ( match this. machine . env_vars . map . get ( & name) {
131
131
Some ( var_ptr) => {
@@ -135,7 +135,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
135
135
let var_ptr = Scalar :: from ( var_ptr. offset ( Size :: from_bytes ( name_offset_bytes) , this) ?) ;
136
136
let var = this. read_os_str_from_wide_str ( var_ptr) ?;
137
137
138
- let buf_ptr = this. read_scalar ( buf_op) ?. not_undef ( ) ?;
138
+ let buf_ptr = this. read_scalar ( buf_op) ?. check_init ( ) ?;
139
139
// `buf_size` represents the size in characters.
140
140
let buf_size = u64:: from ( this. read_scalar ( size_op) ?. to_u32 ( ) ?) ;
141
141
windows_check_buffer_size ( this. write_os_str_to_wide_str ( & var, buf_ptr, buf_size) ?)
@@ -153,7 +153,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
153
153
let this = self . eval_context_mut ( ) ;
154
154
this. assert_target_os ( "windows" , "GetEnvironmentStringsW" ) ;
155
155
156
- // Info on layout of environment blocks in Windows:
156
+ // Info on layout of environment blocks in Windows:
157
157
// https://docs.microsoft.com/en-us/windows/win32/procthread/environment-variables
158
158
let mut env_vars = std:: ffi:: OsString :: new ( ) ;
159
159
for & item in this. machine . env_vars . map . values ( ) {
@@ -173,7 +173,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
173
173
let this = self . eval_context_mut ( ) ;
174
174
this. assert_target_os ( "windows" , "FreeEnvironmentStringsW" ) ;
175
175
176
- let env_block_ptr = this. read_scalar ( env_block_op) ?. not_undef ( ) ?;
176
+ let env_block_ptr = this. read_scalar ( env_block_op) ?. check_init ( ) ?;
177
177
let result = this. memory . deallocate ( this. force_ptr ( env_block_ptr) ?, None , MiriMemoryKind :: Env . into ( ) ) ;
178
178
// If the function succeeds, the return value is nonzero.
179
179
Ok ( result. is_ok ( ) as i32 )
@@ -188,8 +188,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
188
188
let target_os = & this. tcx . sess . target . target . target_os ;
189
189
assert ! ( target_os == "linux" || target_os == "macos" , "`setenv` is only available for the UNIX target family" ) ;
190
190
191
- let name_ptr = this. read_scalar ( name_op) ?. not_undef ( ) ?;
192
- let value_ptr = this. read_scalar ( value_op) ?. not_undef ( ) ?;
191
+ let name_ptr = this. read_scalar ( name_op) ?. check_init ( ) ?;
192
+ let value_ptr = this. read_scalar ( value_op) ?. check_init ( ) ?;
193
193
194
194
let mut new = None ;
195
195
if !this. is_null ( name_ptr) ? {
@@ -224,14 +224,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
224
224
let mut this = self . eval_context_mut ( ) ;
225
225
this. assert_target_os ( "windows" , "SetEnvironmentVariableW" ) ;
226
226
227
- let name_ptr = this. read_scalar ( name_op) ?. not_undef ( ) ?;
228
- let value_ptr = this. read_scalar ( value_op) ?. not_undef ( ) ?;
227
+ let name_ptr = this. read_scalar ( name_op) ?. check_init ( ) ?;
228
+ let value_ptr = this. read_scalar ( value_op) ?. check_init ( ) ?;
229
229
230
230
if this. is_null ( name_ptr) ? {
231
231
// ERROR CODE is not clearly explained in docs.. For now, throw UB instead.
232
232
throw_ub_format ! ( "pointer to environment variable name is NULL" ) ;
233
233
}
234
-
234
+
235
235
let name = this. read_os_str_from_wide_str ( name_ptr) ?;
236
236
if name. is_empty ( ) {
237
237
throw_unsup_format ! ( "environment variable name is an empty string" ) ;
@@ -261,7 +261,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
261
261
let target_os = & this. tcx . sess . target . target . target_os ;
262
262
assert ! ( target_os == "linux" || target_os == "macos" , "`unsetenv` is only available for the UNIX target family" ) ;
263
263
264
- let name_ptr = this. read_scalar ( name_op) ?. not_undef ( ) ?;
264
+ let name_ptr = this. read_scalar ( name_op) ?. check_init ( ) ?;
265
265
let mut success = None ;
266
266
if !this. is_null ( name_ptr) ? {
267
267
let name = this. read_os_str_from_c_str ( name_ptr) ?. to_owned ( ) ;
@@ -295,7 +295,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
295
295
296
296
this. check_no_isolation ( "getcwd" ) ?;
297
297
298
- let buf = this. read_scalar ( buf_op) ?. not_undef ( ) ?;
298
+ let buf = this. read_scalar ( buf_op) ?. check_init ( ) ?;
299
299
let size = this. read_scalar ( size_op) ?. to_machine_usize ( & * this. tcx ) ?;
300
300
// If we cannot get the current directory, we return null
301
301
match env:: current_dir ( ) {
@@ -323,7 +323,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
323
323
this. check_no_isolation ( "GetCurrentDirectoryW" ) ?;
324
324
325
325
let size = u64:: from ( this. read_scalar ( size_op) ?. to_u32 ( ) ?) ;
326
- let buf = this. read_scalar ( buf_op) ?. not_undef ( ) ?;
326
+ let buf = this. read_scalar ( buf_op) ?. check_init ( ) ?;
327
327
328
328
// If we cannot get the current directory, we return 0
329
329
match env:: current_dir ( ) {
@@ -341,7 +341,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
341
341
342
342
this. check_no_isolation ( "chdir" ) ?;
343
343
344
- let path = this. read_path_from_c_str ( this. read_scalar ( path_op) ?. not_undef ( ) ?) ?;
344
+ let path = this. read_path_from_c_str ( this. read_scalar ( path_op) ?. check_init ( ) ?) ?;
345
345
346
346
match env:: set_current_dir ( path) {
347
347
Ok ( ( ) ) => Ok ( 0 ) ,
@@ -362,7 +362,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
362
362
363
363
this. check_no_isolation ( "SetCurrentDirectoryW" ) ?;
364
364
365
- let path = this. read_path_from_wide_str ( this. read_scalar ( path_op) ?. not_undef ( ) ?) ?;
365
+ let path = this. read_path_from_wide_str ( this. read_scalar ( path_op) ?. check_init ( ) ?) ?;
366
366
367
367
match env:: set_current_dir ( path) {
368
368
Ok ( ( ) ) => Ok ( 1 ) ,
@@ -379,7 +379,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
379
379
let this = self . eval_context_mut ( ) ;
380
380
// Deallocate the old environ list, if any.
381
381
if let Some ( environ) = this. machine . env_vars . environ {
382
- let old_vars_ptr = this. read_scalar ( environ. into ( ) ) ?. not_undef ( ) ?;
382
+ let old_vars_ptr = this. read_scalar ( environ. into ( ) ) ?. check_init ( ) ?;
383
383
this. memory . deallocate ( this. force_ptr ( old_vars_ptr) ?, None , MiriMemoryKind :: Env . into ( ) ) ?;
384
384
} else {
385
385
// No `environ` allocated yet, let's do that.
0 commit comments