[Bugs] Issue with compilation vtk to product a vtk.jar

Hello everyone,

I have tried to compile the source vtk to producta vtk.jar. But it fails because we have the enum arguments whose are truncated by the parser.

The possible origin of this behaviour is the function vtkParseHierarchy_QualifiedName whose use a snprintf function.

        size_t scoped_len = strlen(data->Name) + strlen(info->Name) + 2;
        scoped_name = vtkParse_NewString(cache, scoped_len);
       snprintf(scoped_name, scoped_len, "%s::%s", data->Name, info->Name);

There, the length provided (scoped_len) is too small and we have to increase of one. After a little correction, i have succeed to compile a vtk.jar

Could you let me know if it is the good thing to do?

Thank you so much and have a good day :slight_smile:

Alexandre Schmit

Hi Alexandre, thanks for the report.

I’m a bit suspicious, though, because vtkParse_NewString() automatically adds 1, according to the documentation and in the code itself:

  /**
   * Allocate a new string from the cache.
   * A total of n+1 bytes will be allocated, to leave room for null.
   */
  VTKWRAPPINGTOOLS_EXPORT
  char* vtkParse_NewString(StringCache* cache, size_t n);

Do you have any evidence that the name is truncated?

I might just be misunderstanding. Do you want this change?

-  size_t scoped_len = strlen(data->Name) + strlen(info->Name) + 2;
+  size_t scoped_len = strlen(data->Name) + strlen(info->Name) + 3;

or do you want this change?

-  snprintf(scoped_name, scoped_len, "%s::%s", data->Name, info->Name);
+  snprintf(scoped_name, scoped_len + 1, "%s::%s", data->Name, info->Name);

Thank you for your answer,

I guess the better solution would be the first but the secund is good too.

I can have evidence if you want :slight_smile: but you can reproduce it in compiling the vtk with option VTK_WRAP_JAVA=ON

Have a nice evening