]> Devoid-pointer.net GitWeb - libHPCS.git/commitdiff
Handle strings of zero length correctly for old ChemStation file format
authorMichal Malý <madcatxster@devoid-pointer.net>
Mon, 4 Apr 2016 13:43:12 +0000 (15:43 +0200)
committerMichal Malý <madcatxster@devoid-pointer.net>
Mon, 4 Apr 2016 13:43:12 +0000 (15:43 +0200)
libhpcs.c

index a3ee768cb29e8921aa0a970626c7605dd56d7b14..ab435b9b961d9320ad521ab52a7ca3e2e1b3b83a 100644 (file)
--- 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)