From 1cfaf691bd763b7164b38fdb3d51baa02dd3198e Mon Sep 17 00:00:00 2001 From: davi Date: Thu, 13 Jan 2005 23:56:54 +0000 Subject: [PATCH] Better error handling in czech.c. --- src/czech.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/czech.c b/src/czech.c index d699e84..fb422c0 100644 --- a/src/czech.c +++ b/src/czech.c @@ -119,6 +119,13 @@ mphf_t *czech_mph_create(mph_t *mph, float c) free(czech->g); czech->g = malloc(czech->n * sizeof(uint32)); assert(czech->g); + if (!czech->g) + { + fprintf(stderr, "out of memory"); + free(visited); + graph_destroy(czech->graph); + return NULL; + } for (i = 0; i < czech->n; ++i) { if (!visited[i]) @@ -289,11 +296,13 @@ void czech_mphf_load(FILE *f, mphf_t *mphf) czech->g = (uint32 *)malloc(sizeof(uint32)*czech->n); fread(czech->g, czech->n*sizeof(uint32), 1, f); for (i = 0; i < czech->n; ++i) czech->g[i] = ntohl(czech->g[i]); + /* #ifdef DEBUG fprintf(stderr, "G: "); for (i = 0; i < czech->n; ++i) fprintf(stderr, "%u ", czech->g[i]); fprintf(stderr, "\n"); #endif + */ return; }