From 40d0a04ab7a392b2db057edf856348616bf8a1b1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Michal=20Mal=C3=BD?= Date: Mon, 4 Apr 2016 15:43:12 +0200 Subject: [PATCH] Handle strings of zero length correctly for old ChemStation file format --- libhpcs.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libhpcs.c b/libhpcs.c index a3ee768..ab435b9 100644 --- a/libhpcs.c +++ b/libhpcs.c @@ -1095,6 +1095,16 @@ static enum HPCS_ParseCode __read_string_at_offset_v1(FILE* datafile, const HPCS PR_DEBUGF("String length to read: %lu\n", str_length); + if (str_length == 0) { + *result = malloc(sizeof(char)); + + if (*result == NULL) + return PARSE_E_NO_MEM; + + (*result)[0] = '\0'; + return PARSE_OK; + } + /* Allocate read buffer */ string = calloc(str_length + 1, SMALL_SEGMENT_SIZE); if (string == NULL) -- 2.43.5