Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Port fix for a segfault #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions kdrive/linux/mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,7 @@ static const KmouseProt exps2Prot = {
#define PSM_4DPLUS_ID 8

static const unsigned char ps2_init[] = {
PSMC_ENABLE_DEV,
0,
PSMC_ENABLE_DEV
Copy link

Choose a reason for hiding this comment

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

how does removing these 0's fix a segfault ?

};

#define NINIT_PS2 1
Expand All @@ -397,7 +396,6 @@ static const unsigned char wheel_3button_init[] = {
PSMC_SET_SAMPLING_RATE, 100,
PSMC_SET_SAMPLING_RATE, 80,
PSMC_SEND_DEV_ID,
0,
};

#define NINIT_IMPS2 4
Expand All @@ -410,7 +408,6 @@ static const unsigned char wheel_5button_init[] = {
PSMC_SET_SAMPLING_RATE, 200,
PSMC_SET_SAMPLING_RATE, 80,
PSMC_SEND_DEV_ID,
0
};

#define NINIT_EXPS2 7
Expand All @@ -419,7 +416,6 @@ static const unsigned char intelli_init[] = {
PSMC_SET_SAMPLING_RATE, 200,
PSMC_SET_SAMPLING_RATE, 100,
PSMC_SET_SAMPLING_RATE, 80,
0
};

#define NINIT_INTELLI 3
Expand Down Expand Up @@ -456,9 +452,10 @@ static Bool ps2Init(KdMouseInfo * mi)
int id;
const unsigned char *init;
int ninit;
int len;

/* Send Intellimouse initialization sequence */
MouseWriteBytes(km->iob.fd, intelli_init, strlen((char *)intelli_init),
MouseWriteBytes(km->iob.fd, intelli_init, sizeof(intelli_init),
100);
/*
* Send ID command
Expand All @@ -471,20 +468,23 @@ static Bool ps2Init(KdMouseInfo * mi)
init = wheel_3button_init;
ninit = NINIT_IMPS2;
km->prot = &imps2Prot;
len = sizeof(wheel_3button_init);
break;
case 4:
init = wheel_5button_init;
ninit = NINIT_EXPS2;
km->prot = &exps2Prot;
len = sizeof(wheel_5button_init);
break;
default:
init = ps2_init;
ninit = NINIT_PS2;
km->prot = &ps2Prot;
len = sizeof(ps2_init);
break;
}
if (init)
MouseWriteBytes(km->iob.fd, init, strlen((char *)init), 100);
MouseWriteBytes(km->iob.fd, init, len, 100);
/*
* Flush out the available data to eliminate responses to the
* initialization string. Make sure any partial event is
Expand Down Expand Up @@ -729,6 +729,9 @@ static void MouseFirstProtocol(Kmouse * km, char *prot)
for (i = 0; i < NUM_PROT; i++)
ErrorF(" %s", kmouseProts[i]->name);
ErrorF("\n");
km->i_prot = 0;
km->prot = kmouseProts[km->i_prot];
ErrorF("Falling back to %s\n", km->prot->name);
} else {
km->prot = kmouseProts[km->i_prot];
if (km->tty && !km->prot->tty)
Expand All @@ -754,7 +757,7 @@ static void MouseNextProtocol(Kmouse * km)
do {
if (!km->prot)
km->i_prot = 0;
else if (++km->i_prot == NUM_PROT)
else if (++km->i_prot >= NUM_PROT)
km->i_prot = 0;
km->prot = kmouseProts[km->i_prot];
} while (km->prot->tty != km->tty);
Expand Down