Skip to content

Commit 92b35e6

Browse files
committed
ocl: fix null pointer access crash
1 parent 91c1d76 commit 92b35e6

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

modules/core/src/ocl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,6 +1973,7 @@ struct Context::Impl
19731973
{
19741974
if (prefix.empty())
19751975
{
1976+
CV_Assert(!devices.empty());
19761977
const Device& d = devices[0];
19771978
prefix = d.vendorName() + "--" + d.name() + "--" + d.driverVersion();
19781979
// sanitize chars
@@ -3222,6 +3223,8 @@ struct Program::Impl
32223223
refcount = 1;
32233224
const Context ctx = Context::getDefault();
32243225
Device device = ctx.device(0);
3226+
if (ctx.ptr() == NULL || device.ptr() == NULL)
3227+
return;
32253228
if (device.isAMD())
32263229
buildflags += " -D AMD_DEVICE";
32273230
else if (device.isIntel())
@@ -3232,6 +3235,7 @@ struct Program::Impl
32323235
bool compile(const Context& ctx, String& errmsg)
32333236
{
32343237
#if OPENCV_HAVE_FILESYSTEM_SUPPORT
3238+
CV_Assert(ctx.getImpl());
32353239
OpenCLBinaryCacheConfigurator& config = OpenCLBinaryCacheConfigurator::getSingletonInstance();
32363240
const std::string base_dir = config.prepareCacheDirectoryForContext(ctx.getImpl()->getPrefixString());
32373241
const std::string fname = base_dir.empty() ? std::string() :

0 commit comments

Comments
 (0)