False positive: assuming null for value previously assumed non-null
| Bugzilla Link | 4558 |
| Resolution | FIXED |
| Resolved on | Jun 22, 2021 09:13 |
| Version | unspecified |
| OS | All |
| Depends On | llvm/llvm-bugzilla-archive#4561 |
| Attachments | Test case |
| Reporter | LLVM Bugzilla Contributor |
| CC | @aaronpuchert,@devincoughlin,@tkremenek,@haoNoQ |
Extended Description
In the attached test case, steps 1 and 2 make conflicting assumptions.
By taking the false branch in step 1, the analyzer is assuming that *ppListDeviceHead is not null. By assuming the loop condition is initially false in step 2, the analyzer is assuming that pDevice – copied from *ppListDeviceHead – is null, conflicting with step 1.
What actually happens is that if *ppListDeviceHead is null, steps 2 and 3 are never reached and a non-null value is assigned to result on line 16. If *ppListDeviceHead is not null, the loop at step 2 is iterated at least once, and a non-null value is assigned to pDevicePrevious, which is then assigned (with an offset that happens to be zero) to result at line 25. Under no circumstances will pDevicePrevious be null at line 25.
mentioned in issue llvm/llvm-bugzilla-archive#4561
Comment 3 says this should be fixed by now, and there has been no reply.
Gary: This should have been fixed in r259288, which in LLVM 3.9+ (it looks like you are running 3.8.1). Can you try with a newer version of clang?
Looks like an inline defensive check in a macro:
if(plugin_loader != NULL && GPLUGIN_IS_LOADER(plugin_loader)) { const char *loader_name = G_OBJECT_TYPE_NAME(plugin_loader); }
GPLUGIN_IS_LOADER is:
(((extension ({ GTypeInstance __inst = (GTypeInstance) ( (plugin_loader)); GType __t = ((gplugin_loader_get_type())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; }))))
and
G_OBJECT_TYPE_NAME is:
(g_type_name ((((((GTypeClass*) (((GTypeInstance*) (plugin_loader ))->g_class))->g_type)))))
updated test case with scanbuild output scanbuild assumes null on the same line where pointer was checked to be not null.
This false positive has to do with the current memory model (BasicStoreManager) not tracking the symbolic values of the pointees of parameters. The new experimental memory model does this, and if you run scan-build with the "-store region" option you'll notice that the error disappears (at least from r75836 of the tree).
This bug will get resolved as soon as RegionStoreManager becomes the default store manager.
assigned to @tkremenek