From cc58588724ba7432a3ce7378dbc3b9a3e8965369 Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Mon, 24 Nov 2014 22:50:12 -0800 Subject: [PATCH] More sensible error message when there are no valid geometries --- geojson.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/geojson.c b/geojson.c index c26ca7c..982ecef 100644 --- a/geojson.c +++ b/geojson.c @@ -565,10 +565,22 @@ next_feature: printf("bbox: %x %x %x %x\n", file_bbox[0], file_bbox[1], file_bbox[2], file_bbox[3]); struct stat indexst; - fstat(indexfd, &indexst); - struct stat metast; - fstat(metafd, &metast); + + if (fstat(indexfd, &indexst) != 0) { + perror("stat index\n"); + exit(EXIT_FAILURE); + } + if (fstat(metafd, &metast) != 0) { + perror("stat meta\n"); + exit(EXIT_FAILURE); + } + + if (indexst.st_size == 0 || metast.st_size == 0) { + fprintf(stderr, "%s: did not read any valid geometries\n", fname); + exit(EXIT_FAILURE); + } + char *meta = mmap(NULL, metast.st_size, PROT_READ, MAP_PRIVATE, metafd, 0); if (meta == MAP_FAILED) { perror("mmap meta");