From: zooko Date: Fri, 26 Jan 2007 00:47:04 +0000 (+0530) Subject: pyfec: add precondition checks on the values of k and m to constructors X-Git-Url: https://git.rkrishnan.org/components/%22news.html/configuration.txt?a=commitdiff_plain;h=482d7ee57dad92c7d4417ac63096fbeb7655cd3e;p=tahoe-lafs%2Fzfec.git pyfec: add precondition checks on the values of k and m to constructors darcs-hash:2c24684ca751b8b43c46c10e20c7cd0d41195aa5 --- diff --git a/pyfec/fec/fecmodule.c b/pyfec/fec/fecmodule.c index 8e01315..6592428 100644 --- a/pyfec/fec/fecmodule.c +++ b/pyfec/fec/fecmodule.c @@ -96,11 +96,23 @@ Encoder_init(Encoder *self, PyObject *args, PyObject *kwdict) { if (!PyArg_ParseTupleAndKeywords(args, kwdict, "ii", kwlist, &self->kk, &self->mm)) return -1; - self->fec_matrix = fec_new(self->kk, self->mm); - if(self->fec_matrix == NULL) { - py_raise_fec_error(fec_error); /* xyz */ - return -1; + if (self->kk < 1) { + py_raise_fec_error("Precondition violation: first argument is required to be greater than or equal to 1, but it was %d", self->kk); + return -1; + } + if (self->mm < 1) { + py_raise_fec_error("Precondition violation: second argument is required to be greater than or equal to 1, but it was %d", self->mm); + return -1; + } + if (self->mm > 255) { + py_raise_fec_error("Precondition violation: second argument is required to be less than or equal to 255, but it was %d", self->mm); + return -1; } + if (self->kk > self->mm) { + py_raise_fec_error("Precondition violation: first argument is required to be less than or equal to the second argument, but they were %d and %d respectively", self->kk, self->mm); + return -1; + } + self->fec_matrix = fec_new(self->kk, self->mm); return 0; } @@ -333,14 +345,27 @@ Decoder_init(Encoder *self, PyObject *args, PyObject *kwdict) { "m", NULL }; + if (!PyArg_ParseTupleAndKeywords(args, kwdict, "ii", kwlist, &self->kk, &self->mm)) return -1; - self->fec_matrix = fec_new(self->kk, self->mm); - if(self->fec_matrix == NULL) { - py_raise_fec_error(fec_error); /* xyz */ - return -1; + if (self->kk < 1) { + py_raise_fec_error("Precondition violation: first argument is required to be greater than or equal to 1, but it was %d", self->kk); + return -1; + } + if (self->mm < 1) { + py_raise_fec_error("Precondition violation: second argument is required to be greater than or equal to 1, but it was %d", self->mm); + return -1; } + if (self->mm > 255) { + py_raise_fec_error("Precondition violation: second argument is required to be less than or equal to 255, but it was %d", self->mm); + return -1; + } + if (self->kk > self->mm) { + py_raise_fec_error("Precondition violation: first argument is required to be less than or equal to the second argument, but they were %d and %d respectively", self->kk, self->mm); + return -1; + } + self->fec_matrix = fec_new(self->kk, self->mm); return 0; }