@@ -113,7 +113,8 @@ cl_ctx *cl_make_ctx(cl_context ctx, gpucontext_props *p) {
113113 cl_command_queue_properties qprop ;
114114 char vendor [32 ];
115115 char driver_version [64 ];
116- char device_version [32 ];
116+ char * device_version = NULL ;
117+ size_t device_version_size = 0 ;
117118 cl_uint vendor_id ;
118119 cl_int err ;
119120 size_t len ;
@@ -132,9 +133,19 @@ cl_ctx *cl_make_ctx(cl_context ctx, gpucontext_props *p) {
132133 id = get_dev (ctx , global_err );
133134 if (id == NULL ) return NULL ;
134135
136+ /* Query device version string size */
135137 CL_CHECKN (global_err , clGetDeviceInfo (id , CL_DEVICE_VERSION ,
136- sizeof (device_version ),
137- & device_version , NULL ));
138+ 0 , NULL , & device_version_size ));
139+ if (device_version_size > 1024 ) {
140+ error_set (global_err , GA_UNSUPPORTED_ERROR ,
141+ "device version buffer too large" );
142+ return NULL ;
143+ }
144+
145+ device_version = alloca (device_version_size );
146+ CL_CHECKN (global_err , clGetDeviceInfo (id , CL_DEVICE_VERSION ,
147+ device_version_size ,
148+ device_version , NULL ));
138149 if (device_version [7 ] == '1' && device_version [9 ] < '2' ) {
139150 error_set (global_err , GA_UNSUPPORTED_ERROR ,
140151 "We only support OpenCL 1.2 and up" );
0 commit comments