From: Florian Forster Date: Wed, 19 May 2010 12:56:32 +0000 (+0200) Subject: src/sn_stage.c: Check arguments in some of the methods. X-Git-Tag: v1.0.0~32^2 X-Git-Url: https://git.octo.it/?p=sort-networks.git;a=commitdiff_plain;h=903e1f5e0248cb7e0f98d1b1e824e3b1b6c644e3;hp=93e893f5828b7c7c9639ba730f689cd6ff550f5e src/sn_stage.c: Check arguments in some of the methods. --- diff --git a/src/sn_stage.c b/src/sn_stage.c index e6425bf..7319094 100644 --- a/src/sn_stage.c +++ b/src/sn_stage.c @@ -287,6 +287,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 +300,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 +317,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);