From 3fe08b5c7cebd1eb7f2525673819423d84abef0e Mon Sep 17 00:00:00 2001 From: hujianwei Date: Sat, 22 Oct 2022 07:13:21 +0000 Subject: [PATCH] Fix various problems encountered * egl.c (AddShmFormat): Fix coding style. * explicit_synchronization.c (HandleSurfaceCommit): Remove redundant NULL check. * run.c (RunStep): Flush clients after completing selection transfers. Fix sizeof when allocating pollfds. * seat.c (CancelResizeOperation): Avoid NULL-pointer dereference when subcompositor is not specified. * shm.c (DereferencePool, CreatePool): Remove redundant checks of pool->size; it can never be zero. * subsurface.c (Setup): Remove redundant NULL check. * text_input.c (SetCursorRectangle): Fix some statements. (FindTextSections, EncodeIMString, CheckStyles, ConvertString) (PreeditString, CommitString): Fix usage of format modifiers in debug trace code. * xdata.c (HandleSelectionNotify): Use selection time, not event time. * xdg_popup.c (MoveWindow, InternalReposition): Remove various redundant checks. --- egl.c | 4 ++-- explicit_synchronization.c | 5 ++--- run.c | 11 +++++++---- seat.c | 2 +- shm.c | 4 +--- subsurface.c | 3 +-- text_input.c | 26 +++++++++++++------------- xdata.c | 8 ++++---- xdg_popup.c | 10 ++-------- 9 files changed, 33 insertions(+), 40 deletions(-) diff --git a/egl.c b/egl.c index 315a767..2ecbbaf 100644 --- a/egl.c +++ b/egl.c @@ -2110,8 +2110,8 @@ static void AddShmFormat (uint32_t format) { shm_formats - = XLRealloc (shm_formats, - sizeof *shm_formats * ++n_shm_formats); + = XLRealloc (shm_formats, (sizeof *shm_formats + * ++n_shm_formats)); shm_formats[n_shm_formats - 1].format = format; } diff --git a/explicit_synchronization.c b/explicit_synchronization.c index f800838..0cd5927 100644 --- a/explicit_synchronization.c +++ b/explicit_synchronization.c @@ -248,9 +248,8 @@ HandleSurfaceCommit (Synchronization *synchronization, Surface *surface) surface. */ surface->release->surface = surface; - if (surface->release - && !(surface->pending_state.pending & PendingBuffer - && surface->pending_state.buffer)) + if (!(surface->pending_state.pending & PendingBuffer + && surface->pending_state.buffer)) wl_resource_post_error (synchronization->resource, NoBuffer, "no buffer attached" " but release provided"); diff --git a/run.c b/run.c index 60ee082..d3e60fd 100644 --- a/run.c +++ b/run.c @@ -203,10 +203,7 @@ RunStep (void) struct pollfd *fds; PollFd **pollfds, *item, *last; - XFlush (compositor.display); - wl_display_flush_clients (compositor.wl_display); - - fds = alloca (sizeof fds * (num_poll_fd + 2)); + fds = alloca (sizeof *fds * (num_poll_fd + 2)); /* This is used as an optimization to not have to loop over the entire descriptor list twice. */ @@ -220,6 +217,12 @@ RunStep (void) /* Drain complete selection transfers. */ FinishTransfers (); + /* FinishTransfers can potentially send events to Wayland clients + and make X requests. Flush after it is called. */ + XFlush (compositor.display); + wl_display_flush_clients (compositor.wl_display); + + /* Obtain the connections. */ x_connection = ConnectionNumber (compositor.display); wl_connection = wl_event_loop_get_fd (compositor.wl_event_loop); diff --git a/seat.c b/seat.c index e0c7f95..3bfc682 100644 --- a/seat.c +++ b/seat.c @@ -2018,7 +2018,7 @@ CancelResizeOperation (Seat *seat, Time time, Subcompositor *subcompositor, /* Ungrab the pointer. */ XIUngrabDevice (compositor.display, seat->master_pointer, - xev->time); + time); if (!subcompositor) return; diff --git a/shm.c b/shm.c index 4d74be2..d548f69 100644 --- a/shm.c +++ b/shm.c @@ -88,8 +88,6 @@ DereferencePool (Pool *pool) /* Cancel the busfault trap. */ if (pool->data != (void *) -1 - /* If the pool is of size 0, no busfault was installed. */ - && pool->size /* If reading from the pool cannot possibly cause SIGBUS, then no bus fault trap was installed. */ && !(pool->flags & PoolCannotSigbus)) @@ -486,7 +484,7 @@ CreatePool (struct wl_client *client, struct wl_resource *resource, /* Begin trapping SIGBUS from this pool. The client may truncate the file without telling us, in which case accessing its contents will cause crashes. */ - if (!(pool->flags & PoolCannotSigbus) && pool->size) + if (!(pool->flags & PoolCannotSigbus)) XLRecordBusfault (pool->data, pool->size); pool->fd = fd; diff --git a/subsurface.c b/subsurface.c index 9f29de4..5c81c62 100644 --- a/subsurface.c +++ b/subsurface.c @@ -737,8 +737,7 @@ Setup (Surface *surface, Role *role) ViewInsert (parent_view, surface->view); /* Now move the subsurface to its initial location (0, 0) */ - if (subsurface->parent) - MoveFractional (subsurface); + MoveFractional (subsurface); /* Now add the subsurface to the parent's list of subsurfaces. */ subsurface->parent->subsurfaces diff --git a/text_input.c b/text_input.c index 0feb053..8b911b1 100644 --- a/text_input.c +++ b/text_input.c @@ -485,7 +485,7 @@ SetCursorRectangle (struct wl_client *client, struct wl_resource *resource, if ((input->current_state.pending & PendingCursorRectangle /* PendingEnabled will clear the current state's cursor rectangle. */ - && !input->pending_state.pending & PendingEnabled) + && !(input->pending_state.pending & PendingEnabled)) && x == input->current_state.cursor_x && y == input->current_state.cursor_y && width == input->current_state.cursor_width @@ -1956,8 +1956,8 @@ FindTextSections (const char *string, size_t string_size, while (factor) { found = memrchr (string, '\n', found - string); - DebugPrint ("LineStart processing found %p %zd", found, - found - string); + DebugPrint ("LineStart processing found %p %td", found, + found ? found - string : 0); if (!found) { @@ -2126,7 +2126,7 @@ EncodeIMString (const char *input, size_t input_size, int *chars) { rc = iconv (cd, &inbuf, &input_size, &outptr, &outbytesleft); - DebugPrint ("iconv gave: %tu", rc); + DebugPrint ("iconv gave: %zu", rc); if (rc == (size_t) -1) { @@ -2144,7 +2144,7 @@ EncodeIMString (const char *input, size_t input_size, int *chars) outsize += BUFSIZ; outbytesleft += BUFSIZ; - DebugPrint ("expanding outsize to %tu, outbytesleft now %tu", + DebugPrint ("expanding outsize to %zu, outbytesleft now %zu", outsize, outbytesleft); } else @@ -2167,7 +2167,7 @@ EncodeIMString (const char *input, size_t input_size, int *chars) } /* The conversion finished. */ - DebugPrint ("conversion finished, size_out %tu", + DebugPrint ("conversion finished, size_out %zu", outsize - outbytesleft); /* Now, count the number of multibyte characters. */ @@ -2624,7 +2624,7 @@ CheckStyles (XIM xim) /* Otherwise, find the best style in our order of preference. */ for (i = 0; xim_style_order[i] != XimStyleNone; ++i) { - DebugPrint ("considering style: %u", xim_style_order[i]); + DebugPrint ("considering style: %d", (int) xim_style_order[i]); switch (xim_style_order[i]) { @@ -2945,7 +2945,7 @@ ConvertString (char *buffer, size_t nbytes, size_t *size_out) outsize = BUFSIZ; outbytesleft = outsize; - DebugPrint ("converting string of size %tu", nbytes); + DebugPrint ("converting string of size %zu", nbytes); /* Reset the cd state. */ iconv (current_cd, NULL, NULL, &outptr, &outbytesleft); @@ -2956,7 +2956,7 @@ ConvertString (char *buffer, size_t nbytes, size_t *size_out) rc = iconv (current_cd, &buffer, &nbytes, &outptr, &outbytesleft); - DebugPrint ("iconv gave: %tu", rc); + DebugPrint ("iconv gave: %zu", rc); if (rc == (size_t) -1) { @@ -2974,7 +2974,7 @@ ConvertString (char *buffer, size_t nbytes, size_t *size_out) outsize += BUFSIZ; outbytesleft += BUFSIZ; - DebugPrint ("expanding outsize to %tu, outbytesleft now %tu", + DebugPrint ("expanding outsize to %zu, outbytesleft now %zu", outsize, outbytesleft); } else @@ -2983,7 +2983,7 @@ ConvertString (char *buffer, size_t nbytes, size_t *size_out) } finish: - DebugPrint ("conversion finished, size_out %tu", + DebugPrint ("conversion finished, size_out %zu", outsize - outbytesleft); /* Return outbuf and the number of bytes put in it. */ @@ -3032,7 +3032,7 @@ PreeditString (TextInput *input, const char *buffer, end += skip; } - DebugPrint ("end-start (%p-%p): %zd", end, start, + DebugPrint ("end-start (%p-%p): %td", end, start, end - start); /* Now, start to end contain a UTF-8 sequence less than 4000 @@ -3101,7 +3101,7 @@ CommitString (TextInput *input, const char *buffer, end += skip; } - DebugPrint ("end-start (%p-%p): %zd", end, start, + DebugPrint ("end-start (%p-%p): %td", end, start, end - start); /* Now, start to end contain a UTF-8 sequence less than 4000 diff --git a/xdata.c b/xdata.c index e18649a..8eb7ef1 100644 --- a/xdata.c +++ b/xdata.c @@ -1147,14 +1147,14 @@ HandleSelectionNotify (XFixesSelectionNotifyEvent *event) if (event->owner != None && event->selection == CLIPBOARD) - NoticeClipboardChanged (event->timestamp); + NoticeClipboardChanged (event->selection_timestamp); else if (event->selection == CLIPBOARD) - NoticeClipboardCleared (event->timestamp); + NoticeClipboardCleared (event->selection_timestamp); else if (event->owner != None && event->selection == XA_PRIMARY) - NoticePrimaryChanged (event->timestamp); + NoticePrimaryChanged (event->selection_timestamp); else if (event->selection == XA_PRIMARY) - NoticePrimaryCleared (event->timestamp); + NoticePrimaryCleared (event->selection_timestamp); } Bool diff --git a/xdg_popup.c b/xdg_popup.c index 332edc1..8c83d1d 100644 --- a/xdg_popup.c +++ b/xdg_popup.c @@ -279,10 +279,7 @@ MoveWindow (XdgPopup *popup) int geometry_x, geometry_y, x, y; Window window; - /* No parent was specified. */ - if (!popup->parent) - return; - + /* No parent was specified or the role is detached. */ if (!popup->role || !popup->parent) return; @@ -416,10 +413,7 @@ InternalReposition (XdgPopup *popup) int x, y, width, height; FrameClock *clock; - /* No parent was specified. */ - if (!popup->parent) - return; - + /* No parent was specified or the role is detached. */ if (!popup->role || !popup->parent) return;