From a9cf7232ef442f89a3b53a1d4bccd605113c256c Mon Sep 17 00:00:00 2001
From: Florent Lamiraux <florent@laas.fr>
Date: Tue, 7 Jun 2011 10:44:00 +0200
Subject: [PATCH] Fix bug in getCommandDocstring.

    When help was invoked with a wrong command name, the interpreter failed with
    segmentation fault.
---
 src/entity-py.cc | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/src/entity-py.cc b/src/entity-py.cc
index dd24338..c6d8ab0 100644
--- a/src/entity-py.cc
+++ b/src/entity-py.cc
@@ -294,15 +294,20 @@ namespace dynamicgraph {
 	}
 	void* pointer = PyCObject_AsVoidPtr(object);
 	Entity* entity = (Entity*)pointer;
-	typedef	std::map<const std::string, command::Command*>  CommandMap;
-	CommandMap map = entity->getNewStyleCommandMap();
+	typedef	std::map<const std::string, command::Command*> commandMap_t;
+	typedef	std::map<const std::string, command::Command*>::iterator
+	  iterator_t;
+	commandMap_t map = entity->getNewStyleCommandMap();
 	command::Command* command = NULL;
-	try {
-	  command = map[commandName];
-	} catch (const std::exception& exc) {
-	  PyErr_SetString(dgpyError, exc.what());
+	iterator_t it = map.find(commandName);
+	if (it == map.end()) {
+	  std::ostringstream oss;
+	  oss << "'" << entity->getName() << "' entity has no command '"
+	      << commandName << "'.";
+	  PyErr_SetString(PyExc_AttributeError, oss.str().c_str());
 	  return NULL;
 	}
+	command = it->second;
 	std::string docstring = command->getDocstring();
 	return Py_BuildValue("s", docstring.c_str());
       }
-- 
GitLab