There will be some problem in the future to build OpenCPN with GCC16

Open
#5,468 4 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
c, cpp
Domain
backend

Research direction

Start by reading gui/src/tcds_binary_harmonic.cpp, especially TCDS_Binary_Harmonic::LoadData around line 371, and inspect how num_csts is calculated before the allocation. Reproduce the GCC 16 build failure using the reported warning-as-error settings; check whether other files trigger the same warning. Done means OpenCPN builds without suppressing -Walloc-size-larger-than.

Written by the indexing model from the issue text.

Description

Hi
You may know that I am still building rpms of OpenCPN and its plugins for Mageia (Mageia10 now)

We are now preparing Mageia11 in Mageia Cauldron and I found something that may have an interest for you :

Building OpenCPN for Mageia10 is OK
But for Mageia Cauldron I get a failure with this explanation :

/builddir/build/BUILD/opencpn-5.14.2-build/OpenCPN-Release_5.14.2/gui/src/tcds_binary_harmonic.cpp: In member function 'virtual TC_Error_Code TCDS_Binary_Harmonic::LoadData(const wxString&)':

/builddir/build/BUILD/opencpn-5.14.2-build/OpenCPN-Release_5.14.2/gui/src/tcds_binary_harmonic.cpp:371:34: error: argument 1 range [18446744056529682432, 18446744073709551608] exceeds maximum object size 9223372036854775807 [-Werror=alloc-size-larger-than=]

371 | m_cst_nodes = (double **)malloc(num_csts * sizeof(double ));
| ~~~~~~~~~~~~~~ ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/16/cstdlib:83,
from /usr/include/c++/16/ext/string_conversions.h:45,
from /usr/include/c++/16/bits/basic_string.h:4499,
from /usr/include/c++/16/string:58,
from /builddir/build/BUILD/opencpn-5.14.2-build/OpenCPN-Release_5.14.2/gui/src/ tcds_binary_harmonic.cpp:26:
/usr/include/stdlib.h:676:14: note: in a call to allocation function 'void
malloc(size_t)' declared here
676 | extern void *malloc (size_t __size) __THROW attribute__malloc
| ~~~~~~~~~~~~~~^~~~~~
At global scope:

What might have caused this failure ?
mga10 has gcc-15 but Cauldron has gcc-16 which is more strict with Warnings considered as Errors

I have had to add :
export CFLAGS="%{optflags} -Wno-alloc-size-larger-than"
export CXXFLAGS="%{optflags} -Wno-alloc-size-larger-than"
before launching cmake and then OpenCPN could build

There may be something to change inside /gui/src/tcds_binary_harmonic.cpp
and perhaps in other cpp files (since I have suppressed those Werrors with my workaround I can't know if there are other causes of failure)

I attach the spec file I used (I needed to add a .txt extension to upload it here
opencpn.spec.txt

Dominant language
C
Stars
1.5k
Forks
627
Avg merge
1d 9m
Merged PRs (30d)
9

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from OpenCPN/OpenCPN

All issues in OpenCPN/OpenCPN

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.