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 some compiler warnings #301

Merged

Conversation

ppisar
Copy link
Contributor

@ppisar ppisar commented Mar 6, 2024

This patch set resolves these compiler warnings:

  • enumerator value for ‘LR_AUTH_ONLY’ is not an integer constant expression
  • format ‘%p’ expects argument of type ‘void *’
  • initialization discards ‘const’ qualifier from pointer target type
  • _BSD_SOURCE and _SVID_SOURCE are deprecated

Warnings regarding new python and new curl will be addressed in separate pull requests as they will probably need to implement fallback code for older libraries.

GCC with -wpedantic warns:

/home/test/librepo/librepo/types.h:77:27: warning: enumerator value for ‘LR_AUTH_ONLY’ is not an intege
r constant expression [-Wpedantic]
   77 |     LR_AUTH_ONLY        = (1<<31), /*!< This is a meta symbol. OR this value
      |                           ^

That's because enum type is equaled to signed int (in C99 this code
uses for compilation) and 1<<31 does not fit into 32-bit signed
integer (which is a size of int on Linux GCC).

Semantically correct fix would be changing it into 1<<30 or MAX_INT,
but that would break ABI.

Therefore this patch retains the value and fixes the warning by
casting the desired bit-value to an unsigned int explicitly.
GCC 14 with -Wpedantic warns like this:

/home/test/librepo/librepo/downloader.c: In function ‘lr_prepare_lrmirrors’:
/home/test/librepo/librepo/downloader.c:382:17: warning: format ‘%p’ expects argument of type ‘void *’,
 but argument 5 has type ‘LrHandle *’ {aka ‘struct _LrHandle *’} [-Wformat=]
  382 |         g_debug("%s: Preparing internal mirror list for handle id: %p", __func__, handle);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~            ~~~~~~
      |                                                                                   |
      |                                                                                   LrHandle * {a
ka struct _LrHandle *}

This patch fixes the type mismatch over the code.
GCC 14 with libxml2-2.12.5 warns:

/home/test/librepo/librepo/xmlparser.c: In function ‘lr_xml_parser_generic’:
/home/test/librepo/librepo/xmlparser.c:177:33: warning: initialization discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
  177 |             xmlErrorPtr error = xmlCtxtGetLastError(ctxt);
      |                                 ^~~~~~~~~~~~~~~~~~~

The warnings is triggered by a new libxml2 which made it const.
However, the returned data structure is never modified, so making it
const is correct even for older libxml2 versions.
Glibc feature macro _BSD_SOURCE is deprecated in favour of
_DEFAULT_SOURCE since glibc-2.20:

In file included from /usr/include/bits/libc-header-start.h:33,
                 from /usr/include/limits.h:26,
                 from /usr/lib/gcc/x86_64-redhat-linux/14/include/limits.h:210,
                 from /usr/lib/gcc/x86_64-redhat-linux/14/include/syslimits.h:7,
                 from /usr/lib/gcc/x86_64-redhat-linux/14/include/limits.h:34,
                 from /usr/lib64/glib-2.0/include/glibconfig.h:11,
                 from /usr/include/glib-2.0/glib/gtypes.h:34,
                 from /usr/include/glib-2.0/glib/galloca.h:34,
                 from /usr/include/glib-2.0/glib.h:32,
                 from /home/test/librepo/librepo/handle.c:24:
/usr/include/features.h:197:3: warning: #warning "_BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE" [-Wcpp]
  197 | # warning "_BSD_SOURCE and _SVID_SOURCE are deprecated, use _DEFAULT_SOURCE"
      |   ^~~~~~~

This patch adds _DEFAULT_SOURCE definition to do it like
librepo/downloader.c aleady does. (Though replacing _BSD_SOURCE would
do it even on RHEL 8 where glibc is newer than 2.20.)
@kontura kontura self-assigned this Mar 7, 2024
@kontura
Copy link
Contributor

kontura commented Mar 7, 2024

The failing tests are not related.

@kontura kontura merged commit 4be343c into rpm-software-management:master Mar 7, 2024
4 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants