Revert "Fixed a use after free error when manipulating datasets."
[pspp] / src / libpspp / str.c
index 57386cbfc4f89e554a8a4a0e7d5e4303a022ccbf..c227f7f6989da54c915b82884f6b6ee453a63ebf 100644 (file)
@@ -1,5 +1,6 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 1997-9, 2000, 2006, 2009, 2010, 2011, 2012, 2014 Free Software Foundation, Inc.
+   Copyright (C) 1997-9, 2000, 2006, 2009, 2010, 2011, 2012, 2014,
+   2020 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
@@ -1510,6 +1511,9 @@ ds_splice_uninit (struct string *st,
     {
       if (new_len > old_len)
         ds_extend (st, ds_length (st) + (new_len - old_len));
+
+      assert (ds_length (st) >= ofs + old_len);
+
       memmove (ds_data (st) + (ofs + new_len),
                ds_data (st) + (ofs + old_len),
                ds_length (st) - (ofs + old_len));
@@ -1621,7 +1625,7 @@ ds_relocate (struct string *st)
   const char *orig = ds_cstr (st);
   const char *rel = relocate (orig);
 
-  if ( orig != rel)
+  if (orig != rel)
     {
       ds_clear (st);
       ds_put_cstr (st, rel);