Fix some static analyzer complains in glx.c

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2018-12-31 06:54:59 +00:00
parent f322bd4a53
commit 8629fee78f
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
1 changed files with 120 additions and 120 deletions

View File

@ -9,8 +9,8 @@
*
*/
#include <locale.h>
#include <GL/glx.h>
#include <locale.h>
#include "backend/backend.h"
#include "backend/gl/gl_common.h"
#include "string_utils.h"
@ -55,12 +55,14 @@ static inline bool glx_has_extension(session_t *ps, const char *ext) {
int len = strlen(ext);
char *found = strstr(glx_exts, ext);
if (!found)
if (!found) {
log_info("Missing GLX extension %s.", ext);
return false;
}
// Make sure extension names are not crazy...
assert(found[len] == ' ' || found[len] == 0);
return found != NULL;
return true;
}
/**
@ -86,7 +88,8 @@ static void glx_release_pixmap(struct _glx_data *gd, Display *dpy, struct _glx_w
/**
* Free a glx_texture_t.
*/
static void attr_unused glx_release_win(struct _glx_data *gd, Display *dpy, struct _glx_win_data *wd) {
static void attr_unused glx_release_win(struct _glx_data *gd, Display *dpy,
struct _glx_win_data *wd) {
glx_release_pixmap(gd, dpy, wd);
glDeleteTextures(1, &wd->texture.texture);
@ -276,9 +279,6 @@ static bool glx_update_fbconfig(struct _glx_data *gd, session_t *ps) {
"correctly");
}
log_trace("%d-bit: %p, 32-bit: %p", ps->depth, gd->fbconfigs[ps->depth]->cfg,
gd->fbconfigs[32]->cfg);
return true;
}
@ -388,7 +388,7 @@ static void *glx_init(session_t *ps) {
}
// Get GLX context
gd->ctx = glXCreateContext(ps->dpy, pvis, None, GL_TRUE);
gd->ctx = glXCreateContext(ps->dpy, pvis, NULL, GL_TRUE);
if (!gd->ctx) {
log_error("Failed to get GLX context.");
@ -502,21 +502,20 @@ static bool attr_unused glx_init_blur(session_t *ps) {
glDeleteFramebuffers(1, &fbo);
}
{
char *lc_numeric_old = strdup(setlocale(LC_NUMERIC, NULL));
// Enforce LC_NUMERIC locale "C" here to make sure decimal point is sane
// Thanks to hiciu for reporting.
setlocale(LC_NUMERIC, "C");
static const char *FRAG_SHADER_BLUR_PREFIX =
"#version 110\n"
static const char *FRAG_SHADER_BLUR_PREFIX = "#version 110\n"
"%s"
"uniform float offset_x;\n"
"uniform float offset_y;\n"
"uniform float factor_center;\n"
"uniform %s tex_scr;\n\n"
"void main() {\n"
" vec4 sum = vec4(0.0, 0.0, 0.0, 0.0);\n";
" vec4 sum = vec4(0.0, 0.0, 0.0, "
"0.0);\n";
static const char *FRAG_SHADER_BLUR_ADD =
" sum += float(%.7g) * %s(tex_scr, vec2(gl_TexCoord[0].x + offset_x "
"* float(%d), gl_TexCoord[0].y + offset_y * float(%d)));\n";
@ -530,10 +529,8 @@ static bool attr_unused glx_init_blur(session_t *ps) {
"}\n";
const bool use_texture_rect = !gd->cap.non_power_of_two_texture;
const char *sampler_type =
(use_texture_rect ? "sampler2DRect" : "sampler2D");
const char *texture_func =
(use_texture_rect ? "texture2DRect" : "texture2D");
const char *sampler_type = (use_texture_rect ? "sampler2DRect" : "sampler2D");
const char *texture_func = (use_texture_rect ? "texture2DRect" : "texture2D");
const char *shader_add = FRAG_SHADER_BLUR_ADD;
char *extension = strdup("");
if (use_texture_rect)
@ -575,8 +572,8 @@ static bool attr_unused glx_init_blur(session_t *ps) {
if (0.0 == val)
continue;
sum += val;
sprintf(pc, shader_add, val, texture_func,
k - wid / 2, j - hei / 2);
sprintf(pc, shader_add, val, texture_func, k - wid / 2,
j - hei / 2);
pc += strlen(pc);
assert(strlen(shader_str) < len);
}
@ -584,20 +581,19 @@ static bool attr_unused glx_init_blur(session_t *ps) {
sprintf(pc, FRAG_SHADER_BLUR_SUFFIX, texture_func, sum);
assert(strlen(shader_str) < len);
ppass->frag_shader =
gl_create_shader(GL_FRAGMENT_SHADER, shader_str);
ppass->frag_shader = gl_create_shader(GL_FRAGMENT_SHADER, shader_str);
free(shader_str);
if (!ppass->frag_shader) {
log_error("Failed to create fragment shader %d.", i);
return false;
goto err;
}
// Build program
ppass->prog = gl_create_program(&ppass->frag_shader, 1);
if (!ppass->prog) {
log_error("Failed to create GLSL program.");
return false;
goto err;
}
// Get uniform addresses
@ -615,16 +611,19 @@ static bool attr_unused glx_init_blur(session_t *ps) {
// Restore LC_NUMERIC
setlocale(LC_NUMERIC, lc_numeric_old);
free(lc_numeric_old);
}
gl_check_err();
return true;
err:
free(extension);
setlocale(LC_NUMERIC, lc_numeric_old);
free(lc_numeric_old);
return false;
}
void *glx_prepare_win(void *backend_data, session_t *ps, win *w) {
struct _glx_data *gd = backend_data;
auto wd = ccalloc(1, struct _glx_win_data);
// Retrieve pixmap parameters, if they aren't provided
if (w->g.depth > OPENGL_MAX_DEPTH) {
log_error("Requested depth %d higher than max possible depth %d.",
@ -659,6 +658,7 @@ void *glx_prepare_win(void *backend_data, session_t *ps, win *w) {
GLX_TEXTURE_FORMAT_EXT, pcfg->texture_fmt, GLX_TEXTURE_TARGET_EXT, tex_tgt, 0,
};
auto wd = ccalloc(1, struct _glx_win_data);
wd->texture.target =
(GLX_TEXTURE_2D_EXT == tex_tgt ? GL_TEXTURE_2D : GL_TEXTURE_RECTANGLE);
wd->texture.y_inverted = pcfg->y_inverted;