[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] BUG: UintFromObj from base.c does not check for errors
- To: pygame-users@xxxxxxxx
- Subject: Re: [pygame] BUG: UintFromObj from base.c does not check for errors
- From: "René Dudfield" <renesd@xxxxxxxxx>
- Date: Tue, 2 Sep 2008 14:10:20 +1000
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Tue, 02 Sep 2008 00:10:35 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=GWYItWf47dbASIZdLP49fUsbKmUuw2lYOJ9pD7pO3i0=; b=mrYTnTxR6MpDMhc2T3Gq1rtkiMd6P/Wa0Vm5Zza4LG1QrXxcd9fTUkljnbdNaa0vBH uw6J1AAq0nAdQmXpFbUmCjx1Rvf6ANiU1DS+phzgmJnPMGPYzIcg3e8cwVjfOUIWQvUr 7gZlojk9NJIZE2eS085vS2e/QSWea98qT1JCo=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=Dq6AbpHekHVL76F3JzswWA26WI0SE50BxtsvYYnl2CNOuOWyZ05lKanB0SFulMC3wM FDErk7M/uRL/upIqEB+MT/jM5K9cviw191T+SLp1Qia1ZOSWDIbQSIEl/OkB8Z6x16sm Ic9nc/V+cSAcMKFauoZ5Ko9aQG4oowaF2mwls=
- In-reply-to: <160ec900808311308i8697192g8775b942f4bfbaca@xxxxxxxxxxxxxx>
- References: <160ec900808311308i8697192g8775b942f4bfbaca@xxxxxxxxxxxxxx>
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
Thanks.
Does the change below look ok? (non-compiled, non-tested code)
I'm without internet at home for a week or so... so if someone else
can look over it, test it, and commit it that'd be cool?
from src/base.c
static int UintFromObj (PyObject* obj, Uint32* val) {
PyObject* intobj;
int tmp_val;
if (PyNumber_Check (obj)) {
if (!(intobj = PyNumber_Int (obj)))
return 0;
tmp_val = PyInt_AsLong (obj);
if (tmp_val == -1 && PyErr_Occurred ()) {
PyErr_Clear ();
Py_DECREF (intobj);
return 0;
}
*val = (Uint32) tmp_val;
Py_DECREF (intobj);
return 1;
}
return 0;
}
On Mon, Sep 1, 2008 at 6:08 AM, Devan <devlai@xxxxxxxxx> wrote:
> Hi,
> It appears that the utility function UintFromObj does not check if an
> error has occurred after calling PyInt_AsLong. If an error (namely an
> overflow error if the object is actually a long) occured, then it is
> silently ignored until the next call to PyErr_Occurred. In my case
> this propped up while working on an extension module that caught an
> OverflowError on a subsequent call.
>
> If there is a specific reason for ignoring any errors (IntFromObj
> seems to explicitly clear any errors and return 0 instead), then I
> think the best thing would be to replace PyInt_AsLong with the macro
> PyInt_AS_LONG which does not do error checking and will not leave an
> exception hanging around.
>
> Thanks,
> - Devan.
>
> PS: I ran into this while trying using surface.convert(masks). Is
> there a better way to create the masks than x |= (1 << 0) | (1 << 1) |
> (1 << 2)... | (1 <<7) ?
>