Skip to content

Commit

Permalink
UPBGE: Fix python setUseExternalTime call.
Browse files Browse the repository at this point in the history
Python can't convert a boolean argument from python to
a bool in C through PyArg_ParseTuple. Else a stack smashing
appears (maybe writing a int to a bool and resulting in overflow).
This error is so easy to make and nothing could show it at compilation.
Be aware of this.
  • Loading branch information
panzergame committed Aug 7, 2017
1 parent 1028e0c commit fa20294
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions source/gameengine/Ketsji/KX_PythonInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,12 +461,12 @@ static PyObject *gPyGetUseExternalClock(PyObject *)

static PyObject *gPySetUseExternalClock(PyObject *, PyObject *args)
{
bool bUseExternalClock;
int bUseExternalClock;

if (!PyArg_ParseTuple(args, "p:setUseExternalClock", &bUseExternalClock))
return nullptr;

KX_GetActiveEngine()->SetFlag(KX_KetsjiEngine::USE_EXTERNAL_CLOCK, bUseExternalClock);
KX_GetActiveEngine()->SetFlag(KX_KetsjiEngine::USE_EXTERNAL_CLOCK, (bool)bUseExternalClock);
Py_RETURN_NONE;
}

Expand Down

2 comments on commit fa20294

@youle31
Copy link
Collaborator

@youle31 youle31 commented on fa20294 Aug 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello! in if (!PyArg_ParseTuple(args, "p: what is the "p"? I'm used to see i for int iirc

@panzergame
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"p" is for true or false objects, "i" works too, but it should failed in python when we sent a object which is true but not an integer or a boolean.

Please sign in to comment.