From 4aaef353d4a3d95d026a230ffe9151b9f27596d6 Mon Sep 17 00:00:00 2001 From: jpark37 Date: Mon, 12 Aug 2019 08:05:38 -0700 Subject: [PATCH] libobs-opengl: Fix gl_error_to_str Tweaked function to address some issues: compiler warnings, skipped entries, and type safety. --- libobs-opengl/gl-helpers.h | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/libobs-opengl/gl-helpers.h b/libobs-opengl/gl-helpers.h index 1e38c90b2..82de9fbae 100644 --- a/libobs-opengl/gl-helpers.h +++ b/libobs-opengl/gl-helpers.h @@ -17,9 +17,12 @@ #pragma once -static char *gl_error_to_str(GLenum errorcode) +static const char *gl_error_to_str(GLenum errorcode) { - static void *err_to_str[][2] = { + static const struct { + GLenum error; + const char *str; + } err_to_str[] = { { GL_INVALID_ENUM, "GL_INVALID_ENUM", @@ -48,17 +51,12 @@ static char *gl_error_to_str(GLenum errorcode) GL_STACK_OVERFLOW, "GL_STACK_OVERFLOW", }, - { - NULL, - "Unknown", - }, }; - int i = 0; - while ((GLenum)err_to_str[i][0] != errorcode || - err_to_str[i][0] == NULL) { - i += 2; + for (size_t i = 0; i < sizeof(err_to_str) / sizeof(*err_to_str); i++) { + if (err_to_str[i].error == errorcode) + return err_to_str[i].str; } - return err_to_str[i][1]; + return "Unknown"; } /*