Bug in pfuGetEvents

New Message Reply Date view Thread view Subject view Author view

Mario Veraart (rioj7++at++fel.tno.nl)
Wed, 10 Feb 1999 22:31:41 +0100 (MET)


Hello,

I have found what could be a bug in the code of pfuGetEvents.
Depending on the time that it takes to get the forked X-input process
initialised you have the value of the returned structure also
uninisialised.
In case of the following code

pfuEventStream events;

pfuGetEvents (&events);

if ( (events.numDevs<0) || (events.numDevs >= PFUDEV_MAX_DEVS) ) {
    errorMessage ("KeybdUpdate", "Wrong nr of devices : %d",
        events.numDevs);
    events.numDevs = 0;
    return;
}

I get sometimes the following output

PF Info: X input process 122397 running for channel 0
[STW] Error in KeybdUpdate ### Wrong nr of devices : 230626048
PF Notice(11): Using 60Hz video rate.
PF Info: Asynchronous X Input process 122397 opened on Display :0.0

After a look at the source code of pfuGetEvents I saw the cause.
The marked 'return' statement should be a 'continue' statement, that way
the events structure gets initialised because there are no events
found.

void
pfuGetEvents(pfuEventStream* events)
{
    int dfs, efs;
    XEvent event;
    int chan;
    int events_found = 0;

#ifdef DO_TIME
    float start_time, acquire_time, total_time;
#endif
    if (!DeviceInput)
            initDataPool();

    for (chan = 0; chan < DeviceInput->numChan; chan++)
    {
        if (!DeviceInput->forked &&
            (DeviceInput->mode == PFUINPUT_X) &&
            !DeviceInput->inited[chan])
            openXInput(chan);
        if (!DeviceInput->inited[chan])
            return;
            ^^^^^^ this should be a 'continue;' statement

The workaround, if you do not recompile pfutil, is the following code

pfuEventStream events;

events.numDevs = 0;
pfuGetEvents (&events);

Mario Veraart


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Wed Feb 10 1999 - 13:34:24 PST

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.