From a4c6517d069d8d5e72fcf66ee37b6d863cd52b56 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 15 Jul 2022 14:40:55 -0400 Subject: [PATCH] glshader: Add preconditions Add preconditions to many of the glshader uniform apis. --- gsk/gskglshader.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/gsk/gskglshader.c b/gsk/gskglshader.c index 7823651b8b..b8d5566d29 100644 --- a/gsk/gskglshader.c +++ b/gsk/gskglshader.c @@ -162,6 +162,7 @@ uniform_type_from_glsl (const char *str) return GSK_GL_UNIFORM_TYPE_NONE; } +#ifdef G_ENABLE_DEBUG static const char * uniform_type_name (GskGLUniformType type) { @@ -194,6 +195,7 @@ uniform_type_name (GskGLUniformType type) return NULL; } } +#endif static int uniform_type_size (GskGLUniformType type) @@ -397,6 +399,7 @@ gsk_gl_shader_constructed (GObject *object) shader->n_textures = max_texture_seen; +#ifdef G_ENABLE_DEBUG if (GSK_DEBUG_CHECK(SHADERS)) { GString *s; @@ -414,6 +417,7 @@ gsk_gl_shader_constructed (GObject *object) s->str); g_string_free (s, TRUE); } +#endif } #define SPACE_RE "[ \\t]+" // Don't use \s, we don't want to match newlines @@ -631,6 +635,7 @@ gsk_gl_shader_get_uniform_name (GskGLShader *shader, int idx) { g_return_val_if_fail (GSK_IS_GL_SHADER (shader), NULL); + g_return_val_if_fail (0 <= idx && idx < shader->uniforms->len, NULL); return g_array_index (shader->uniforms, GskGLUniform, idx).name; } @@ -675,6 +680,7 @@ gsk_gl_shader_get_uniform_type (GskGLShader *shader, int idx) { g_return_val_if_fail (GSK_IS_GL_SHADER (shader), 0); + g_return_val_if_fail (0 <= idx && idx < shader->uniforms->len, 0); return g_array_index (shader->uniforms, GskGLUniform, idx).type; } @@ -693,6 +699,7 @@ gsk_gl_shader_get_uniform_offset (GskGLShader *shader, int idx) { g_return_val_if_fail (GSK_IS_GL_SHADER (shader), 0); + g_return_val_if_fail (0 <= idx && idx < shader->uniforms->len, 0); return g_array_index (shader->uniforms, GskGLUniform, idx).offset; }