[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Wesnoth-cvs-commits] wesnoth/src font.cpp serialization/string_utils...
From: |
Guillaume Melquiond |
Subject: |
[Wesnoth-cvs-commits] wesnoth/src font.cpp serialization/string_utils... |
Date: |
Sat, 26 Mar 2005 10:32:26 -0500 |
CVSROOT: /cvsroot/wesnoth
Module name: wesnoth
Branch:
Changes by: Guillaume Melquiond <address@hidden> 05/03/26 15:32:26
Modified files:
src : font.cpp
src/serialization: string_utils.cpp string_utils.hpp
Log message:
Remove illegal read for empty strings. Sanitize utf8 iterators (const
members, no empty constructor).
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/font.cpp.diff?tr1=1.126&tr2=1.127&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/serialization/string_utils.cpp.diff?tr1=1.11&tr2=1.12&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/serialization/string_utils.hpp.diff?tr1=1.7&tr2=1.8&r1=text&r2=text
Patches:
Index: wesnoth/src/font.cpp
diff -u wesnoth/src/font.cpp:1.126 wesnoth/src/font.cpp:1.127
--- wesnoth/src/font.cpp:1.126 Fri Mar 25 18:19:20 2005
+++ wesnoth/src/font.cpp Sat Mar 26 15:32:25 2005
@@ -1,4 +1,4 @@
-/* $Id: font.cpp,v 1.126 2005/03/25 18:19:20 silene Exp $ */
+/* $Id: font.cpp,v 1.127 2005/03/26 15:32:25 silene Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -98,13 +98,16 @@
std::vector<text_chunk> split_text(std::string const & utf8_text) {
text_chunk current_chunk(0);
std::vector<text_chunk> chunks;
-
+
+ if (utf8_text.empty())
+ return chunks;
+
try {
utils::utf8_iterator ch(utf8_text);
if(*ch < font_map.size() && font_map[*ch] >= 0) {
current_chunk.subset = font_map[*ch];
}
- for(; ch != utils::utf8_iterator::end(utf8_text); ++ch) {
+ for(utils::utf8_iterator end =
utils::utf8_iterator::end(utf8_text); ch != end; ++ch) {
if(*ch < font_map.size() && font_map[*ch] >= 0 &&
font_map[*ch] != current_chunk.subset) {
//null-terminate ucs2_text so we can pass it to
SDL_ttf later
current_chunk.ucs2_text.push_back(0);
Index: wesnoth/src/serialization/string_utils.cpp
diff -u wesnoth/src/serialization/string_utils.cpp:1.11
wesnoth/src/serialization/string_utils.cpp:1.12
--- wesnoth/src/serialization/string_utils.cpp:1.11 Mon Mar 14 03:52:48 2005
+++ wesnoth/src/serialization/string_utils.cpp Sat Mar 26 15:32:26 2005
@@ -1,4 +1,4 @@
-/* $Id: string_utils.cpp,v 1.11 2005/03/14 03:52:48 Sirp Exp $ */
+/* $Id: string_utils.cpp,v 1.12 2005/03/26 15:32:26 silene Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Copyright (C) 2005 by Guillaume Melquiond <address@hidden>
@@ -327,10 +327,6 @@
return count;
}
-utf8_iterator::utf8_iterator() :
- current_char(0)
-{
-}
utf8_iterator::utf8_iterator(const std::string& str)
{
current_substr.first = str.begin();
@@ -338,25 +334,24 @@
update();
}
-utf8_iterator::utf8_iterator(std::string::const_iterator beg,
std::string::const_iterator end)
+utf8_iterator::utf8_iterator(std::string::const_iterator const &beg,
std::string::const_iterator const &end)
{
current_substr.first = beg;
string_end = end;
update();
}
-utf8_iterator utf8_iterator::end(const std::string& str)
+utf8_iterator utf8_iterator::begin(std::string const &str)
{
- utf8_iterator res;
-
- res.current_char = 0;
- res.current_substr.first = str.end();
- res.string_end = str.end();
+ return utf8_iterator(str.begin(), str.end());
+}
- return res;
+utf8_iterator utf8_iterator::end(const std::string& str)
+{
+ return utf8_iterator(str.end(), str.end());
}
-bool utf8_iterator::operator==(const utf8_iterator& a)
+bool utf8_iterator::operator==(const utf8_iterator& a) const
{
return current_substr.first == a.current_substr.first;
}
@@ -365,16 +360,15 @@
{
current_substr.first = current_substr.second;
update();
-
return *this;
}
-wchar_t utf8_iterator::operator*()
+wchar_t utf8_iterator::operator*() const
{
return current_char;
}
-const std::pair<std::string::const_iterator, std::string::const_iterator>&
utf8_iterator::substr()
+const std::pair<std::string::const_iterator, std::string::const_iterator>&
utf8_iterator::substr() const
{
return current_substr;
}
Index: wesnoth/src/serialization/string_utils.hpp
diff -u wesnoth/src/serialization/string_utils.hpp:1.7
wesnoth/src/serialization/string_utils.hpp:1.8
--- wesnoth/src/serialization/string_utils.hpp:1.7 Sat Mar 12 04:42:59 2005
+++ wesnoth/src/serialization/string_utils.hpp Sat Mar 26 15:32:26 2005
@@ -1,4 +1,4 @@
-/* $Id: string_utils.hpp,v 1.7 2005/03/12 04:42:59 j_daniel Exp $ */
+/* $Id: string_utils.hpp,v 1.8 2005/03/26 15:32:26 silene Exp $ */
/*
Copyright (C) 2003 by David White <address@hidden>
Copyright (C) 2005 by Guillaume Melquiond <address@hidden>
@@ -68,17 +68,17 @@
typedef wchar_t* pointer;
typedef wchar_t& reference;
- utf8_iterator();
utf8_iterator(const std::string& str);
- utf8_iterator(std::string::const_iterator begin,
std::string::const_iterator end);
+ utf8_iterator(std::string::const_iterator const &begin,
std::string::const_iterator const &end);
+ static utf8_iterator begin(const std::string& str);
static utf8_iterator end(const std::string& str);
- bool operator==(const utf8_iterator& a);
- bool operator!=(const utf8_iterator& a) { return ! (*this == a); }
+ bool operator==(const utf8_iterator& a) const;
+ bool operator!=(const utf8_iterator& a) const { return ! (*this == a); }
utf8_iterator& operator++();
- wchar_t operator*();
- const std::pair<std::string::const_iterator,
std::string::const_iterator>& substr();
+ wchar_t operator*() const;
+ const std::pair<std::string::const_iterator,
std::string::const_iterator>& substr() const;
private:
void update();
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Wesnoth-cvs-commits] wesnoth/src font.cpp serialization/string_utils...,
Guillaume Melquiond <=