src/sn-markov.c: Add missing include.
[sort-networks.git] / src / sn_stage.c
index e6425bf..d89fc89 100644 (file)
@@ -152,6 +152,7 @@ int sn_stage_comparator_remove (sn_stage_t *s, int c_num)
 sn_stage_t *sn_stage_clone (const sn_stage_t *s)
 {
   sn_stage_t *s_copy;
+  int i;
 
   s_copy = sn_stage_create (s->depth);
   if (s_copy == NULL)
@@ -287,6 +288,9 @@ int sn_stage_invert (sn_stage_t *s)
 {
   int i;
 
+  if (s == NULL)
+    return (EINVAL);
+
   for (i = 0; i < s->comparators_num; i++)
     sn_comparator_invert (s->comparators + i);
 
@@ -297,6 +301,13 @@ int sn_stage_shift (sn_stage_t *s, int sw, int inputs_num)
 {
   int i;
 
+  if ((s == NULL) || (inputs_num < 2))
+    return (EINVAL);
+
+  sw %= inputs_num;
+  if (sw == 0)
+    return (0);
+
   for (i = 0; i < s->comparators_num; i++)
     sn_comparator_shift (s->comparators + i, sw, inputs_num);
 
@@ -307,6 +318,9 @@ int sn_stage_swap (sn_stage_t *s, int con0, int con1)
 {
   int i;
 
+  if (s == NULL)
+    return (EINVAL);
+
   for (i = 0; i < s->comparators_num; i++)
     sn_comparator_swap (s->comparators + i, con0, con1);