From 8a8552766bfedcd037822b407efd16d92244efb3 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Mon, 1 Jun 2015 16:08:16 +0200 Subject: [PATCH] Shapefiles: Improved debug output --- shp.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/shp.c b/shp.c index 0e0ff54..34f9b32 100644 --- a/shp.c +++ b/shp.c @@ -1,7 +1,7 @@ /* * Hic Est Leo -- Reading ESRI Shape Files * - * (c) 2014 Martin Mares + * (c) 2014--2015 Martin Mares * * FIXME: Currently, this parser handles only the subset * of shape file syntax which is used by gdal_contours. @@ -86,24 +86,28 @@ void shp_parse(const char *name) die("Unsupported shape file type %u", type); u32 last_recno = 0; - while (len = bread(fb, buf, 8)) + for (;;) { + u64 pos = btell(fb); + uns len = bread(fb, buf, 8); + if (!len) + break; if (len != 8) - die("Truncated record header"); + die("Truncated record header at %ju", (uintmax_t) pos); u32 recno = get_u32_be(buf); u32 reclen = get_u32_be(buf+4) * 2; - DBG("@%ju: recno %u len %u", (uintmax_t) btell(fb) - 8, recno, reclen); if (recno != ++last_recno) - die("Unexpected record #%u, should be #%u", recno, last_recno); + die("Unexpected record #%u (should be #%u) at %ju", recno, last_recno, (uintmax_t) pos); if (reclen > GARY_SIZE(buf)) GARY_RESIZE(buf, reclen); len = bread(fb, buf, reclen); if (len != reclen) - die("Truncated record: %u < %u", len, reclen); + die("Truncated record: %u < %u at %ju", len, reclen, (uintmax_t) pos); if (len < 4) - die("Record too short: %u bytes", reclen); + die("Record too short: %u bytes at %ju", reclen, (uintmax_t) pos); u32 rectype = get_u32_le(buf); + DBG("@%ju: recno=%u len=%u type=%u", (uintmax_t) pos, recno, reclen, rectype); if (rectype == 3) shp_record_polyline(buf, len); } -- 2.39.5