[Piglit] [PATCH 01/18] util/gl: Print numeric value of unrecognized enums.
Fabian Bieler
fabianbieler at fastmail.fm
Sun Jan 7 22:13:56 UTC 2018
Use a static cyclic buffer of 4096 bytes. This should give returned
strings a long enough lifetime.
---
tests/util/piglit-util-gl-enum-gen.c.mako | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/tests/util/piglit-util-gl-enum-gen.c.mako b/tests/util/piglit-util-gl-enum-gen.c.mako
index 1a878c945..3e07b9d69 100644
--- a/tests/util/piglit-util-gl-enum-gen.c.mako
+++ b/tests/util/piglit-util-gl-enum-gen.c.mako
@@ -38,7 +38,19 @@ piglit_get_gl_enum_name(GLenum param)
>-------case ${enum.c_num_literal}: return "${enum.name}";
% endif
% endfor
->-------default: return "(unrecognized enum)";
+>-------default: {
+>------->-------static const char *format = "(unrecognized enum: 0x%X)";
+>------->-------static char buffer[4096];
+>------->-------static char *position = buffer;
+>------->-------const ptrdiff_t size_left = 4096 - (position - buffer);
+>------->-------const size_t size_needed = strlen(format) + 8 - 2 + 1;
+>------->-------if (size_left < size_needed)
+>------->------->-------position = buffer;
+>------->-------const int len = sprintf(position, format, param);
+>------->-------const char *old_position = position;
+>------->-------position += len + 1;
+>------->-------return old_position;
+>------->-------}
>-------}
}
--
2.15.1
More information about the Piglit
mailing list