Bug 471339 - Marble container iterator methods crash
Summary: Marble container iterator methods crash
Status: REPORTED
Alias: None
Product: marble
Classification: Applications
Component: general (show other bugs)
Version: 23.04.2
Platform: Arch Linux Linux
: NOR normal
Target Milestone: ---
Assignee: marble-bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-06-22 14:09 UTC by casqadius
Modified: 2023-06-22 14:23 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments
Sample CMakeLists project to reproduce the crash (510 bytes, text/plain)
2023-06-22 14:09 UTC, casqadius
Details

Note You need to log in before you can comment on or make changes to this bug.
Description casqadius 2023-06-22 14:09:50 UTC
Created attachment 159836 [details]
Sample CMakeLists project to reproduce the crash

SUMMARY

Marble container iterators (e.g. GeoDataLineString::constBegin) usage causes segmentation fault. 
By default, marble is compiled with QT_STRICT_ITERATORS definition for non-Windows platforms, which probably results in ODR violation when other projects without this definition link to the library. 

I believe that's the main reason for this bug as well:
https://bugs.kde.org/show_bug.cgi?id=458555

Compiling the project with explicitly enabled definition fixes described behaviour. If that define is cricital enough to cause crashes, I expect it to be mentioned in docs. 


STEPS TO REPRODUCE
1. Create an empty C++ project which links to marble & qt
2. Compile & execute the following code:

#include <marble/GeoDataLineString.h>
#include <marble/GeoDataCoordinates.h>

#include <cassert>
#include <iostream>

int main()
{
  using Marble::GeoDataLineString;
  using Marble::GeoDataCoordinates;

  GeoDataLineString line {};

  for ( size_t i = 0, j = 0; i < 10; ++i, ++j )
    line << GeoDataCoordinates{j + 1.0, j + 2.0, j + 3.0};

  for ( size_t i = 0; i < line.size(); ++i )
  {
    const auto& point = static_cast <const GeoDataLineString&> (line).at(i);

    std::cout << "point " << i
              << ": lon " << point.longitude()
              << " lat " << point.latitude()
              << " alt " << point.altitude();

    std::cout << "\n";
  }

  assert(line.size() > 0);
  assert(line.isEmpty() == false);
  assert(line.constBegin() != line.constEnd());
  assert(line.begin() != line.end());

  return 0;
}


OBSERVED RESULT
Segmentation fault at third assert during the call to line.constBegin():

1 Marble::GeoDataLineString::constBegin() const                         0x7f94865c47bb 
2 main                                                                         main.cpp 31 0x563cf7795b4b 

Adding QT_STRICT_ITERATORS definition eliminates the crash. 


EXPECTED RESULT
Successful execution. 

SOFTWARE/OS VERSIONS
Linux: archlinux 6.3.9-arch1-1
Qt Version: 5.15.10+kde+r129-1

ADDITIONAL INFORMATION
The issue is probably non-existent on Windows, since the library is compiled with strict iterators disabled for this platform by default
Comment 1 casqadius 2023-06-22 14:19:20 UTC
The only solution I can propose is to make QT_STRICT_ITERATORS definition in the library public: 

if (NOT WIN32)
  target_compile_definitions(marblewidget PUBLIC QT_STRICT_ITERATORS)
endif()