Commit 314a8bd6 authored by David Gobbi's avatar David Gobbi

Use size_t for array size in wrappers

Previously the size type was 'int', which can overflow for large
arrays.
parent a92ee8b2
This diff is collapsed.
This diff is collapsed.
...@@ -1148,7 +1148,7 @@ void vtkWrap_DeclareVariableSize( ...@@ -1148,7 +1148,7 @@ void vtkWrap_DeclareVariableSize(
if (val->NumberOfDimensions > 1) if (val->NumberOfDimensions > 1)
{ {
fprintf(fp, fprintf(fp,
" static int %s%s[%d] = ", " static size_t %s%s[%d] = ",
name, idx, val->NumberOfDimensions); name, idx, val->NumberOfDimensions);
for (j = 0; j < val->NumberOfDimensions; j++) for (j = 0; j < val->NumberOfDimensions; j++)
...@@ -1161,14 +1161,14 @@ void vtkWrap_DeclareVariableSize( ...@@ -1161,14 +1161,14 @@ void vtkWrap_DeclareVariableSize(
else if (val->Count != 0 || val->CountHint || vtkWrap_IsPODPointer(val)) else if (val->Count != 0 || val->CountHint || vtkWrap_IsPODPointer(val))
{ {
fprintf(fp, fprintf(fp,
" %sint %s%s = %d;\n", " %ssize_t %s%s = %d;\n",
((val->Count == 0 || val->Value != 0) ? "" : "const "), ((val->Count == 0 || val->Value != 0) ? "" : "const "),
name, idx, (val->Count == 0 ? 0 : val->Count)); name, idx, (val->Count == 0 ? 0 : val->Count));
} }
else if (val->NumberOfDimensions == 1) else if (val->NumberOfDimensions == 1)
{ {
fprintf(fp, fprintf(fp,
" const int %s%s = %s;\n", " const size_t %s%s = %s;\n",
name, idx, val->Dimensions[0]); name, idx, val->Dimensions[0]);
} }
} }
......
...@@ -115,7 +115,7 @@ void vtkWrapPython_DeclareVariables( ...@@ -115,7 +115,7 @@ void vtkWrapPython_DeclareVariables(
{ {
/* prepare for "char *" arg for non-const char pointer */ /* prepare for "char *" arg for non-const char pointer */
fprintf(fp, fprintf(fp,
" int size%d = ap.GetStringSize(%d);\n" " size_t size%d = ap.GetStringSize(%d);\n"
" vtkPythonArgs::Array<char> store%d(%ssize%d + 1);\n" " vtkPythonArgs::Array<char> store%d(%ssize%d + 1);\n"
" char *temp%d = store%d.Data();\n", " char *temp%d = store%d.Data();\n",
i, i, i, i,
...@@ -132,7 +132,7 @@ void vtkWrapPython_DeclareVariables( ...@@ -132,7 +132,7 @@ void vtkWrapPython_DeclareVariables(
{ {
/* prepare for "T *" arg, where T is a plain type */ /* prepare for "T *" arg, where T is a plain type */
fprintf(fp, fprintf(fp,
" int size%d = ap.GetArgSize(%d);\n" " size_t size%d = ap.GetArgSize(%d);\n"
" vtkPythonArgs::Array<%s> store%d(%ssize%d);\n" " vtkPythonArgs::Array<%s> store%d(%ssize%d);\n"
" %s *temp%d = store%d.Data();\n", " %s *temp%d = store%d.Data();\n",
i, i, i, i,
...@@ -150,7 +150,7 @@ void vtkWrapPython_DeclareVariables( ...@@ -150,7 +150,7 @@ void vtkWrapPython_DeclareVariables(
{ {
/* prepare for "T a[n] = nullptr" arg (array with default of NULL) */ /* prepare for "T a[n] = nullptr" arg (array with default of NULL) */
fprintf(fp, fprintf(fp,
" int size%d = 0;\n" " size_t size%d = 0;\n"
" %s store%d[%s%d];\n" " %s store%d[%s%d];\n"
" %s *temp%d = nullptr;\n", " %s *temp%d = nullptr;\n",
i, i,
...@@ -226,7 +226,7 @@ void vtkWrapPython_DeclareVariables( ...@@ -226,7 +226,7 @@ void vtkWrapPython_DeclareVariables(
!theFunc->ReturnValue->CountHint) !theFunc->ReturnValue->CountHint)
{ {
fprintf(fp, fprintf(fp,
" int sizer = %d;\n", " size_t sizer = %d;\n",
theFunc->ReturnValue->Count); theFunc->ReturnValue->Count);
} }
} }
...@@ -1282,7 +1282,7 @@ void vtkWrapPython_GenerateOneMethod( ...@@ -1282,7 +1282,7 @@ void vtkWrapPython_GenerateOneMethod(
if (theOccurrence->ReturnValue && theOccurrence->ReturnValue->CountHint) if (theOccurrence->ReturnValue && theOccurrence->ReturnValue->CountHint)
{ {
fprintf(fp, fprintf(fp,
" int sizer = "); " size_t sizer = ");
vtkWrapPython_SubstituteCode(fp, data, theOccurrence, vtkWrapPython_SubstituteCode(fp, data, theOccurrence,
theOccurrence->ReturnValue->CountHint); theOccurrence->ReturnValue->CountHint);
fprintf(fp, ";\n"); fprintf(fp, ";\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment