From: Michal MalĂ˝ Date: Mon, 4 Apr 2016 13:43:12 +0000 (+0200) Subject: Handle strings of zero length correctly for old ChemStation file format X-Git-Url: https://gitweb.devoid-pointer.net/?a=commitdiff_plain;h=40d0a04ab7a392b2db057edf856348616bf8a1b1;p=libHPCS.git Handle strings of zero length correctly for old ChemStation file format --- 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)