# HG changeset patch
# User Nathann Cohen <nathann.cohen@gmail.com>
# Date 1319210935 -7200
# Node ID 19f096fe24a2280948e4d4486341f9e81744f177
# Parent  d740726a92bc0eef8e372e0a59c37b6cdf0a84b0
trac #11942 -- segfault on Graph().connected_component_containing_vertex('')

diff --git a/sage/graphs/base/c_graph.pyx b/sage/graphs/base/c_graph.pyx
--- a/sage/graphs/base/c_graph.pyx
+++ b/sage/graphs/base/c_graph.pyx
@@ -3318,6 +3318,22 @@
             sage: g = graphs.PetersenGraph()
             sage: list(g.breadth_first_search(0))
             [0, 1, 4, 5, 2, 6, 3, 9, 7, 8]
+
+        TEST:
+
+        A vertex which does not belong to the graph::
+
+            sage: list(g.breadth_first_search(-9))
+            Traceback (most recent call last):
+            ...
+            ValueError: The given vertex is not an element of the graph !
+
+        An empty graph::
+            
+            sage: list(Graph().breadth_first_search(''))
+            Traceback (most recent call last):
+            ...
+            ValueError: The given vertex is not an element of the graph !
         """
         self.graph = graph
         self.direction = direction
@@ -3325,10 +3341,15 @@
         bitset_init(self.seen, (<CGraph>self.graph._cg).active_vertices.size)
         bitset_set_first_n(self.seen, 0)
 
-        self.stack = [get_vertex(v,
+        cdef int v_id = get_vertex(v,
                                  self.graph.vertex_ints,
                                  self.graph.vertex_labels,
-                                 self.graph._cg)]
+                                 self.graph._cg)
+
+        if v_id == -1:
+            raise ValueError("The given vertex is not an element of the graph !")
+
+        self.stack = [v_id]
 
         if not self.graph.directed:
             ignore_direction = False
