Trap some bad usage
[pspp-builds.git] / lib / gtksheet / psppire-axis-impl.c
index dd515a572d9228b4fabf8aa65678f48b420dc38a..b722a87b16c4379a69b9ae4c5198c9b417328725 100644 (file)
@@ -132,6 +132,8 @@ total_size (const PsppireAxis *axis)
 }
 
 
+static void resize (PsppireAxis *axis, gint posn, glong size);
+
 
 
 static void
@@ -142,6 +144,7 @@ psppire_impl_iface_init (PsppireAxisIface *iface)
   iface->start_pixel = start_pixel;
   iface->unit_at_pixel = unit_at_pixel;
   iface->total_size = total_size;
+  iface->resize = resize;
 }
 
 /* --- functions --- */
@@ -266,9 +269,10 @@ split (PsppireAxisImpl *a, gint posn)
   struct tower_node *n;
   struct axis_node *existing_node;
 
+  g_return_if_fail (posn <= tower_height (&a->unit_tower));
 
   /* Nothing needs to be done */
-  if ( posn == 0)
+  if ( posn == 0 || posn  == tower_height (&a->unit_tower))
     return;
 
   n = tower_lookup (&a->unit_tower, posn, &start);
@@ -309,7 +313,12 @@ void
 psppire_axis_impl_insert (PsppireAxisImpl *a, gint posn, gint size)
 {
   struct axis_node *before = NULL;
-  struct axis_node *new_node = pool_alloc (a->pool, sizeof (*new_node));
+  struct axis_node *new_node;
+
+  g_return_if_fail ( posn < tower_height (&a->unit_tower));
+  g_return_if_fail ( posn >= 0);
+
+  new_node = pool_alloc (a->pool, sizeof (*new_node));
 
   if ( posn > 0)
     {
@@ -344,6 +353,9 @@ make_single (PsppireAxisImpl *a, gint posn)
 {
   unsigned long int start;
   struct tower_node *n;
+
+  g_return_val_if_fail (posn < tower_height (&a->unit_tower), NULL);
+
   n = tower_lookup (&a->unit_tower, posn, &start);
 
   if ( 1 != tower_node_get_size (n))
@@ -364,15 +376,33 @@ make_single (PsppireAxisImpl *a, gint posn)
   return tower_data (n, struct axis_node, unit_node);
 }
 
-void
-psppire_axis_impl_resize (PsppireAxisImpl *a, gint posn, gint size)
+static void
+resize (PsppireAxis *axis, gint posn, glong size)
 {
-  struct axis_node *an =  make_single (a, posn);
+  PsppireAxisImpl *a = PSPPIRE_AXIS_IMPL (axis);
+
+  struct axis_node *an;
+  g_return_if_fail (posn >= 0);
+
+  /* Silently ignore this request if the position is greater than the number of
+     units in the axis */
+  if (posn >= tower_height (&a->unit_tower))
+    return ;
+
+  an = make_single (a, posn);
 
   tower_resize (&a->pixel_tower, &an->pixel_node, size);
 }
 
 
+void
+psppire_axis_impl_resize (PsppireAxisImpl *a, gint posn, gint size)
+{
+  resize (PSPPIRE_AXIS (a), posn, size);
+}
+
+
+
 
 void
 psppire_axis_impl_clear (PsppireAxisImpl *a)