[gnome-network-displays/cc-tmp: 73/80] cc: assert sizeof for header_buffer and waiting_for




commit 791b202c32c0cc45e58224002a1bb034debd5ae2
Author: Anupam Kumar <kyteinsky gmail com>
Date:   Tue Sep 6 17:59:42 2022 +0530

    cc: assert sizeof for header_buffer and waiting_for

 src/cc/cc-comm.c | 3 +++
 src/cc/cc-ctrl.c | 7 +++++--
 2 files changed, 8 insertions(+), 2 deletions(-)
---
diff --git a/src/cc/cc-comm.c b/src/cc/cc-comm.c
index 332ff48..709aa09 100644
--- a/src/cc/cc-comm.c
+++ b/src/cc/cc-comm.c
@@ -194,6 +194,9 @@ cc_comm_header_read_cb (GObject      *source_object,
       return;
     }
 
+  /* be sure the size of guint32 is 4 bytes */
+  G_STATIC_ASSERT (sizeof (comm->header_buffer) == sizeof (guint32));
+
   /* if everything is well, read all `io_bytes` */
   message_size = GINT32_FROM_BE (comm->header_buffer);
   g_debug ("CcComm: Message size: %d", message_size);
diff --git a/src/cc/cc-ctrl.c b/src/cc/cc-ctrl.c
index dfe5032..d9e6800 100644
--- a/src/cc/cc-ctrl.c
+++ b/src/cc/cc-ctrl.c
@@ -651,10 +651,13 @@ cc_ctrl_connection_init (CcCtrl *ctrl, gchar *remote_address)
   /* since tls_send is a synchronous call */
   ctrl->state = CC_CTRL_STATE_CONNECTED;
 
-  /* send pings to device every 5 seconds */
+  /* keeps the connection alive */
   ctrl->ping_timeout_handle = g_timeout_add_seconds (5, G_SOURCE_FUNC (cc_ctrl_send_ping), ctrl);
 
-  /* check waiting for every 15 seconds */
+  /* assert waiting_for can accmodate all the bits */
+  G_STATIC_ASSERT (sizeof (ctrl->waiting_for) * 8 >= CC_RWAIT_TYPE_UNKNOWN);
+
+  /* timeout waiting for messages */
   ctrl->waiting_check_timeout_handle = g_timeout_add_seconds (CC_MAX_MESSAGE_TIMEOUT,
                                                               G_SOURCE_FUNC (cc_ctrl_check_waiting_for),
                                                               ctrl);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]