From 1a9f2cefc47ad5dbf658015d94e6ff92b11964a5 Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Wed, 7 Oct 2026 17:39:42 +0200 Subject: [PATCH 1/3] introduce a fixed constant for the length of the description field --- src/t8_vtk/t8_vtk.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/t8_vtk/t8_vtk.h b/src/t8_vtk/t8_vtk.h index e3ed2dd595..c91be2bd59 100644 --- a/src/t8_vtk/t8_vtk.h +++ b/src/t8_vtk/t8_vtk.h @@ -46,7 +46,8 @@ #define T8_VTK_FLOAT_TYPE double #endif -#define T8_VTK_FORMAT_STRING "ascii" /**< Format string for vtk */ +#define T8_VTK_FORMAT_STRING "ascii" /**< Format string for vtk */ +#define T8_VTK_MAX_STRING_LENGTH 1024 /**< Maximal string length for the description in t8_vtk_data_field_t */ #if T8_ENABLE_VTK #define t8_vtk_locidx_array_type_t vtkTypeInt32Array /**< VTK array type for local indices */ @@ -65,8 +66,8 @@ typedef enum { */ typedef struct { - t8_vtk_data_type_t type; /**< Describes of which type the data array is */ - char description[BUFSIZ]; /**< String that describes the data. */ + t8_vtk_data_type_t type; /**< Describes of which type the data array is */ + char description[T8_VTK_MAX_STRING_LENGTH]; /**< String that describes the data. */ double *data; /**< An array of length n*num_local_elements doubles with n = 1 if type = T8_VTK_SCALAR, n = 3 if type = T8_VTK_VECTOR */ From 3766dd1cdec338ad33455da4e4fcedc95243421f Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Wed, 7 Oct 2026 23:31:31 +0200 Subject: [PATCH 2/3] change BUFSIZ to T8_VTK_MAX_STRING_LENGTH --- .../IO/cmesh/vtk/t8_cmesh_read_from_vtk.cxx | 2 +- example/advect/t8_advection.cxx | 8 +-- example/remove/t8_example_gauss_blob.cxx | 2 +- src/t8_vtk/t8_vtk.c | 52 ++++++++++--------- src/t8_vtk/t8_vtk.h | 2 +- src/t8_vtk/t8_vtk_write_ASCII.cxx | 16 +++--- test/t8_IO/t8_gtest_vtk_writer.cxx | 4 +- 7 files changed, 45 insertions(+), 41 deletions(-) diff --git a/example/IO/cmesh/vtk/t8_cmesh_read_from_vtk.cxx b/example/IO/cmesh/vtk/t8_cmesh_read_from_vtk.cxx index 0da13bbcad..0b2c6b0e19 100644 --- a/example/IO/cmesh/vtk/t8_cmesh_read_from_vtk.cxx +++ b/example/IO/cmesh/vtk/t8_cmesh_read_from_vtk.cxx @@ -90,7 +90,7 @@ t8_forest_construct_from_vtk (const char *prefix, sc_MPI_Comm comm, const int va vtk_data[ivalues].data = cell_values[ivalues]; /*TODO: Arbitrary type of data */ vtk_data[ivalues].type = T8_VTK_SCALAR; - snprintf (vtk_data[ivalues].description, BUFSIZ, "cell_data_%i", ivalues); + snprintf (vtk_data[ivalues].description, T8_VTK_MAX_STRING_LENGTH, "cell_data_%i", ivalues); } for (t8_locidx_t itree = 0; itree < num_trees; itree++) { diff --git a/example/advect/t8_advection.cxx b/example/advect/t8_advection.cxx index 939ae3bc69..012d424d02 100644 --- a/example/advect/t8_advection.cxx +++ b/example/advect/t8_advection.cxx @@ -1112,16 +1112,16 @@ t8_advect_write_vtk (t8_advect_problem_t *problem) } /* Write meta data for vtk */ - snprintf (vtk_data[0].description, BUFSIZ, "Num. Solution"); + snprintf (vtk_data[0].description, T8_VTK_MAX_STRING_LENGTH, "Num. Solution"); vtk_data[0].type = T8_VTK_SCALAR; vtk_data[0].data = u_and_phi_array[0]; - snprintf (vtk_data[1].description, BUFSIZ, "Ana. Solution"); + snprintf (vtk_data[1].description, T8_VTK_MAX_STRING_LENGTH, "Ana. Solution"); vtk_data[1].type = T8_VTK_SCALAR; vtk_data[1].data = u_and_phi_array[1]; - snprintf (vtk_data[2].description, BUFSIZ, "Error"); + snprintf (vtk_data[2].description, T8_VTK_MAX_STRING_LENGTH, "Error"); vtk_data[2].type = T8_VTK_SCALAR; vtk_data[2].data = u_and_phi_array[2]; - snprintf (vtk_data[3].description, BUFSIZ, "Flow"); + snprintf (vtk_data[3].description, T8_VTK_MAX_STRING_LENGTH, "Flow"); vtk_data[3].type = T8_VTK_VECTOR; vtk_data[3].data = u_and_phi_array[3]; /* Write filename */ diff --git a/example/remove/t8_example_gauss_blob.cxx b/example/remove/t8_example_gauss_blob.cxx index 3604cb7a7b..da1c35bb47 100644 --- a/example/remove/t8_example_gauss_blob.cxx +++ b/example/remove/t8_example_gauss_blob.cxx @@ -79,7 +79,7 @@ t8_output_data_to_vtu (t8_forest_t forest, double *data, const char *prefix) { t8_vtk_data_field_t vtk_data; vtk_data.type = T8_VTK_SCALAR; - snprintf (vtk_data.description, BUFSIZ, "Gauss"); + snprintf (vtk_data.description, T8_VTK_MAX_STRING_LENGTH, "Gauss"); vtk_data.data = data; int num_data = 1; diff --git a/src/t8_vtk/t8_vtk.c b/src/t8_vtk/t8_vtk.c index ff07ac3b8f..70b35f0bff 100644 --- a/src/t8_vtk/t8_vtk.c +++ b/src/t8_vtk/t8_vtk.c @@ -71,21 +71,22 @@ t8_write_pvtu (const char *filename, int num_procs, int write_tree, int write_ra if (num_data > 0) { /* Print point data for data fields */ - char vtkPointDataString[BUFSIZ] = ""; - char vtkPointVectorString[BUFSIZ] = ""; - char description[BUFSIZ]; + char vtkPointDataString[T8_VTK_MAX_STRING_LENGTH] = ""; + char vtkPointVectorString[T8_VTK_MAX_STRING_LENGTH] = ""; + char description[T8_VTK_MAX_STRING_LENGTH]; for (idata = 0; idata < num_data && data[idata].type == T8_VTK_SCALAR; idata++) { - sreturn = snprintf (description, BUFSIZ, "%s_%s", data[idata].description, "points"); + sreturn = snprintf (description, T8_VTK_MAX_STRING_LENGTH, "%s_%s", data[idata].description, "points"); - if (sreturn >= BUFSIZ) { + if (sreturn >= T8_VTK_MAX_STRING_LENGTH) { /* The output was truncated */ /* Note: gcc >= 7.1 prints a warning if we * do not check the return value of snprintf. */ t8_debugf ("Warning: Truncated vtk point data description to '%s'\n", description); } - printed += snprintf (vtkPointDataString + printed, BUFSIZ - printed, "%s%s", printed > 0 ? "," : "", description); + printed += snprintf (vtkPointDataString + printed, T8_VTK_MAX_STRING_LENGTH - printed, "%s%s", + printed > 0 ? "," : "", description); } num_scalars = idata; /* Write Vector fields in data */ @@ -94,16 +95,16 @@ t8_write_pvtu (const char *filename, int num_procs, int write_tree, int write_ra for (idata = num_scalars; idata < num_data; idata++) { SC_CHECK_ABORT (data[idata].type == T8_VTK_VECTOR, "vtk data mismatch. After scalar fields only vector" " fields are allowed."); - sreturn = snprintf (description, BUFSIZ, "%s_%s", data[idata].description, "points"); + sreturn = snprintf (description, T8_VTK_MAX_STRING_LENGTH, "%s_%s", data[idata].description, "points"); - if (sreturn >= BUFSIZ) { + if (sreturn >= T8_VTK_MAX_STRING_LENGTH) { /* The output was truncated */ /* Note: gcc >= 7.1 prints a warning if we * do not check the return value of snprintf. */ t8_debugf ("Warning: Truncated vtk point data description to '%s'\n", description); } - printed - += snprintf (vtkPointVectorString + printed, BUFSIZ - printed, "%s%s", printed > 0 ? "," : "", description); + printed += snprintf (vtkPointVectorString + printed, T8_VTK_MAX_STRING_LENGTH - printed, "%s%s", + printed > 0 ? "," : "", description); } } @@ -118,9 +119,9 @@ t8_write_pvtu (const char *filename, int num_procs, int write_tree, int write_ra } /* Write data fields */ for (idata = 0; idata < num_scalars; idata++) { - sreturn = snprintf (description, BUFSIZ, "%s_%s", data[idata].description, "points"); + sreturn = snprintf (description, T8_VTK_MAX_STRING_LENGTH, "%s_%s", data[idata].description, "points"); - if (sreturn >= BUFSIZ) { + if (sreturn >= T8_VTK_MAX_STRING_LENGTH) { /* The output was truncated */ /* Note: gcc >= 7.1 prints a warning if we * do not check the return value of snprintf. */ @@ -136,9 +137,9 @@ t8_write_pvtu (const char *filename, int num_procs, int write_tree, int write_ra /* Write vector data fields */ for (idata = num_scalars; idata < num_data; idata++) { T8_ASSERT (data[idata].type == T8_VTK_VECTOR); - sreturn = snprintf (description, BUFSIZ, "%s_%s", data[idata].description, "points"); + sreturn = snprintf (description, T8_VTK_MAX_STRING_LENGTH, "%s_%s", data[idata].description, "points"); - if (sreturn >= BUFSIZ) { + if (sreturn >= T8_VTK_MAX_STRING_LENGTH) { /* The output was truncated */ /* Note: gcc >= 7.1 prints a warning if we * do not check the return value of snprintf. */ @@ -157,24 +158,27 @@ t8_write_pvtu (const char *filename, int num_procs, int write_tree, int write_ra /* reset counter */ printed = 0; if (write_cell_data) { - char vtkCellDataString[BUFSIZ] = ""; - char vtkCellVectorString[BUFSIZ] = ""; + char vtkCellDataString[T8_VTK_MAX_STRING_LENGTH] = ""; + char vtkCellVectorString[T8_VTK_MAX_STRING_LENGTH] = ""; if (write_tree) { - printed += snprintf (vtkCellDataString + printed, BUFSIZ - printed, "treeid"); + printed += snprintf (vtkCellDataString + printed, T8_VTK_MAX_STRING_LENGTH - printed, "treeid"); } if (write_rank) { - printed += snprintf (vtkCellDataString + printed, BUFSIZ - printed, "%s%s", printed > 0 ? "," : "", "mpirank"); + printed += snprintf (vtkCellDataString + printed, T8_VTK_MAX_STRING_LENGTH - printed, "%s%s", + printed > 0 ? "," : "", "mpirank"); } if (write_level) { - printed += snprintf (vtkCellDataString + printed, BUFSIZ - printed, "%s%s", printed > 0 ? "," : "", "level"); + printed += snprintf (vtkCellDataString + printed, T8_VTK_MAX_STRING_LENGTH - printed, "%s%s", + printed > 0 ? "," : "", "level"); } if (write_id) { - printed += snprintf (vtkCellDataString + printed, BUFSIZ - printed, "%s%s", printed > 0 ? "," : "", "element_id"); + printed += snprintf (vtkCellDataString + printed, T8_VTK_MAX_STRING_LENGTH - printed, "%s%s", + printed > 0 ? "," : "", "element_id"); } for (idata = 0; idata < num_data && data[idata].type == T8_VTK_SCALAR; idata++) { - printed += snprintf (vtkCellDataString + printed, BUFSIZ - printed, "%s%s", printed > 0 ? "," : "", - data[idata].description); + printed += snprintf (vtkCellDataString + printed, T8_VTK_MAX_STRING_LENGTH - printed, "%s%s", + printed > 0 ? "," : "", data[idata].description); } num_scalars = idata; /* Write Vector fields in data */ @@ -183,8 +187,8 @@ t8_write_pvtu (const char *filename, int num_procs, int write_tree, int write_ra for (idata = num_scalars; idata < num_data; idata++) { SC_CHECK_ABORT (data[idata].type == T8_VTK_VECTOR, "vtk data mismatch. After scalar fields only vector" " fields are allowed."); - printed += snprintf (vtkCellVectorString + printed, BUFSIZ - printed, "%s%s", printed > 0 ? "," : "", - data[idata].description); + printed += snprintf (vtkCellVectorString + printed, T8_VTK_MAX_STRING_LENGTH - printed, "%s%s", + printed > 0 ? "," : "", data[idata].description); } } if (strcmp (vtkCellDataString, "")) { diff --git a/src/t8_vtk/t8_vtk.h b/src/t8_vtk/t8_vtk.h index c91be2bd59..e8fef48d97 100644 --- a/src/t8_vtk/t8_vtk.h +++ b/src/t8_vtk/t8_vtk.h @@ -47,7 +47,7 @@ #endif #define T8_VTK_FORMAT_STRING "ascii" /**< Format string for vtk */ -#define T8_VTK_MAX_STRING_LENGTH 1024 /**< Maximal string length for the description in t8_vtk_data_field_t */ +#define T8_VTK_MAX_STRING_LENGTH 1023 /**< Maximal string length for the description in t8_vtk_data_field_t */ #if T8_ENABLE_VTK #define t8_vtk_locidx_array_type_t vtkTypeInt32Array /**< VTK array type for local indices */ diff --git a/src/t8_vtk/t8_vtk_write_ASCII.cxx b/src/t8_vtk/t8_vtk_write_ASCII.cxx index 68ca8561ce..00a1962b60 100644 --- a/src/t8_vtk/t8_vtk_write_ASCII.cxx +++ b/src/t8_vtk/t8_vtk_write_ASCII.cxx @@ -557,7 +557,7 @@ t8_forest_vtk_write_cell_data (t8_forest_t forest, FILE *vtufile, const char *da return 0; } } /* ghost loop ends here */ - } /* write_ghosts ends here */ + } /* write_ghosts ends here */ /* call the kernel in clean-up modus */ kernel (nullptr, 0, nullptr, 0, nullptr, T8_ECLASS_INVALID, 0, nullptr, nullptr, &data, T8_VTK_KERNEL_CLEANUP); freturn = fprintf (vtufile, "\n \n"); @@ -720,7 +720,7 @@ t8_forest_vtk_write_points (t8_forest_t forest, FILE *vtufile, const int write_g int freturn; int sreturn; int idata; - char description[BUFSIZ]; + char description[T8_VTK_MAX_STRING_LENGTH]; T8_ASSERT (t8_forest_is_committed (forest)); T8_ASSERT (vtufile != NULL); @@ -748,9 +748,9 @@ t8_forest_vtk_write_points (t8_forest_t forest, FILE *vtufile, const int write_g for (idata = 0; idata < num_data; idata++) { if (data[idata].type == T8_VTK_SCALAR) { /* Write the description string. */ - sreturn = snprintf (description, BUFSIZ, "%s_%s", data[idata].description, "points"); + sreturn = snprintf (description, T8_VTK_MAX_STRING_LENGTH, "%s_%s", data[idata].description, "points"); - if (sreturn >= BUFSIZ) { + if (sreturn >= T8_VTK_MAX_STRING_LENGTH) { /* The output was truncated */ t8_debugf ("Warning: Truncated vtk point data description to '%s'\n", description); } @@ -758,13 +758,13 @@ t8_forest_vtk_write_points (t8_forest_t forest, FILE *vtufile, const int write_g t8_forest_vtk_vertices_scalar_kernel, write_ghosts, data[idata].data); } else { - char component_string[BUFSIZ]; + char component_string[T8_VTK_MAX_STRING_LENGTH]; T8_ASSERT (data[idata].type == T8_VTK_VECTOR); - snprintf (component_string, BUFSIZ, "NumberOfComponents=\"3\""); + snprintf (component_string, T8_VTK_MAX_STRING_LENGTH, "NumberOfComponents=\"3\""); /* Write the description string. */ - sreturn = snprintf (description, BUFSIZ, "%s_%s", data[idata].description, "points"); + sreturn = snprintf (description, T8_VTK_MAX_STRING_LENGTH, "%s_%s", data[idata].description, "points"); - if (sreturn >= BUFSIZ) { + if (sreturn >= T8_VTK_MAX_STRING_LENGTH) { /* The output was truncated */ /* Note: gcc >= 7.1 prints a warning if we * do not check the return value of snprintf. */ diff --git a/test/t8_IO/t8_gtest_vtk_writer.cxx b/test/t8_IO/t8_gtest_vtk_writer.cxx index 9ae95f14c4..0f983ee3fa 100644 --- a/test/t8_IO/t8_gtest_vtk_writer.cxx +++ b/test/t8_IO/t8_gtest_vtk_writer.cxx @@ -175,10 +175,10 @@ struct vtk_writer_test: public testing::Test // Fill the vtk_data descriptors vtk_data[0].type = T8_VTK_SCALAR; - strncpy (vtk_data[0].description, "Testdata scalar i/10.", BUFSIZ); + strncpy (vtk_data[0].description, "Testdata scalar i/10.", T8_VTK_MAX_STRING_LENGTH); vtk_data[0].data = scalar_data.data (); vtk_data[1].type = T8_VTK_VECTOR; - strncpy (vtk_data[1].description, "Testdata vector (i/10.,-i/10.,42)", BUFSIZ); + strncpy (vtk_data[1].description, "Testdata vector (i/10.,-i/10.,42)", T8_VTK_MAX_STRING_LENGTH); vtk_data[1].data = vector_data.data (); writer = new vtk_writer (true, true, true, true, true, true, std::string ("test_vtk_writer"), num_vtk_data, From 3dd3d357deda0eb94a986c0fc363156584c441bd Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Thu, 8 Oct 2026 11:14:54 +0200 Subject: [PATCH 3/3] fmt --- src/t8_vtk/t8_vtk_write_ASCII.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/t8_vtk/t8_vtk_write_ASCII.cxx b/src/t8_vtk/t8_vtk_write_ASCII.cxx index 00a1962b60..d6eda46573 100644 --- a/src/t8_vtk/t8_vtk_write_ASCII.cxx +++ b/src/t8_vtk/t8_vtk_write_ASCII.cxx @@ -557,7 +557,7 @@ t8_forest_vtk_write_cell_data (t8_forest_t forest, FILE *vtufile, const char *da return 0; } } /* ghost loop ends here */ - } /* write_ghosts ends here */ + } /* write_ghosts ends here */ /* call the kernel in clean-up modus */ kernel (nullptr, 0, nullptr, 0, nullptr, T8_ECLASS_INVALID, 0, nullptr, nullptr, &data, T8_VTK_KERNEL_CLEANUP); freturn = fprintf (vtufile, "\n \n");