Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GCC 14 build failure and simplify XML error handler #137

Merged
merged 2 commits into from
Jun 3, 2024

Conversation

antecrescent
Copy link
Contributor

This was reported downstream at https://bugs.gentoo.org/928331.

The compilation fails with GCC 14 due to incompatible-pointer-types being an error by default.

$ ./autogen.sh
$ ./configure
$ make
Making all in src
make[1]: Entering directory '/root/FORT-validator/src'
make  all-am
make[2]: Entering directory '/root/FORT-validator/src'
gcc -DHAVE_CONFIG_H -I.    -Wall -Wpedantic -std=c99 -D_DEFAULT_SOURCE=1 -D_XOPEN_SOURCE=700 -D_BSD_SOURCE=1 -O2 -g  -I/usr/include/libxml2 -DBACKTRACE_ENABLED -g -O2 -MT xml/fort-relax_ng.o -MD -MP -MF xml/.deps/fort-relax_ng.Tpo -c -o xml/fort-relax_ng.o `test -f 'xml/relax_ng.c' || echo './'`xml/relax_ng.c
xml/relax_ng.c: In function 'relax_ng_parse':
xml/relax_ng.c:117:56: error: passing argument 2 of 'xmlTextReaderSetStructuredErrorHandler' from incompatible pointer type [-Wincompatible-pointer-types]
  117 |         xmlTextReaderSetStructuredErrorHandler(reader, relax_ng_log_str_err,
      |                                                        ^~~~~~~~~~~~~~~~~~~~
      |                                                        |
      |                                                        void (*)(void *, xmlError *) {aka void (*)(void *, struct _xmlError *)}
In file included from ./xml/relax_ng.h:4,
                 from xml/relax_ng.c:1:
/usr/include/libxml2/libxml/xmlreader.h:420:75: note: expected 'xmlStructuredErrorFunc' {aka 'void (*)(void *, const struct _xmlError *)'} but argument is of type 'void (*)(void *, xmlError *)' {aka 'void (*)(void *, struct _xmlError *)'}
  420 |                                                    xmlStructuredErrorFunc f,
      |                                                    ~~~~~~~~~~~~~~~~~~~~~~~^
make[2]: *** [Makefile:2712: xml/fort-relax_ng.o] Error 1
make[2]: Leaving directory '/root/FORT-validator/src'
make[1]: *** [Makefile:791: all] Error 2
make[1]: Leaving directory '/root/FORT-validator/src'
make: *** [Makefile:372: all-recursive] Error 1

Since we don't manipulate any struct members, I believe we can safely take a const xmlError * argument instead, as per libxml2's documentation .

I also believe we can drop the string-termination handling, because C strings end with \0 and therefore ptr[strlen(ptr)-1] is always \0.

No need to check if ptr[strlen(ptr) - 1] is '\n' because because C
strings always end with a null-byte.
ydahhrk added a commit that referenced this pull request Jun 3, 2024
Pull request #137 fixes relax_ng_log_str_err()'s argument list for
libxml2 2.12 and above, but breaks it for libxml2 2.11 and below.
@ydahhrk ydahhrk merged commit 2027900 into NICMx:main Jun 3, 2024
@ydahhrk
Copy link
Member

ydahhrk commented Jun 3, 2024

Thanks!

@antecrescent
Copy link
Contributor Author

Thank you for merging my changes! Sorry for breaking support with older libxml2 versions. I did not stop to check for API changes before opening the PR... Thank you for fixing that.

@ydahhrk ydahhrk added this to the 1.6.3 milestone Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants