Skip to content

Commit 5595f5d

Browse files
committed
fix segfaults with NA crs
1 parent 89e4e98 commit 5595f5d

File tree

5 files changed

+8
-14
lines changed

5 files changed

+8
-14
lines changed

src/gdal_read_stream.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,14 @@ Rcpp::List CPL_read_gdal_stream(
9898
R_ExternalPtrAddr(stream_xptr));
9999

100100
OGRSpatialReference* crs = poLayer->GetSpatialRef();
101-
char* wkt_out;
102-
crs->exportToWkt(&wkt_out);
103-
std::string wkt_str(wkt_out);
104-
CPLFree(wkt_out);
101+
102+
Rcpp::String wkt_str = NA_STRING;
103+
if (crs != nullptr) {
104+
char* wkt_out;
105+
crs->exportToWkt(&wkt_out);
106+
wkt_str = wkt_out;
107+
CPLFree(wkt_out);
108+
}
105109

106110
struct ArrowArrayStream stream_temp;
107111
if (!poLayer->GetArrowStream(&stream_temp, array_stream_options)) {

tests/testthat/test_read.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,6 @@ test_that("we get a warning when not specifying one of multiple layers", {
174174

175175
test_that("reading non-spatial table works", {
176176
skip_if_not(sf_extSoftVersion()[["GDAL"]] >= "2.2.0") # error on OSX for 2.1.3
177-
# currently segfaults using the stream interface
178-
skip_if(default_st_read_use_stream())
179177

180178
expect_warning(st_read(system.file("gpkg/nospatial.gpkg", package = "sf")),
181179
"no simple feature geometries present")

tests/testthat/test_sp.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@ test_that("Can convert `XY` objects to sp", {
104104
})
105105

106106
test_that("Can't convert `M` dimension to sp", {
107-
# Segfaults using the stream interface
108-
skip_if(default_st_read_use_stream())
109107
skip_if_not_installed("sp")
110108
skip_if_not(sf_extSoftVersion()[["GDAL"]] >= "2.1.0")
111109
x <- read_sf(system.file("shape/storms_xyzm_feature.shp", package = "sf"), quiet = TRUE)

tests/testthat/test_write.R

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,6 @@ test_that("append errors work", {
148148
})
149149

150150
test_that("non-spatial tables can be written to GPKG; #1345", {
151-
# currently segfaults using the stream interface
152-
skip_if(default_st_read_use_stream())
153-
154151
nc = system.file("gpkg/nc.gpkg", package = "sf")
155152
tf = tempfile(fileext = ".gpkg")
156153
file.copy(nc, tf)

tests/testthat/test_zm_range.R

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,6 @@ test_that("transform includes zm in output", {
144144

145145

146146
test_that("XYM-only objects correctly calculate M (and not Z)", {
147-
# currently segfaults using the stream interface
148-
skip_if(default_st_read_use_stream())
149-
150147
skip_if_not(sf_extSoftVersion()["GDAL"] > "2.1.0")
151148

152149
sf_m <- sf::st_read(system.file("/shape/storms_xyzm.shp", package = "sf"), quiet = TRUE)

0 commit comments

Comments
 (0)