From: Zooko O'Whielacronx zooko@zooko.com Date: Thu, 1 Feb 2007 01:01:40 +0000 (+0530) Subject: pyfec: fix precondition checks on k and m to actually check the value before coercing... X-Git-Url: https://git.rkrishnan.org/vdrive/%22news.html//%22%22.?a=commitdiff_plain;h=70ad650bed2141ee1ac952575fd41e1d50163c7b;p=tahoe-lafs%2Fzfec.git pyfec: fix precondition checks on k and m to actually check the value before coercing it into a smaller type (oops) darcs-hash:21df35e9c35aabba96d79ce0a08ed44061320811 --- diff --git a/pyfec/fec/_fecmodule.c b/pyfec/fec/_fecmodule.c index e3d68c5..d1c3174 100644 --- a/pyfec/fec/_fecmodule.c +++ b/pyfec/fec/_fecmodule.c @@ -99,14 +99,15 @@ Encoder_init(Encoder *self, PyObject *args, PyObject *kwdict) { "m", NULL }; - if (!PyArg_ParseTupleAndKeywords(args, kwdict, "ii", kwlist, &self->kk, &self->mm)) + int ink, inm; + if (!PyArg_ParseTupleAndKeywords(args, kwdict, "ii", kwlist, &ink, &inm)) return -1; - if (self->kk < 1) { + if (ink < 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) { + if (inm < 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; } @@ -114,10 +115,12 @@ Encoder_init(Encoder *self, PyObject *args, PyObject *kwdict) { 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); + if (ink > inm) { + 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", ink, inm); return -1; } + self->kk = (unsigned char)ink; + self->mm = (unsigned char)inm; self->fec_matrix = fec_new(self->kk, self->mm); return 0; @@ -352,14 +355,15 @@ Decoder_init(Encoder *self, PyObject *args, PyObject *kwdict) { NULL }; - if (!PyArg_ParseTupleAndKeywords(args, kwdict, "ii", kwlist, &self->kk, &self->mm)) + int ink, inm; + if (!PyArg_ParseTupleAndKeywords(args, kwdict, "ii", kwlist, &ink, &inm)) return -1; - if (self->kk < 1) { + if (ink < 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) { + if (inm < 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; } @@ -367,10 +371,12 @@ Decoder_init(Encoder *self, PyObject *args, PyObject *kwdict) { 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); + if (ink > inm) { + 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", ink, inm); return -1; } + self->kk = (unsigned char)ink; + self->mm = (unsigned char)inm; self->fec_matrix = fec_new(self->kk, self->mm); return 0;