From fc9ca6c71a5bf8cb87dc9bebca94cf5169a22649 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Mon, 5 Oct 2020 03:13:29 -0700 Subject: [PATCH] clang-tidy: do not use else after return Found with readability-else-after-return Easier to read. Signed-off-by: Rosen Penev --- server/dcc-send.cpp | 50 ++++++++++++++-------------------- server/display-channel.cpp | 3 +- server/glz-encoder-dict.c | 4 +-- server/main-channel-client.cpp | 8 ++++-- server/main-channel.cpp | 23 ++++++++-------- server/mjpeg-encoder.c | 3 +- server/red-channel-client.cpp | 14 ++++++---- server/red-channel.cpp | 6 ++-- server/red-replay-qxl.cpp | 3 +- server/red-stream.cpp | 6 ++-- server/reds.cpp | 3 +- server/sound.cpp | 8 +++--- server/spice-bitmap-utils.c | 41 ++++++++++++++-------------- server/websocket.c | 3 +- 14 files changed, 84 insertions(+), 91 deletions(-) diff --git a/server/dcc-send.cpp b/server/dcc-send.cpp index 6a41ae7c..1031c6a6 100644 --- a/server/dcc-send.cpp +++ b/server/dcc-send.cpp @@ -142,9 +142,8 @@ static bool is_bitmap_lossy(DisplayChannelClient *dcc, SpiceImage *image, SpiceR if (dcc_pixmap_cache_hit(dcc, image->descriptor.id, &is_hit_lossy)) { out_data->type = BITMAP_DATA_TYPE_CACHE; return is_hit_lossy; - } else { - out_data->type = BITMAP_DATA_TYPE_BITMAP_TO_CACHE; } + out_data->type = BITMAP_DATA_TYPE_BITMAP_TO_CACHE; } else { out_data->type = BITMAP_DATA_TYPE_BITMAP; } @@ -166,10 +165,9 @@ static bool is_brush_lossy(DisplayChannelClient *dcc, SpiceBrush *brush, if (brush->type == SPICE_BRUSH_TYPE_PATTERN) { return is_bitmap_lossy(dcc, brush->u.pattern.pat, NULL, out_data); - } else { - out_data->type = BITMAP_DATA_TYPE_INVALID; - return FALSE; } + out_data->type = BITMAP_DATA_TYPE_INVALID; + return FALSE; } static RedChannelClient::Pipe::iterator get_pipe_tail(RedChannelClient::Pipe& pipe) @@ -388,11 +386,9 @@ static FillBitsType fill_bits(DisplayChannelClient *dcc, SpiceMarshaller *m, stat_inc_counter(display->priv->cache_hits_counter, 1); pthread_mutex_unlock(&dcc->priv->pixmap_cache->lock); return FILL_BITS_TYPE_CACHE; - } else { - pixmap_cache_unlocked_set_lossy(dcc->priv->pixmap_cache, simage->descriptor.id, - FALSE); - image.descriptor.flags |= SPICE_IMAGE_FLAGS_CACHE_REPLACE_ME; } + pixmap_cache_unlocked_set_lossy(dcc->priv->pixmap_cache, simage->descriptor.id, FALSE); + image.descriptor.flags |= SPICE_IMAGE_FLAGS_CACHE_REPLACE_ME; } } @@ -460,27 +456,23 @@ static FillBitsType fill_bits(DisplayChannelClient *dcc, SpiceMarshaller *m, } pthread_mutex_unlock(&dcc->priv->pixmap_cache->lock); return FILL_BITS_TYPE_BITMAP; - } else { - red_display_add_image_to_pixmap_cache(dcc, simage, &image, - comp_send_data.is_lossy); - - spice_marshall_Image(m, &image, - &bitmap_palette_out, &lzplt_palette_out); - spice_assert(bitmap_palette_out == NULL); - - marshaller_add_compressed(m, comp_send_data.comp_buf, - comp_send_data.comp_buf_size); - - if (lzplt_palette_out && comp_send_data.lzplt_palette) { - spice_marshall_Palette(lzplt_palette_out, comp_send_data.lzplt_palette); - } - - spice_assert(!comp_send_data.is_lossy || can_lossy); - pthread_mutex_unlock(&dcc->priv->pixmap_cache->lock); - return (comp_send_data.is_lossy ? FILL_BITS_TYPE_COMPRESS_LOSSY : - FILL_BITS_TYPE_COMPRESS_LOSSLESS); } - break; + red_display_add_image_to_pixmap_cache(dcc, simage, &image, comp_send_data.is_lossy); + + spice_marshall_Image(m, &image, &bitmap_palette_out, &lzplt_palette_out); + spice_assert(bitmap_palette_out == NULL); + + marshaller_add_compressed(m, comp_send_data.comp_buf, + comp_send_data.comp_buf_size); + + if (lzplt_palette_out && comp_send_data.lzplt_palette) { + spice_marshall_Palette(lzplt_palette_out, comp_send_data.lzplt_palette); + } + + spice_assert(!comp_send_data.is_lossy || can_lossy); + pthread_mutex_unlock(&dcc->priv->pixmap_cache->lock); + return (comp_send_data.is_lossy ? FILL_BITS_TYPE_COMPRESS_LOSSY : + FILL_BITS_TYPE_COMPRESS_LOSSLESS); } case SPICE_IMAGE_TYPE_QUIC: red_display_add_image_to_pixmap_cache(dcc, simage, &image, FALSE); diff --git a/server/display-channel.cpp b/server/display-channel.cpp index 0e2b6890..50059636 100644 --- a/server/display-channel.cpp +++ b/server/display-channel.cpp @@ -882,7 +882,8 @@ static bool current_add(DisplayChannel *display, Ring *ring, Drawable *drawable) * on to the next one. */ now = ring_next(ring, now); continue; - } else if (sibling->type != TREE_ITEM_TYPE_SHADOW) { + } + if (sibling->type != TREE_ITEM_TYPE_SHADOW) { /* there is an overlap between the two regions */ /* NOTE: Shadow types represent a source region for a COPY_BITS * operation, they don't represent a region that will be drawn. diff --git a/server/glz-encoder-dict.c b/server/glz-encoder-dict.c index 72e3d1bb..6a1da292 100644 --- a/server/glz-encoder-dict.c +++ b/server/glz-encoder-dict.c @@ -264,9 +264,9 @@ static inline int __get_pixels_num(LzImageType image_type, unsigned int num_line { if (IS_IMAGE_TYPE_RGB[image_type]) { return num_lines * stride / RGB_BYTES_PER_PIXEL[image_type]; - } else { - return num_lines * stride * PLT_PIXELS_PER_BYTE[image_type]; } + + return num_lines * stride * PLT_PIXELS_PER_BYTE[image_type]; } static void __glz_dictionary_window_segs_realloc(SharedDictionary *dict) diff --git a/server/main-channel-client.cpp b/server/main-channel-client.cpp index d815ad24..d1f031cc 100644 --- a/server/main-channel-client.cpp +++ b/server/main-channel-client.cpp @@ -115,12 +115,14 @@ uint8_t *MainChannelClient::alloc_recv_buf(uint16_t type, uint32_t size) if (type == SPICE_MSGC_MAIN_AGENT_DATA) { RedChannel *channel = get_channel(); return reds_get_agent_data_buffer(channel->get_server(), this, size); - } else if (size > sizeof(priv->recv_buf)) { + } + + if (size > sizeof(priv->recv_buf)) { /* message too large, caller will log a message and close the connection */ return NULL; - } else { - return priv->recv_buf; } + + return priv->recv_buf; } void MainChannelClient::release_recv_buf(uint16_t type, uint32_t size, uint8_t *msg) diff --git a/server/main-channel.cpp b/server/main-channel.cpp index fefda684..4abfd3bc 100644 --- a/server/main-channel.cpp +++ b/server/main-channel.cpp @@ -258,20 +258,19 @@ int MainChannel::migrate_connect(RedsMigSpice *new_mig_target, int try_seamless) if (!try_seamless) { return main_channel_connect_semi_seamless(this); - } else { - RedChannelClient *rcc; - GList *clients = get_clients(); - - /* just test the first one */ - rcc = (RedChannelClient*) g_list_nth_data(clients, 0); - - if (!rcc->test_remote_cap(SPICE_MAIN_CAP_SEAMLESS_MIGRATE)) { - return main_channel_connect_semi_seamless(this); - } else { - return main_channel_connect_seamless(this); - } } + RedChannelClient *rcc; + GList *clients = get_clients(); + + /* just test the first one */ + rcc = (RedChannelClient*) g_list_nth_data(clients, 0); + + if (!rcc->test_remote_cap(SPICE_MAIN_CAP_SEAMLESS_MIGRATE)) { + return main_channel_connect_semi_seamless(this); + } + + return main_channel_connect_seamless(this); } void MainChannel::migrate_cancel_wait() diff --git a/server/mjpeg-encoder.c b/server/mjpeg-encoder.c index 0b4f5a4c..7d2482a6 100644 --- a/server/mjpeg-encoder.c +++ b/server/mjpeg-encoder.c @@ -1020,9 +1020,8 @@ static void mjpeg_encoder_decrease_bit_rate(MJpegEncoder *encoder) if (now - rate_control->warmup_start_time < MJPEG_WARMUP_TIME) { spice_debug("during warmup. ignoring"); return; - } else { - rate_control->warmup_start_time = 0; } + rate_control->warmup_start_time = 0; } if (bit_rate_info->num_enc_frames > MJPEG_BIT_RATE_EVAL_MIN_NUM_FRAMES || diff --git a/server/red-channel-client.cpp b/server/red-channel-client.cpp index f39c6d6a..635d1f0a 100644 --- a/server/red-channel-client.cpp +++ b/server/red-channel-client.cpp @@ -1003,9 +1003,11 @@ static int red_peer_receive(RedStream *stream, uint8_t *buf, uint32_t size) spice_assert(now == -1); if (errno == EAGAIN) { break; - } else if (errno == EINTR) { + } + if (errno == EINTR) { continue; - } else if (errno != EPIPE) { + } + if (errno != EPIPE) { g_warning("%s", strerror(errno)); } return -1; @@ -1214,7 +1216,8 @@ void RedChannelClientPrivate::handle_pong(SpiceMsgPing *ping) if (latency_monitor.state == PING_STATE_WARMUP) { latency_monitor.state = PING_STATE_LATENCY; return; - } else if (latency_monitor.state != PING_STATE_LATENCY) { + } + if (latency_monitor.state != PING_STATE_LATENCY) { spice_warning("unexpected"); return; } @@ -1631,10 +1634,9 @@ bool RedChannelClient::wait_outgoing_item(int64_t timeout) if (blocked) { spice_warning("timeout"); return FALSE; - } else { - spice_assert(no_item_being_sent()); - return TRUE; } + spice_assert(no_item_being_sent()); + return TRUE; } bool RedChannelClient::no_item_being_sent() const diff --git a/server/red-channel.cpp b/server/red-channel.cpp index 282d304a..d4830c6a 100644 --- a/server/red-channel.cpp +++ b/server/red-channel.cpp @@ -510,10 +510,10 @@ bool RedChannel::wait_all_sent(int64_t timeout) max_pipe_size, blocked); red_channel_disconnect_if_pending_send(this); return FALSE; - } else { - spice_assert(red_channel_no_item_being_sent(this)); - return TRUE; } + + spice_assert(red_channel_no_item_being_sent(this)); + return TRUE; } RedsState* RedChannel::get_server() diff --git a/server/red-replay-qxl.cpp b/server/red-replay-qxl.cpp index 2fb1e9ab..83ffa22f 100644 --- a/server/red-replay-qxl.cpp +++ b/server/red-replay-qxl.cpp @@ -1095,9 +1095,8 @@ static QXLPHYSICAL red_replay_drawable(SpiceReplay *replay, uint32_t flags) } if (flags & QXL_COMMAND_FLAG_COMPAT) { return QXLPHYSICAL_FROM_PTR(red_replay_compat_drawable(replay, flags)); - } else { - return QXLPHYSICAL_FROM_PTR(red_replay_native_drawable(replay, flags)); } + return QXLPHYSICAL_FROM_PTR(red_replay_native_drawable(replay, flags)); } static QXLUpdateCmd *red_replay_update_cmd(SpiceReplay *replay) diff --git a/server/red-stream.cpp b/server/red-stream.cpp index 8a01857d..df4ddbb2 100644 --- a/server/red-stream.cpp +++ b/server/red-stream.cpp @@ -262,9 +262,8 @@ bool red_stream_set_auto_flush(RedStream *s, bool auto_flush) if (socket_set_cork(s->socket, 1)) { s->priv->use_cork = false; return false; - } else { - s->priv->corked = true; } + s->priv->corked = true; } else if (s->priv->corked) { socket_set_cork(s->socket, 0); s->priv->corked = false; @@ -532,9 +531,8 @@ RedStreamSslStatus red_stream_ssl_accept(RedStream *stream) ssl_error == SSL_ERROR_WANT_WRITE)) { if (ssl_error == SSL_ERROR_WANT_READ) { return RED_STREAM_SSL_STATUS_WAIT_FOR_READ; - } else { - return RED_STREAM_SSL_STATUS_WAIT_FOR_WRITE; } + return RED_STREAM_SSL_STATUS_WAIT_FOR_WRITE; } red_dump_openssl_errors(); diff --git a/server/reds.cpp b/server/reds.cpp index 58faccc3..1bd36ac9 100644 --- a/server/reds.cpp +++ b/server/reds.cpp @@ -4368,9 +4368,8 @@ static int calc_compression_level(RedsState *reds) if ((reds_get_streaming_video(reds) != SPICE_STREAM_VIDEO_OFF) || (spice_server_get_image_compression(reds) != SPICE_IMAGE_COMPRESSION_QUIC)) { return 0; - } else { - return 1; } + return 1; } void reds_on_ic_change(RedsState *reds) diff --git a/server/sound.cpp b/server/sound.cpp index af2c1bda..67e3b268 100644 --- a/server/sound.cpp +++ b/server/sound.cpp @@ -497,9 +497,9 @@ static int snd_playback_send_ctl(PlaybackChannelClient *playback_client) if ((client->client_active = client->active)) { return snd_playback_send_start(playback_client); - } else { - return snd_playback_send_stop(playback_client); } + + return snd_playback_send_stop(playback_client); } static bool snd_record_send_start(RecordChannelClient *record_client) @@ -536,9 +536,9 @@ static int snd_record_send_ctl(RecordChannelClient *record_client) if ((client->client_active = client->active)) { return snd_record_send_start(record_client); - } else { - return snd_record_send_stop(record_client); } + + return snd_record_send_stop(record_client); } static bool snd_record_send_volume(RecordChannelClient *record_client) diff --git a/server/spice-bitmap-utils.c b/server/spice-bitmap-utils.c index c0df4fac..50903e38 100644 --- a/server/spice-bitmap-utils.c +++ b/server/spice-bitmap-utils.c @@ -87,9 +87,9 @@ BitmapGradualType bitmap_get_graduality_level(SpiceBitmap *bitmap) if (score < GRADUAL_MEDIUM_SCORE_TH) { return BITMAP_GRADUAL_MEDIUM; - } else { - return BITMAP_GRADUAL_LOW; } + + return BITMAP_GRADUAL_LOW; } int bitmap_has_extra_stride(SpiceBitmap *bitmap) @@ -97,25 +97,26 @@ int bitmap_has_extra_stride(SpiceBitmap *bitmap) spice_assert(bitmap); if (bitmap_fmt_is_rgb(bitmap->format)) { return ((bitmap->x * bitmap_fmt_get_bytes_per_pixel(bitmap->format)) < bitmap->stride); - } else { - switch (bitmap->format) { - case SPICE_BITMAP_FMT_8BIT: - return (bitmap->x < bitmap->stride); - case SPICE_BITMAP_FMT_4BIT_BE: - case SPICE_BITMAP_FMT_4BIT_LE: { - int bytes_width = SPICE_ALIGN(bitmap->x, 2) >> 1; - return bytes_width < bitmap->stride; - } - case SPICE_BITMAP_FMT_1BIT_BE: - case SPICE_BITMAP_FMT_1BIT_LE: { - int bytes_width = SPICE_ALIGN(bitmap->x, 8) >> 3; - return bytes_width < bitmap->stride; - } - default: - spice_error("invalid image type %u", bitmap->format); - return 0; - } } + + switch (bitmap->format) { + case SPICE_BITMAP_FMT_8BIT: + return (bitmap->x < bitmap->stride); + case SPICE_BITMAP_FMT_4BIT_BE: + case SPICE_BITMAP_FMT_4BIT_LE: { + int bytes_width = SPICE_ALIGN(bitmap->x, 2) >> 1; + return bytes_width < bitmap->stride; + } + case SPICE_BITMAP_FMT_1BIT_BE: + case SPICE_BITMAP_FMT_1BIT_LE: { + int bytes_width = SPICE_ALIGN(bitmap->x, 8) >> 3; + return bytes_width < bitmap->stride; + } + default: + spice_error("invalid image type %u", bitmap->format); + return 0; + } + return 0; } diff --git a/server/websocket.c b/server/websocket.c index 82b20b49..6b974cce 100644 --- a/server/websocket.c +++ b/server/websocket.c @@ -369,7 +369,8 @@ int websocket_read(RedsWebSocket *ws, uint8_t *buf, size_t size, unsigned *flags websocket_clear_frame(frame); send_pending_data(ws); return 0; - } else if (frame->type == BINARY_FRAME || frame->type == TEXT_FRAME) { + } + if (frame->type == BINARY_FRAME || frame->type == TEXT_FRAME) { rc = 0; if (frame->expected_len > frame->relayed) { rc = ws->raw_read(ws->raw_stream, buf,