From 5df4c9510e559dfb6bd14a920a95903515fcce41 Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Thu, 13 Oct 2016 23:19:58 +0100 Subject: [PATCH 5/6] Marshalling tests: make integer generation more concise This also avoids -Wswitch-default warnings. [smcv: split out from a larger commit] Reviewed-by: Simon McVittie Bug: https://bugs.freedesktop.org/show_bug.cgi?id=98191 --- dbus/dbus-marshal-recursive-util.c | 56 +++++++++++--------------------------- 1 file changed, 16 insertions(+), 40 deletions(-) diff --git a/dbus/dbus-marshal-recursive-util.c b/dbus/dbus-marshal-recursive-util.c index 7c5bb5c..d43972f 100644 --- a/dbus/dbus-marshal-recursive-util.c +++ b/dbus/dbus-marshal-recursive-util.c @@ -2070,27 +2070,15 @@ int16_from_seed (int seed) * just use seed itself, but that would only ever touch one byte of * the int so would miss some kinds of bug. */ - dbus_int16_t v; + static const dbus_int16_t v_of_seed[5] = { + SAMPLE_INT16, + SAMPLE_INT16_ALTERNATE, + -1, + _DBUS_INT16_MAX, + 1 + }; - v = 42; /* just to quiet compiler afaik */ - switch (seed % 5) - { - case 0: - v = SAMPLE_INT16; - break; - case 1: - v = SAMPLE_INT16_ALTERNATE; - break; - case 2: - v = -1; - break; - case 3: - v = _DBUS_INT16_MAX; - break; - case 4: - v = 1; - break; - } + dbus_int16_t v = v_of_seed[seed % _DBUS_N_ELEMENTS(v_of_seed)]; if (seed > 1) v *= seed; /* wraps around eventually, which is fine */ @@ -2207,27 +2195,15 @@ int32_from_seed (int seed) * just use seed itself, but that would only ever touch one byte of * the int so would miss some kinds of bug. */ - dbus_int32_t v; + static const dbus_int32_t v_of_seed[5] = { + SAMPLE_INT32, + SAMPLE_INT32_ALTERNATE, + -1, + _DBUS_INT_MAX, + 1 + }; - v = 42; /* just to quiet compiler afaik */ - switch (seed % 5) - { - case 0: - v = SAMPLE_INT32; - break; - case 1: - v = SAMPLE_INT32_ALTERNATE; - break; - case 2: - v = -1; - break; - case 3: - v = _DBUS_INT_MAX; - break; - case 4: - v = 1; - break; - } + dbus_int32_t v = v_of_seed[seed % _DBUS_N_ELEMENTS(v_of_seed)]; if (seed > 1) v *= seed; /* wraps around eventually, which is fine */ -- 2.9.3