osm2pgsql-dev / osm2pgsql

OpenStreetMap data to PostgreSQL converter

Home Page:https://osm2pgsql.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Test failure in bdd-flex with 1.9.0

tomhughes opened this issue · comments

I'm seeing a failure in the bdd-flex test building 1.9.0 on anything other than x86_64 with a failure as follows:

  Scenario: Minzoom value in expire output definition has to be in range  # flex/lua-expire-output-definitions.feature:110
    Given the input file 'liechtenstein-2013-08-03.osm.pbf'               # steps/steps_osm_data.py:12
    And the lua style                                                     # steps/steps_execute.py:131
      """
      osm2pgsql.define_expire_output({
          name = 'foo',
          maxzoom = 12,
          minzoom = -3,
          filename = 'somewhere'
      })
      """
    Then running osm2pgsql flex fails                                     # steps/steps_execute.py:163
    And the error output contains                                         # steps/steps_execute.py:193
      """
      Value of 'minzoom' field must be between 1 and 'maxzoom'.
      """
      Assertion Failed: Output 'Value of 'minzoom' field must be between 1 and 'maxzoom'.' not found in error output:
      2023-08-16 09:49:54  osm2pgsql version 1.9.0
      2023-08-16 09:49:54  Database version: 15.3
      2023-08-16 09:49:54  PostGIS version: 3.3
      2023-08-16 09:49:54  Storing properties to table '"public"."osm2pgsql_properties"'.
      2023-08-16 09:49:54  ERROR: No tables defined in Lua config. Nothing to do!

I think the problem is that https://github.com/openstreetmap/osm2pgsql/blob/5b3f1c4d6500187b62af63f5e83a08956cc1e18d/src/flex-lua-expire-output.cpp#L61 is fetching the zoom value as unsigned which obviously causes problems with a signed value.

I don't really understand why x86_64 behaves differently though - as far as I can work out lua_tonumber returns a double and coercing -3.0 to uint32_t gives zero and then https://github.com/openstreetmap/osm2pgsql/blob/5b3f1c4d6500187b62af63f5e83a08956cc1e18d/src/flex-lua-expire-output.cpp#L65 ought to skip reporting an error on all platforms.

In C++ conversions from double to integers are undefined if the value is outside the range that the integer can hold. So yes, it is to be expected that there can be a difference here between different architectures.

Ah I wondered if it was actually undefined but all my tests with different architectures on godbolt were converting to zero but obviously they were a much simplified test case compared to the real thing.