diff options
author | Thomas White <taw@physics.org> | 2020-07-10 15:11:57 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2020-07-29 18:53:45 +0200 |
commit | 465f36e8fa43e371142ee6861c56403f13e7d12d (patch) | |
tree | 84dc6fcddcf82e8ecfe6c0a6f40d9af6229b0c08 /libcrystfel/src | |
parent | 234ebec9ac60c645b4118004a6e95a0ff73b08ec (diff) |
Fix reading of geometry from stream
Diffstat (limited to 'libcrystfel/src')
-rw-r--r-- | libcrystfel/src/stream.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/libcrystfel/src/stream.c b/libcrystfel/src/stream.c index f9a75e9d..dbb213bf 100644 --- a/libcrystfel/src/stream.c +++ b/libcrystfel/src/stream.c @@ -1103,14 +1103,16 @@ static void read_geometry_file(Stream *st) int done = 0; size_t len = 0; int started = 0; + int success = 0; const size_t max_geom_len = 64*1024; + char *geom; - st->geometry_file = malloc(max_geom_len); - if ( st->geometry_file == NULL ) { + geom = malloc(max_geom_len); + if ( geom == NULL ) { ERROR("Failed to allocate memory for audit information\n"); return; } - st->geometry_file[0] = '\0'; + geom[0] = '\0'; do { @@ -1121,8 +1123,7 @@ static void read_geometry_file(Stream *st) if ( rval == NULL ) { ERROR("Failed to read stream geometry file.\n"); stream_close(st); - free(st->geometry_file); - st->geometry_file = NULL; + free(geom); return; } @@ -1133,6 +1134,7 @@ static void read_geometry_file(Stream *st) if ( strcmp(line, STREAM_GEOM_END_MARKER"\n") == 0 ) { done = 1; + success = 1; continue; } @@ -1148,14 +1150,17 @@ static void read_geometry_file(Stream *st) if ( len > max_geom_len-1 ) { ERROR("Stream's geometry file is too long (%li > %i).\n", (long)len, (int)max_geom_len); - free(st->geometry_file); - st->geometry_file = NULL; + free(geom); return; } else { - strcat(st->geometry_file, line); + strcat(geom, line); } } while ( !done ); + + if ( success ) { + st->geometry_file = geom; + } } |