aboutsummaryrefslogtreecommitdiff
path: root/src/pj_gc_reader.c
diff options
context:
space:
mode:
authorKristian Evers <kristianevers@gmail.com>2017-11-15 21:00:49 +0100
committerKristian Evers <kristianevers@gmail.com>2017-11-15 21:00:49 +0100
commit94771c16596d75c989657447f65d52e8115d3426 (patch)
tree0f7e4206ca3b724e9ebc24c065a137490bf0adfb /src/pj_gc_reader.c
parent91b641e627a028786e56276d18501dd518d6b112 (diff)
parentf08a7c0cf9dc3ed017a224e196e9d251da8dc97c (diff)
downloadPROJ-94771c16596d75c989657447f65d52e8115d3426.tar.gz
PROJ-94771c16596d75c989657447f65d52e8115d3426.zip
Merge remote-tracking branch 'osgeo/master' into docs-release-4.10.0
Diffstat (limited to 'src/pj_gc_reader.c')
-rw-r--r--src/pj_gc_reader.c31
1 files changed, 28 insertions, 3 deletions
diff --git a/src/pj_gc_reader.c b/src/pj_gc_reader.c
index dc528b52..e49e56a4 100644
--- a/src/pj_gc_reader.c
+++ b/src/pj_gc_reader.c
@@ -27,6 +27,7 @@
#define PJ_LIB__
+#include <errno.h>
#include <projects.h>
#include <string.h>
#include <ctype.h>
@@ -56,15 +57,29 @@ PJ_GridCatalog *pj_gc_readcatalog( projCtx ctx, const char *catalog_name )
catalog = (PJ_GridCatalog *) calloc(1,sizeof(PJ_GridCatalog));
if( !catalog )
{
+ pj_ctx_set_errno(ctx, ENOMEM);
pj_ctx_fclose(ctx, fid);
return NULL;
}
- catalog->catalog_name = strdup(catalog_name);
+ catalog->catalog_name = pj_strdup(catalog_name);
+ if (!catalog->catalog_name) {
+ pj_ctx_set_errno(ctx, ENOMEM);
+ free(catalog);
+ pj_ctx_fclose(ctx, fid);
+ return NULL;
+ }
entry_max = 10;
catalog->entries = (PJ_GridCatalogEntry *)
malloc(entry_max * sizeof(PJ_GridCatalogEntry));
+ if (!catalog->entries) {
+ pj_ctx_set_errno(ctx, ENOMEM);
+ free(catalog->catalog_name);
+ free(catalog);
+ pj_ctx_fclose(ctx, fid);
+ return NULL;
+ }
while( pj_gc_readentry( ctx, fid,
catalog->entries+catalog->entry_count) == 0)
@@ -83,6 +98,7 @@ PJ_GridCatalog *pj_gc_readcatalog( projCtx ctx, const char *catalog_name )
int i;
for( i = 0; i < catalog->entry_count; i++ )
free( catalog->entries[i].definition );
+ free( catalog->entries );
free( catalog->catalog_name );
free( catalog );
pj_ctx_fclose(ctx, fid);
@@ -124,6 +140,7 @@ static int pj_gc_read_csv_line( projCtx ctx, PAFile fid,
while( token_count < max_tokens && *next != '\0' )
{
const char *start = next;
+ char* token;
while( *next != '\0' && *next != ',' )
next++;
@@ -134,7 +151,14 @@ static int pj_gc_read_csv_line( projCtx ctx, PAFile fid,
next++;
}
- tokens[token_count++] = strdup(start);
+ token = pj_strdup(start);
+ if (!token) {
+ while (token_count > 0)
+ free(tokens[--token_count]);
+ pj_ctx_set_errno(ctx, ENOMEM);
+ return 0;
+ }
+ tokens[token_count++] = token;
}
return token_count;
@@ -199,7 +223,8 @@ static int pj_gc_readentry(projCtx ctx, PAFile fid, PJ_GridCatalogEntry *entry)
}
else
{
- entry->definition = strdup( tokens[0] );
+ entry->definition = tokens[0];
+ tokens[0] = NULL; /* We take ownership of tokens[0] */
entry->region.ll_long = dmstor_ctx( ctx, tokens[1], NULL );
entry->region.ll_lat = dmstor_ctx( ctx, tokens[2], NULL );
entry->region.ur_long = dmstor_ctx( ctx, tokens[3], NULL );