[nemiver: 3/3] Check for empty before isspace in UString::chomp()



commit 05b7632f00458e867c5071fe28585658920a08ab
Author: Jonathon Jongsma <jonathon jongsma collabora co uk>
Date:   Wed Mar 4 22:33:31 2009 -0600

    Check for empty before isspace in UString::chomp() (Closes: #574214)
    
    	* src/common/nmv-ustring.cc: in cases where a string is all whitespace, an
    	  out-of-range exception was being thrown, because we were checking for
    	  isspace before we were checking that the string was non-empty.  I switched
    	  the order of these comparisons so now we never examine whether the first
    	  character of an empty string is a space.  At the same time I switched from
    	  using size() to using !empty() since theoretically that should be slightly
    	  more efficient.
---
 src/common/nmv-ustring.cc |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/common/nmv-ustring.cc b/src/common/nmv-ustring.cc
index 04f8cbc..7b9822d 100644
--- a/src/common/nmv-ustring.cc
+++ b/src/common/nmv-ustring.cc
@@ -245,7 +245,7 @@ UString::chomp ()
     Glib::ustring::size_type i = 0 ;
 
     //remove the ws from the beginning of the string.
-    while (isspace (at (0)) && size ()) {
+    while (!empty() && isspace (at (0))) {
         erase (0, 1) ;
     }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]