Skip to content

Conversation

@neteler
Copy link
Member

@neteler neteler commented Sep 23, 2025

This PR fixes the limitation to 16 bits by replacing short type to integer.

Example (now fixed):

GRASS latlong_wgs84/mymapset:grass >

g.region vector=solar_panels_points -m
projection=3
zone=0
n=56.62055
s=47
w=5.451694
e=14.991018
nsres=30.9064117
ewres=19.07598674
rows=34634
cols=34342
cells=1189400828

One giga-pixels (34k x 34k) is not that much. Yet it overflowed:

r.surf.idw input=solar_panels output=heatmap_idw_rast
Current region rows: 34634, cols: 34342
ERROR: G_calloc: unable to allocate 18446744073709520714 * 40 bytes of
       memory at raster/r.surf.idw/dist.c:43

This PR fixes this limitation.

Co-authored-by: @metzm

This PR fixes the limitation to 16 bits by replacing `short` type to `integer`.

Example (now fixed):

```bash
GRASS latlong_wgs84/mymapset:grass >

g.region vector=solar_panels_points -m
projection=3
zone=0
n=56.62055
s=47
w=5.451694
e=14.991018
nsres=30.9064117
ewres=19.07598674
rows=34634
cols=34342
cells=1189400828
```

One giga-pixels (34k x 34k) is not that much. Yet it overflowed:

```bash
r.surf.idw input=solar_panels output=heatmap_idw_rast
Current region rows: 34634, cols: 34342
ERROR: G_calloc: unable to allocate 18446744073709520714 * 40 bytes of
       memory at raster/r.surf.idw/dist.c:43
```

This PR fixes this limitation.

Co-authored-by: @metzm
@neteler neteler added this to the 8.5.0 milestone Sep 23, 2025
@neteler neteler self-assigned this Sep 23, 2025
@neteler neteler added bug Something isn't working raster Related to raster data processing C Related code is in C backport to 8.4 PR needs to be backported to release branch 8.4 labels Sep 23, 2025
Copy link
Contributor

@nilason nilason left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!
(Wonder why using short in the first place).

@neteler
Copy link
Member Author

neteler commented Sep 23, 2025

(Wonder why using short in the first place).

Guess it stems from very old times: it is already in the code snippet from > 20 years ago:
https://github.com/OSGeo/grass-legacy/blame/6b2017f5f90a1cb073d29e9cf77f1f6af0cfdf74/raster/r.surf.idw/dist.c#L25

@nilason
Copy link
Contributor

nilason commented Sep 23, 2025

(Wonder why using short in the first place).

Guess it stems from very old times: it is already in the code snippet from > 20 years ago: https://github.com/OSGeo/grass-legacy/blame/6b2017f5f90a1cb073d29e9cf77f1f6af0cfdf74/raster/r.surf.idw/dist.c#L25

Seems like yesterday :). I suspected that was the reason.

@neteler neteler merged commit fe8daa2 into OSGeo:main Sep 24, 2025
27 checks passed
@neteler neteler deleted the r_surf_idw_fix_short_overflow branch September 24, 2025 06:49
neteler added a commit that referenced this pull request Sep 24, 2025
@neteler neteler removed the backport to 8.4 PR needs to be backported to release branch 8.4 label Sep 24, 2025
@neteler neteler modified the milestones: 8.5.0, 8.4.2 Sep 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working C Related code is in C module raster Related to raster data processing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants