Do not choke on zero-sized windows.

Configure requests with zero width or height will always
fail with BadValue and have to be avoided. Same goes for
shm segments of size 0.
This commit is contained in:
Laszlo Agocs 2011-06-01 10:37:30 +02:00
parent 38745b341c
commit 646fcc1bd3
2 changed files with 18 additions and 5 deletions

View File

@ -285,7 +285,10 @@ void QXcbWindow::setGeometry(const QRect &rect)
QPlatformWindow::setGeometry(rect); QPlatformWindow::setGeometry(rect);
const quint32 mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT; const quint32 mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT;
const quint32 values[] = { rect.x(), rect.y(), rect.width(), rect.height() }; const quint32 values[] = { rect.x(),
rect.y(),
qBound(1, rect.width(), XCOORD_MAX),
qBound(1, rect.height(), XCOORD_MAX) };
Q_XCB_CALL(xcb_configure_window(xcb_connection(), m_window, mask, values)); Q_XCB_CALL(xcb_configure_window(xcb_connection(), m_window, mask, values));
} }

View File

@ -98,7 +98,10 @@ QXcbShmImage::QXcbShmImage(QXcbScreen *screen, const QSize &size, uint depth, QI
~0, ~0,
0); 0);
int segmentSize = m_xcb_image->stride * m_xcb_image->height; const int segmentSize = m_xcb_image->stride * m_xcb_image->height;
if (!segmentSize)
return;
int id = shmget(IPC_PRIVATE, segmentSize, IPC_CREAT | 0777); int id = shmget(IPC_PRIVATE, segmentSize, IPC_CREAT | 0777);
if (id == -1) if (id == -1)
qWarning("QXcbShmImage: shmget() failed (%d) for size %d (%dx%d)", qWarning("QXcbShmImage: shmget() failed (%d) for size %d (%dx%d)",
@ -122,10 +125,17 @@ QXcbShmImage::QXcbShmImage(QXcbScreen *screen, const QSize &size, uint depth, QI
void QXcbShmImage::destroy() void QXcbShmImage::destroy()
{ {
Q_XCB_CALL(xcb_shm_detach(xcb_connection(), m_shm_info.shmseg)); const int segmentSize = m_xcb_image ? (m_xcb_image->stride * m_xcb_image->height) : 0;
if (segmentSize)
Q_XCB_CALL(xcb_shm_detach(xcb_connection(), m_shm_info.shmseg));
xcb_image_destroy(m_xcb_image); xcb_image_destroy(m_xcb_image);
shmdt(m_shm_info.shmaddr);
shmctl(m_shm_info.shmid, IPC_RMID, 0); if (segmentSize) {
shmdt(m_shm_info.shmaddr);
shmctl(m_shm_info.shmid, IPC_RMID, 0);
}
if (m_gc) if (m_gc)
Q_XCB_CALL(xcb_free_gc(xcb_connection(), m_gc)); Q_XCB_CALL(xcb_free_gc(xcb_connection(), m_gc));
} }