spice-vdagent/SOURCES/0003-x11-randr-simplest-fix...

75 lines
3.2 KiB
Diff
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

From 7976dc31af511315fa7b83cfbb1e3bf4b613f84b Mon Sep 17 00:00:00 2001
From: Victor Toso <me@victortoso.com>
Date: Fri, 12 Jul 2019 11:12:41 +0200
Subject: [PATCH 3/9] x11-randr: simplest fix for address-of-packed-member
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The struct type for width/height is uint32_t while we are trying to
access and change it with int* - code can be improved a bit in following
patches but this one fixes the warning by copying the value from the
struct and copying back new value afterwards.
Also:
- Moved variables to internal scope;
- Added braces to inner if;
> src/vdagent/x11-randr.c: In function zero_base_monitors:
> src/vdagent/x11-randr.c:621:28: error: taking address of packed member of
> struct VDAgentMonConfig may result in an unaligned pointer value
> [-Werror=address-of-packed-member]
> 621 | mon_width = (int *)&mon_config->monitors[i].width;
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> src/vdagent/x11-randr.c:622:29: error: taking address of packed member of
> struct VDAgentMonConfig may result in an unaligned pointer value
> [-Werror=address-of-packed-member]
> 622 | mon_height = (int *)&mon_config->monitors[i].height;
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Signed-off-by: Victor Toso <victortoso@redhat.com>
Acked-by: Frediano Ziglio <fziglio@redhat.com>
---
src/vdagent/x11-randr.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/src/vdagent/x11-randr.c b/src/vdagent/x11-randr.c
index d000e28..4b022d6 100644
--- a/src/vdagent/x11-randr.c
+++ b/src/vdagent/x11-randr.c
@@ -611,20 +611,24 @@ static void zero_base_monitors(struct vdagent_x11 *x11,
int *width, int *height)
{
int i, min_x = INT_MAX, min_y = INT_MAX, max_x = INT_MIN, max_y = INT_MIN;
- int *mon_height, *mon_width;
for (i = 0; i < mon_config->num_of_monitors; i++) {
- if (!monitor_enabled(&mon_config->monitors[i]))
+ int mon_height, mon_width;
+
+ if (!monitor_enabled(&mon_config->monitors[i])) {
continue;
+ }
mon_config->monitors[i].x &= ~7;
mon_config->monitors[i].width &= ~7;
- mon_width = (int *)&mon_config->monitors[i].width;
- mon_height = (int *)&mon_config->monitors[i].height;
- constrain_to_screen(x11, mon_width, mon_height);
+ mon_width = mon_config->monitors[i].width;
+ mon_height = mon_config->monitors[i].height;
+ constrain_to_screen(x11, &mon_width, &mon_height);
min_x = MIN(mon_config->monitors[i].x, min_x);
min_y = MIN(mon_config->monitors[i].y, min_y);
- max_x = MAX(mon_config->monitors[i].x + *mon_width, max_x);
- max_y = MAX(mon_config->monitors[i].y + *mon_height, max_y);
+ max_x = MAX(mon_config->monitors[i].x + mon_width, max_x);
+ max_y = MAX(mon_config->monitors[i].y + mon_height, max_y);
+ mon_config->monitors[i].width = mon_width;
+ mon_config->monitors[i].height = mon_height;
}
if (min_x != 0 || min_y != 0) {
syslog(LOG_ERR, "%s: agent config %d,%d rooted, adjusting to 0,0.",
--
2.21.0