提交 a502edbc authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Check if pointer is NULL before accessing it (not after...).

上级 28f822b0
...@@ -334,13 +334,17 @@ int CudaNdarray_set_nd(CudaNdarray * self, const int nd) ...@@ -334,13 +334,17 @@ int CudaNdarray_set_nd(CudaNdarray * self, const int nd)
if (nd == -1) return 0; if (nd == -1) return 0;
self->host_structure = (int*)malloc(cnda_structure_size(nd)*sizeof(int)); self->host_structure = (int*)malloc(cnda_structure_size(nd)*sizeof(int));
//initialize all dimensions and strides to 0
for (int i = 0; i < cnda_structure_size(nd); ++i) self->host_structure[i] = 0;
if (NULL == self->host_structure) if (NULL == self->host_structure)
{ {
PyErr_SetString(PyExc_MemoryError, "Failed to allocate dim or str"); PyErr_SetString(PyExc_MemoryError, "Failed to allocate dim or str");
return -1; return -1;
} }
//initialize all dimensions and strides to 0
for (int i = 0; i < cnda_structure_size(nd); ++i)
{
self->host_structure[i] = 0;
}
int struct_size = cnda_structure_size(nd); int struct_size = cnda_structure_size(nd);
if (struct_size) if (struct_size)
{ {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论