dbus: use correct types for edge events
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Tue, 1 Oct 2024 12:54:17 +0000 (14:54 +0200)
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Tue, 1 Oct 2024 18:07:47 +0000 (20:07 +0200)
On 32-bit architectures the size of a gulong will typically be 4 bytes
while we try to package an 8-byte integer when creating the edge event
variant. The client also expects wrong types and crashes. Use strict
type sizes for sending the events.

Closes: https://github.com/brgl/libgpiod/issues/103
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
dbus/client/monitor.c
dbus/manager/daemon.c

index 292b2bf67a7c918ff36cc7d79582af6faf658613..3bd25b870f9ded5e1078821ee1bcfff5d5e755ab 100644 (file)
@@ -16,14 +16,14 @@ static void on_edge_event(GpiodbusLine *line, GVariant *args,
                          gpointer user_data G_GNUC_UNUSED)
 {
        const char *name = gpiodbus_line_get_name(line);
-       gulong global_seqno, line_seqno;
-       guint64 timestamp;
-       gint edge;
+       guint64 global_seqno, line_seqno, timestamp;
+       gint32 edge;
 
        g_variant_get(args, "(ittt)", &edge, &timestamp,
                      &global_seqno, &line_seqno);
 
-       g_print("%lu %s ", timestamp, edge ? "rising " : "falling");
+       g_print("%"G_GUINT64_FORMAT" %s ",
+               timestamp, edge ? "rising " : "falling");
        if (strlen(name))
                g_print("\"%s\"\n", name);
        else
index 1bfc3cbef7b9154229e6836c016b601e0c8c9a4c..8e1de8a43097b2e09d5b98dc14720e082cbbef3c 100644 (file)
@@ -520,12 +520,11 @@ gpiodbus_daemon_on_edge_event(GpiodglibLineRequest *request G_GNUC_UNUSED,
                              GpiodglibEdgeEvent *event, gpointer user_data)
 {
        GpiodbusDaemonRequestData *req_data = user_data;
+       guint64 line_seqno, global_seqno, timestamp;
        GpiodbusDaemonLineData *line_data;
-       gulong line_seqno, global_seqno;
        GpiodglibEdgeEventType edge;
-       guint64 timestamp;
        guint offset;
-       gint val;
+       gint32 val;
 
        edge = gpiodglib_edge_event_get_event_type(event);
        offset = gpiodglib_edge_event_get_line_offset(event);