Fix dereference to reallocated pointer in data-parser.c (parse_delimited_no_span...
authorJohn Darrington <john@darrington.wattle.id.au>
Sat, 12 Sep 2015 10:38:50 +0000 (12:38 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Sat, 12 Sep 2015 10:38:50 +0000 (12:38 +0200)
The parse_delimited_span and parse_delimited_no_span functions were
accessing a pointer from within a loop, but the pointer had been
initialised outside the loop.  However the loop itself was deallocating
the memory referenced by that pointer.

This change initialises the pointer within the loop so as to avoid
a potential crash here.

src/language/data-io/data-parser.c

index 55c62e08c0e0612868313e8647a1f42fb46f0785..b85d1b172012e44dcaf540d60902adcf63518973 100644 (file)
@@ -578,7 +578,6 @@ static bool
 parse_delimited_span (const struct data_parser *parser,
                       struct dfm_reader *reader, struct ccase *c)
 {
-  const char *input_encoding = dfm_reader_get_encoding (reader);
   const char *output_encoding = dict_get_encoding (parser->dict);
   struct string tmp = DS_EMPTY_INITIALIZER;
   struct field *f;
@@ -605,6 +604,7 @@ parse_delimited_span (const struct data_parser *parser,
            }
        }
 
+      const char *input_encoding = dfm_reader_get_encoding (reader);
       error = data_in (s, input_encoding, f->format.type,
                        case_data_rw_idx (c, f->case_idx),
                        fmt_var_width (&f->format), output_encoding);
@@ -622,7 +622,6 @@ static bool
 parse_delimited_no_span (const struct data_parser *parser,
                          struct dfm_reader *reader, struct ccase *c)
 {
-  const char *input_encoding = dfm_reader_get_encoding (reader);
   const char *output_encoding = dict_get_encoding (parser->dict);
   struct string tmp = DS_EMPTY_INITIALIZER;
   struct substring s;
@@ -650,6 +649,7 @@ parse_delimited_no_span (const struct data_parser *parser,
           goto exit;
        }
 
+      const char *input_encoding = dfm_reader_get_encoding (reader);
       error = data_in (s, input_encoding, f->format.type,
                        case_data_rw_idx (c, f->case_idx),
                        fmt_var_width (&f->format), output_encoding);