From: Florian Forster Date: Mon, 17 May 2010 08:48:50 +0000 (+0200) Subject: src/sn_stage.c: Added some parameter checks. X-Git-Tag: v1.0.0~40 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=5c159ad124f930cf65c9c7c107cb82920ca1ef69;p=sort-networks.git src/sn_stage.c: Added some parameter checks. --- diff --git a/src/sn_stage.c b/src/sn_stage.c index 56512ea..e6425bf 100644 --- a/src/sn_stage.c +++ b/src/sn_stage.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "sn_comparator.h" #include "sn_stage.h" @@ -82,10 +83,17 @@ int sn_stage_comparator_add (sn_stage_t *s, const sn_comparator_t *c) sn_comparator_t *temp; int i; + if ((s == NULL) || (c == NULL)) + return (EINVAL); + + i = sn_stage_comparator_check_conflict (s, c); + if (i != 0) + return (i); + temp = (sn_comparator_t *) realloc (s->comparators, (s->comparators_num + 1) * sizeof (sn_comparator_t)); if (temp == NULL) - return (-1); + return (ENOMEM); s->comparators = temp; temp = NULL; @@ -112,6 +120,9 @@ int sn_stage_comparator_remove (sn_stage_t *s, int c_num) int nmemb = s->comparators_num - (c_num + 1); sn_comparator_t *temp; + if ((s == NULL) || (s->comparators_num <= c_num)) + return (EINVAL); + assert (c_num < s->comparators_num); assert (c_num >= 0); @@ -307,6 +318,9 @@ int sn_stage_cut_at (sn_stage_t *s, int input, enum sn_network_cut_dir_e dir) int new_position = input; int i; + if ((s == NULL) || (input < 0)) + return (-EINVAL); + for (i = 0; i < s->comparators_num; i++) { sn_comparator_t *c = s->comparators + i;