i18n: Make recode_substring_pool() always return a pool_malloc()'d string.
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 20 Oct 2013 16:44:09 +0000 (09:44 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Wed, 23 Oct 2013 05:56:56 +0000 (22:56 -0700)
recode_substring_pool() generally returned a string allocated by
pool_malloc(), but when there was an error finding the converter it
returned a string that was allocated by pool_alloc().  This was a problem
for parse_value_labels() in the system file reader, because that function
frees all the strings it recodes.  This commit fixes the problem by
always using pool_malloc() in recode_substring_pool().

src/libpspp/i18n.c

index dca85db4f0ee48670a2519bd37bc68f27f58f536..cdcf57003bfbd608008314f0c468826e899b19a0 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 2006, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
+   Copyright (C) 2006, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -502,7 +502,8 @@ filename_to_utf8 (const char *filename)
    dynamically allocated string in TO-encoding.  Any characters which cannot be
    converted will be represented by '?'.
 
-   The returned string will be null-terminated and allocated on POOL.
+   The returned string will be null-terminated and allocated on POOL with
+   pool_malloc().
 
    This function's behaviour differs from that of g_convert_with_fallback
    provided by GLib.  The GLib function will fail (returns NULL) if any part of
@@ -526,7 +527,11 @@ recode_substring_pool (const char *to, const char *from,
   if ( (iconv_t) -1 == conv )
     {
       struct substring out;
-      ss_alloc_substring_pool (&out, text, pool);
+
+      out.string = pool_malloc (pool, text.length + 1);
+      out.length = text.length;
+      memcpy (out.string, text.string, text.length);
+      out.string[out.length] = '\0';
       return out;
     }