Selaa lähdekoodia

Handle OGR function calls which may fail (#1276)

Fixes -Wunused-result compiler warnings.

Co-authored-by: Markus Metz <markus.metz.giswork@gmail.com>
nila 4 vuotta sitten
vanhempi
commit
7dfe7e6e0a
3 muutettua tiedostoa jossa 16 lisäystä ja 5 poistoa
  1. 3 1
      db/drivers/ogr/execute.c
  2. 7 2
      lib/vector/Vlib/open_ogr.c
  3. 6 2
      lib/vector/Vlib/write_ogr.c

+ 3 - 1
db/drivers/ogr/execute.c

@@ -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);
     }
     

+ 7 - 2
lib/vector/Vlib/open_ogr.c

@@ -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:

+ 6 - 2
lib/vector/Vlib/write_ogr.c

@@ -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;
 }