From 31645f3408b41b5f7776c35a0979118e46ed24f0 Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Mon, 22 Mar 2021 14:16:39 -0400 Subject: [PATCH] Don't treat 2d array as 1d array, fixing UBSan complaint in `CPP_testhdf5` --- c++/test/ttypes.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/c++/test/ttypes.cpp b/c++/test/ttypes.cpp index b6337404ff0..f14e10a48f1 100644 --- a/c++/test/ttypes.cpp +++ b/c++/test/ttypes.cpp @@ -656,7 +656,6 @@ static void test_named() { static hsize_t ds_size[2] = {10, 20}; - hsize_t i; unsigned attr_data[10][20]; DataType * ds_type = NULL; @@ -726,8 +725,11 @@ test_named() // It should be possible to define an attribute for the named type Attribute attr1 = itype.createAttribute("attr1", PredType::NATIVE_UCHAR, space); - for (i = 0; i < ds_size[0] * ds_size[1]; i++) - attr_data[0][i] = (int)i; /*tricky*/ + for (hsize_t i = 0; i < ds_size[0]; i++) { + for (hsize_t j = 0; j < ds_size[1]; j++) { + attr_data[i][j] = (unsigned)(i * ds_size[1]] + j); + } + } attr1.write(PredType::NATIVE_UINT, attr_data); attr1.close();