[client] Fix compiler warnings about potentially uninitialized variables

Build failed with _FORTIFY_SOURCE enabled because the compiler couldn't
ensure the switch statements didn't hit the default arm and thus wouldn't
define the variables. Adding a statically failing assert makes sure that
all code paths either define the variables or fail early.

$ cd client
$ env CFLAGS='-O1 -D_FORTIFY_SOURCE=1' cmake -B build/
$ make -C build
[...]
client/renderers/EGL/egl.c: In function ‘egl_calc_mouse_size’:
client/renderers/EGL/egl.c:299:36: error: ‘h’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  299 |         (this->mouseHeight * (1.0f / h)) * this->scaleY
      |                              ~~~~~~^~~~
This commit is contained in:
Xiretza 2021-01-19 16:06:49 +01:00 committed by Geoffrey McRae
parent 6d162cf92d
commit 31ea93dd0d
2 changed files with 11 additions and 0 deletions

View File

@ -34,6 +34,8 @@ Place, Suite 330, Boston, MA 02111-1307 USA
#include <wayland-egl.h> #include <wayland-egl.h>
#endif #endif
#include <assert.h>
#include "app.h" #include "app.h"
#include "model.h" #include "model.h"
#include "shader.h" #include "shader.h"
@ -288,6 +290,9 @@ static void egl_calc_mouse_size(struct Inst * this)
w = this->format.height; w = this->format.height;
h = this->format.width; h = this->format.width;
break; break;
default:
assert(!"unreachable");
} }
switch((this->format.rotate + this->rotate) % LG_ROTATE_MAX) switch((this->format.rotate + this->rotate) % LG_ROTATE_MAX)

View File

@ -192,6 +192,9 @@ static void updatePositionInfo(void)
srcW = g_state.srcSize.y; srcW = g_state.srcSize.y;
srcH = g_state.srcSize.x; srcH = g_state.srcSize.x;
break; break;
default:
assert(!"unreachable");
} }
if (params.keepAspect) if (params.keepAspect)
@ -1242,6 +1245,9 @@ inline static void localCurToGuest(struct DoublePoint *guest)
* g_cursor.scale.y; * g_cursor.scale.y;
guest->y = (point.x - g_state.dstRect.x) * g_cursor.scale.x; guest->y = (point.x - g_state.dstRect.x) * g_cursor.scale.x;
break; break;
default:
assert(!"unreachable");
} }
} }