MCPcopy Create free account
hub / github.com/CodeSentryAI/lockbud / detect_uninitialized

Method detect_uninitialized

src/detector/memory/invalid_free.rs:272–316  ·  view source on GitHub ↗

Detect mem::uninitialized()

(
        &self,
        instance_id: InstanceId,
        instance: &Instance<'tcx>,
        body: &Body<'tcx>,
        loc: Location,
        drops: &[(Location, Place<'tcx>)],
        alias_analysis

Source from the content-addressed store, hash-verified

270
271 /// Detect mem::uninitialized()
272 fn detect_uninitialized(
273 &self,
274 instance_id: InstanceId,
275 instance: &Instance<'tcx>,
276 body: &Body<'tcx>,
277 loc: Location,
278 drops: &[(Location, Place<'tcx>)],
279 alias_analysis: &mut AliasAnalysis,
280 ) -> Option<String> {
281 if let TerminatorKind::Call {
282 func: _func,
283 args: _args,
284 destination,
285 ..
286 } = &body[loc.block].terminator().kind
287 {
288 let ty = destination.ty(body, self.tcx).ty;
289 let ty = self.monomorphize(instance, ty);
290 if !ty.is_simple_ty() {
291 let span = body.source_info(loc).span;
292 let span_str = format!("{span:?}");
293 // skip std lib
294 if !(span_str.contains(".rustup/toolchains")
295 && span_str.contains("lib/rustlib/src/rust/library"))
296 {
297 // find drop(place) s.t. place alias with destination
298 for (_drop_loc, drop_place) in drops {
299 let aid1 = AliasId {
300 instance_id,
301 local: drop_place.local,
302 };
303 let aid2 = AliasId {
304 instance_id,
305 local: destination.local,
306 };
307 if alias_analysis.alias(aid1, aid2) > ApproximateAliasKind::Unlikely {
308 let diagnosis = format!("{ty:?} = mem::uninitialized() at {span_str}");
309 return Some(diagnosis);
310 }
311 }
312 }
313 }
314 }
315 None
316 }
317
318 /// Find all the paths from loc1 to loc2
319 fn paths_from_to(

Callers 1

Calls 2

monomorphizeMethod · 0.80
aliasMethod · 0.80

Tested by

no test coverage detected