Skip to content

avahi-common: fix -Wunused-value warnings in i18n.h no-op macros#902

Open
heitbaum wants to merge 1 commit into
avahi:masterfrom
heitbaum:gcc3
Open

avahi-common: fix -Wunused-value warnings in i18n.h no-op macros#902
heitbaum wants to merge 1 commit into
avahi:masterfrom
heitbaum:gcc3

Conversation

@heitbaum

@heitbaum heitbaum commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

bindtextdomain and bind_textdomain_codeset were defined to return their first argument, causing -Wunused-value warnings when called as statements without NLS. Cast to void to suppress the warnings.

(Split out of #900)

In file included from i18n.c:24:
i18n.c: In function 'avahi_init_i18n':
i18n.h:46:42: warning: statement with no effect [-Wunused-value]
   46 | #define bindtextdomain(Domain,Directory) (Domain)
      |                                          ^
i18n.c:34:9: note: in expansion of macro 'bindtextdomain'
   34 |         bindtextdomain(GETTEXT_PACKAGE, AVAHI_LOCALEDIR);
      |         ^~~~~~~~~~~~~~
i18n.h:47:49: warning: statement with no effect [-Wunused-value]
   47 | #define bind_textdomain_codeset(Domain,Codeset) (Codeset)
      |                                                 ^
i18n.c:35:9: note: in expansion of macro 'bind_textdomain_codeset'
   35 |         bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
      |         ^~~~~~~~~~~~~~~~~~~~~~~

bindtextdomain and bind_textdomain_codeset were defined to return their
first argument, causing -Wunused-value warnings when called as statements
without NLS. Cast to void to suppress the warnings.

fixes:
    In file included from i18n.c:24:
    i18n.c: In function 'avahi_init_i18n':
    i18n.h:46:42: warning: statement with no effect [-Wunused-value]
       46 | #define bindtextdomain(Domain,Directory) (Domain)
          |                                          ^
    i18n.c:34:9: note: in expansion of macro 'bindtextdomain'
       34 |         bindtextdomain(GETTEXT_PACKAGE, AVAHI_LOCALEDIR);
          |         ^~~~~~~~~~~~~~
    i18n.h:47:49: warning: statement with no effect [-Wunused-value]
       47 | #define bind_textdomain_codeset(Domain,Codeset) (Codeset)
          |                                                 ^
    i18n.c:35:9: note: in expansion of macro 'bind_textdomain_codeset'
       35 |         bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
          |         ^~~~~~~~~~~~~~~~~~~~~~~
@evverx

evverx commented Apr 29, 2026

Copy link
Copy Markdown
Collaborator

The newly introduced NDEBUG job failed with

==25580==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffc190c1e7f at pc 0x564e3c405cd6 bp 0x7ffc190b1780 sp 0x7ffc190b1778
READ of size 1 at 0x7ffc190c1e7f thread T0
    #0 0x564e3c405cd5 in avahi_hexdump /home/runner/work/avahi/avahi/avahi-core/util.c:44:33
    #1 0x564e3c40441e in main /home/runner/work/avahi/avahi/avahi-core/dns-test.c:87:5
    #2 0x7f8fb5e2a1c9 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
    #3 0x7f8fb5e2a28a in __libc_start_main csu/../csu/libc-start.c:360:3
    #4 0x564e3c31e4d4 in _start (/home/runner/work/avahi/avahi/avahi-core/.libs/dns-test+0x3e4d4) (BuildId: ff3e8c8c7db95c37e273df31a82e91d400c93c5b)

Address 0x7ffc190c1e7f is located in stack of thread T0 at offset 66719 in frame
    #0 0x564e3c403c8f in main /home/runner/work/avahi/avahi/avahi-core/dns-test.c:39

  This frame has 2 object(s):
    [32, 1046) 't' (line 40)
    [1184, 66719) 'rdata' (line 44) <== Memory access at offset 66719 overflows this variable
HINT: this may be a false positive if your program uses some custom stack unwind mechanism, swapcontext or vfork
      (longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-overflow /home/runner/work/avahi/avahi/avahi-core/util.c:44:33 in avahi_hexdump
Shadow bytes around the buggy address:
  0x7ffc190c1b80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x7ffc190c1c00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x7ffc190c1c80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x7ffc190c1d00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x7ffc190c1d80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x7ffc190c1e00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00[07]
  0x7ffc190c1e80: f3 f3 f3 f3 f3 f3 f3 f3 f3 f3 f3 f3 f3 f3 f3 f3
  0x7ffc190c1f00: f3 f3 f3 f3 f3 f3 f3 f3 f3 f3 f3 f3 f3 f3 f3 f3
  0x7ffc190c1f80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x7ffc190c2000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x7ffc190c2080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
make[2]: *** [Makefile:1988: check-TESTS] Error 2
make[1]: *** [Makefile:2074: check-am] Error 2
make: *** [Makefile:833: check-recursive] Error 1
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==25580==ABORTING
FAIL dns-test (exit status: 1)

@evverx

evverx commented Apr 29, 2026

Copy link
Copy Markdown
Collaborator

It also failed in #903 so it's probably unrelated to this PR. I'm guessing there are assertions with side effects somewhere.

@evverx

evverx commented Apr 29, 2026

Copy link
Copy Markdown
Collaborator

I'd probably track down the stack overflow first.

Either way before I start looking at this can you expand on how avahi is compiled to trigger the warnings this PR should address? Is it configured with --disable-nls?

@heitbaum

Copy link
Copy Markdown
Contributor Author

I'd probably track down the stack overflow first.

Either way before I start looking at this can you expand on how avahi is compiled to trigger the warnings this PR should address? Is it configured with --disable-nls?

Yes. —-disable-nls. The full package.mk that we use is at https://github.com/LibreELEC/LibreELEC.tv/blob/master/packages/network/avahi/package.mk

@heitbaum

Copy link
Copy Markdown
Contributor Author

I'd probably track down the stack overflow first.
Either way before I start looking at this can you expand on how avahi is compiled to trigger the warnings this PR should address? Is it configured with --disable-nls?

Yes. —-disable-nls. The full package.mk that we use is at https://github.com/LibreELEC/LibreELEC.tv/blob/master/packages/network/avahi/package.mk

(I have been building with the latest / 0.9-rc4 when doing these) we have 0.8 in our stable release, but will be dropping in 0.9 when it’s ready.

@evverx

evverx commented Apr 29, 2026

Copy link
Copy Markdown
Collaborator

Thank you for the link.

we have 0.8 in our stable release, but will be dropping in 0.9 when it’s ready.

It's kind of ready but the only contentious point is that it should be mentioned in the release notes what should be deprecated and then removed and it hasn't been decided yet. Looking at https://github.com/LibreELEC/LibreELEC.tv/blob/master/packages/network/avahi/package.mk I can see that the components that I think should be deprecated and removed are turned off so it shouldn't affect those builds. General-purpose/desktop-oriented distros claiming long-term support shipping those components don't seem to agree yet.

@evverx

evverx commented Apr 29, 2026

Copy link
Copy Markdown
Collaborator

Now that #906 is merged the stack overflow should no longer pop up.

@evverx evverx removed the ci-fails label Apr 29, 2026
@evverx

evverx commented May 1, 2026

Copy link
Copy Markdown
Collaborator

I took a quick look and I don't think it should be suppressed in --disable-nls builds only. After all the return values of bindtextdomain and bind_textdomain_codeset are ignored in --enable-nls builds as well. The straightforward fix would probably be

     if (!done) {
-        bindtextdomain(GETTEXT_PACKAGE, AVAHI_LOCALEDIR);
-        bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
+        (void) bindtextdomain(GETTEXT_PACKAGE, AVAHI_LOCALEDIR);
+        (void) bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
         done = 1;
     }

(which should also help various static analyzers complaining about that) but I'm not sure whether it's OK to ignore the return values there in the first place. I'd keep that warning until it's figured out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants