Skip to content

Fix format string for 32 bit architectures

Krassy Boykinov requested to merge chereskata/livi:formatstring into main

The compilation on armhf, armv7 and x86 fails, because format strings explicitly specify 64 bit specific datatypes. Replaced with macro to compile on all architectures regardless of 32 or 64 bit.

Fixed error log (armhf as example):

../src/livi-window.c:170:32: error: format '%ld' expects argument of type 'long int', but argument 2 has type 'guint64' {aka 'long long unsigned int'} [-Werror=format=]
  170 |   text = g_strdup_printf ("%.2ld:%.2ld / %.2ld:%.2ld",
      |                            ~~~~^
      |                                |
      |                                long int
      |                            %.2lld
  171 |                           pos / 60, pos % 60,
      |                           ~~~~~~~~
      |                               |
      |                               guint64 {aka long long unsigned int}
../src/livi-window.c:170:38: error: format '%ld' expects argument of type 'long int', but argument 3 has type 'guint64' {aka 'long long unsigned int'} [-Werror=format=]
  170 |   text = g_strdup_printf ("%.2ld:%.2ld / %.2ld:%.2ld",
      |                                  ~~~~^
      |                                      |
      |                                      long int
      |                                  %.2lld
  171 |                           pos / 60, pos % 60,
      |                                     ~~~~~~~~
      |                                         |
      |                                         guint64 {aka long long unsigned int}
../src/livi-window.c:170:46: error: format '%ld' expects argument of type 'long int', but argument 4 has type 'guint64' {aka 'long long unsigned int'} [-Werror=format=]
  170 |   text = g_strdup_printf ("%.2ld:%.2ld / %.2ld:%.2ld",
      |                                          ~~~~^
      |                                              |
      |                                              long int
      |                                          %.2lld
  171 |                           pos / 60, pos % 60,
  172 |                           dur / 60, dur % 60);
      |                           ~~~~~~~~            
      |                               |
      |                               guint64 {aka long long unsigned int}
../src/livi-window.c:170:52: error: format '%ld' expects argument of type 'long int', but argument 5 has type 'guint64' {aka 'long long unsigned int'} [-Werror=format=]
  170 |   text = g_strdup_printf ("%.2ld:%.2ld / %.2ld:%.2ld",
      |                                                ~~~~^
      |                                                    |
      |                                                    long int
      |                                                %.2lld
  171 |                           pos / 60, pos % 60,
  172 |                           dur / 60, dur % 60);
      |                                     ~~~~~~~~        
      |                                         |
      |                                         guint64 {aka long long unsigned int}
In file included from /usr/include/glib-2.0/glib.h:64,
                 from /usr/include/gtk-4.0/gtk/css/gtkcss.h:29,
                 from /usr/include/gtk-4.0/gtk/gtk.h:29,
                 from ../src/livi-window.h:12,
                 from ../src/livi-window.c:13:
../src/livi-window.c: In function 'on_player_duration_changed':
../src/livi-window.c:371:12: error: format '%ld' expects argument of type 'long int', but argument 4 has type 'long long unsigned int' [-Werror=format=]
  371 |   g_debug ("Duration %lds", duration / GST_SECOND);
Edited by Krassy Boykinov

Merge request reports