Skip to content

Commit

Permalink
Handle OGR function calls which may fail (#1276)
Browse files Browse the repository at this point in the history
Fixes -Wunused-result compiler warnings.

Co-authored-by: Markus Metz <markus.metz.giswork@gmail.com>
  • Loading branch information
nilason and metzm committed Feb 8, 2021
1 parent e37da6a commit 7dfe7e6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
4 changes: 3 additions & 1 deletion db/drivers/ogr/execute.c
Expand Up @@ -109,7 +109,9 @@ int db__driver_execute_immediate(dbString * sql)
}
OGR_F_SetFieldString(hFeature, cols[i].index, value);
}
OGR_L_SetFeature(hLayer, hFeature);
if (OGR_L_SetFeature(hLayer, hFeature) != OGRERR_NONE)
G_warning(_("\tOGR failed to write feature fid=%ld to layer <%s>"),
OGR_F_GetFID(hFeature), OGR_L_GetName(hLayer));
OGR_F_Destroy(hFeature);
}

Expand Down
9 changes: 7 additions & 2 deletions lib/vector/Vlib/open_ogr.c
Expand Up @@ -100,8 +100,13 @@ int V1_open_old_ogr(struct Map_info *Map, int update)
G_debug(2, "OGR layer %d opened", layer);

ogr_info->layer = Ogr_layer;
if (update && OGR_L_TestCapability(ogr_info->layer, OLCTransactions))
OGR_L_StartTransaction(ogr_info->layer);
if (update && OGR_L_TestCapability(ogr_info->layer, OLCTransactions) &&
(OGR_L_StartTransaction(ogr_info->layer) != OGRERR_NONE)) {
OGR_DS_Destroy(Ogr_ds);
G_warning(_("OGR transaction with layer <%s> failed to start"),
ogr_info->layer_name);
return -1;
}

switch(Ogr_geom_type) {
case wkbPoint25D: case wkbLineString25D: case wkbPolygon25D:
Expand Down
8 changes: 6 additions & 2 deletions lib/vector/Vlib/write_ogr.c
Expand Up @@ -347,8 +347,12 @@ int create_ogr_layer(struct Map_info *Map, int type)
"Unable to write attributes."));
}

if (OGR_L_TestCapability(ogr_info->layer, OLCTransactions))
OGR_L_StartTransaction(ogr_info->layer);
if (OGR_L_TestCapability(ogr_info->layer, OLCTransactions) &&
(OGR_L_StartTransaction(ogr_info->layer) != OGRERR_NONE)) {
G_warning(_("OGR transaction with layer <%s> failed to start"),
ogr_info->layer_name);
return -1;
}

return 0;
}
Expand Down

0 comments on commit 7dfe7e6

Please sign in to comment.