[Bf-blender-cvs] [49c190b] alembic_basic_io: Fix crashes and lookup errors due to a weak (and not so thread safe) string tokenizer algorithm.

Kévin Dietrich noreply at git.blender.org
Wed May 25 14:53:47 CEST 2016


Commit: 49c190bc755413b2e11e1d22c37e9c46a930b9f1
Author: Kévin Dietrich
Date:   Wed May 25 14:46:54 2016 +0200
Branches: alembic_basic_io
https://developer.blender.org/rB49c190bc755413b2e11e1d22c37e9c46a930b9f1

Fix crashes and lookup errors due to a weak (and not so thread safe)
string tokenizer algorithm.

===================================================================

M	source/blender/alembic/intern/abc_object.cc
M	source/blender/alembic/intern/abc_util.cc
M	source/blender/alembic/intern/abc_util.h
M	source/blender/alembic/intern/alembic_capi.cc

===================================================================

diff --git a/source/blender/alembic/intern/abc_object.cc b/source/blender/alembic/intern/abc_object.cc
index d7358e9..fca0580 100644
--- a/source/blender/alembic/intern/abc_object.cc
+++ b/source/blender/alembic/intern/abc_object.cc
@@ -313,7 +313,7 @@ AbcObjectReader::AbcObjectReader(const IObject &object, ImportSettings &settings
 {
 	m_name = object.getFullName();
 	std::vector<std::string> parts;
-	split(m_name, "/", parts);
+	split(m_name, '/', parts);
 
 	assert(parts.size() >= 2);
 
diff --git a/source/blender/alembic/intern/abc_util.cc b/source/blender/alembic/intern/abc_util.cc
index 8dd96cd..3620e93 100644
--- a/source/blender/alembic/intern/abc_util.cc
+++ b/source/blender/alembic/intern/abc_util.cc
@@ -106,19 +106,16 @@ Imath::M44d convert_matrix(float mat[4][4])
 	return m;
 }
 
-void split(const std::string &s, const char *delim, std::vector<std::string> &v)
+void split(const std::string &s, const char delim, std::vector<std::string> &tokens)
 {
-	/* to avoid modifying original string first duplicate the original string
-	 * and return a char pointer then free the memory */
-	char *dup = strdup(s.c_str());
-	char *token = strtok(dup, delim);
-
-	while (token != NULL) {
-		v.push_back(std::string(token));
-		/* the call is treated as a subsequent calls to strtok: the function
-		 * continues from where it left in previous invocation */
-		token = strtok(NULL, delim);
-	}
+	tokens.clear();
+
+	std::stringstream ss(s);
+	std::string item;
 
-	free(dup);
+	while (std::getline(ss, item, delim)) {
+		if (!item.empty()) {
+			tokens.push_back(item);
+		}
+	}
 }
diff --git a/source/blender/alembic/intern/abc_util.h b/source/blender/alembic/intern/abc_util.h
index 3d75c6e..4b4b9fa 100644
--- a/source/blender/alembic/intern/abc_util.h
+++ b/source/blender/alembic/intern/abc_util.h
@@ -37,7 +37,7 @@ bool parent_selected(Object *ob);
 
 Imath::M44d convert_matrix(float mat[4][4]);
 
-void split(const std::string &s, const char *delim, std::vector<std::string> &v);
+void split(const std::string &s, const char delim, std::vector<std::string> &tokens);
 
 template<class TContainer>
 bool begins_with(const TContainer &input, const TContainer &match)
diff --git a/source/blender/alembic/intern/alembic_capi.cc b/source/blender/alembic/intern/alembic_capi.cc
index ff02caf..f175cb2 100644
--- a/source/blender/alembic/intern/alembic_capi.cc
+++ b/source/blender/alembic/intern/alembic_capi.cc
@@ -148,7 +148,7 @@ static void find_mesh_object(const IObject &object, IObject &ret,
 	}
 
 	std::vector<std::string> tokens;
-	split(name, "/", tokens);
+	split(name, '/', tokens);
 
 	IObject tmp = object;
 
@@ -429,7 +429,7 @@ static void create_hierarchy(Main *bmain, Scene *scene, AbcObjectReader *root)
 	const std::string &full_name = iobjet.getFullName();
 
 	std::vector<std::string> parts;
-	split(full_name, "/", parts);
+	split(full_name, '/', parts);
 
 	/* object doesn't have any parents, since its path only contain its name,
 	 * and its data name. */




More information about the Bf-blender-cvs mailing list