]> https://gitweb.dealii.org/ - dealii.git/commitdiff
empty string in split_string_list fix
authorMFraters <menno.fraters@outlook.com>
Tue, 24 Feb 2015 10:32:07 +0000 (11:32 +0100)
committerMFraters <menno.fraters@outlook.com>
Tue, 24 Feb 2015 10:32:07 +0000 (11:32 +0100)
When an empty string or a string with only spaces is given to this function, the split_string_list function will ask in line 222 for name[-1], which will result in unpredictable behaviour. I propose to prevent this by adding a condition that the length of the string may not be 0.

source/base/utilities.cc

index 8af548922dd7e668b7e5f7ec1fee654ac2fe9497..6507542bb7a7ea7c0e8925b9a470449ca951f6d9 100644 (file)
@@ -219,7 +219,7 @@ namespace Utilities
                (name[0] == ' '))
           name.erase (0,1);
 
-        while (name[name.length()-1] == ' ')
+        while (name[name.length()-1] == ' ' && name.length() != 0)
           name.erase (name.length()-1, 1);
 
         split_list.push_back (name);

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.