wesnoth-cvs-commits
[Top][All Lists]
Advanced

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

[Wesnoth-cvs-commits] wesnoth/src language.cpp


From: Guillaume Melquiond
Subject: [Wesnoth-cvs-commits] wesnoth/src language.cpp
Date: Tue, 07 Sep 2004 15:57:32 -0400

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     Guillaume Melquiond <address@hidden>    04/09/07 19:52:19

Modified files:
        src            : language.cpp 

Log message:
        Correctly detect past-the-end issue on botched utf8 strings

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/language.cpp.diff?tr1=1.38&tr2=1.39&r1=text&r2=text

Patches:
Index: wesnoth/src/language.cpp
diff -u wesnoth/src/language.cpp:1.38 wesnoth/src/language.cpp:1.39
--- wesnoth/src/language.cpp:1.38       Sun Aug 29 14:54:39 2004
+++ wesnoth/src/language.cpp    Tue Sep  7 19:52:19 2004
@@ -1,4 +1,4 @@
-/* $Id: language.cpp,v 1.38 2004/08/29 14:54:39 ydirson Exp $ */
+/* $Id: language.cpp,v 1.39 2004/09/07 19:52:19 silene Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -277,31 +277,30 @@
 wide_string utf8_to_wstring(const std::string &src)
 {
        wide_string ret;        
-       wchar_t ch;
-       std::string::const_iterator i;
        
        try {
-               for(i = src.begin(); i != src.end(); ++i ) {
-                       ch = (unsigned char)*i;
+               for(size_t i = 0, l = src.size(); i != l;) {
+                       wchar_t ch = (unsigned char)src[i];
                        const int count = byte_size_from_utf8_first(ch);
-                                       
-                       if(i + count - 1 == src.end())
+
+                       if (i + count > l)
                                throw invalid_utf8_exception();
 
                        /* Convert the first character */
                        if (count != 1) {
                                ch &= 0xFF >> (count + 1);
                        }
-                       
+
                        /* Convert the continuation bytes */
-                       for(std::string::const_iterator j = i+1; j != i+count; 
++j) {
-                               if((*j & 0xC0) != 0x80)
+                       for(size_t j = i + 1; j != i + count; ++j) {
+                               unsigned char ch2 = src[j];
+                               if ((ch2 & 0xC0) != 0x80)
                                        throw invalid_utf8_exception();
-                               
-                               ch = (ch << 6) | (*j & 0x3F);
+
+                               ch = (ch << 6) | (ch2 & 0x3F);
                        }
-                       i += (count - 1);
-                       
+                       i += count;
+
                        push_back(ret,ch);
                }
        }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]