diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2018-01-11 14:38:06 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2018-01-11 14:38:06 +0100 |
commit | a2ec81696de98151bfdf1913042a739ef6d8a36c (patch) | |
tree | 0e7dc6cfcf23b13cdfc4af829a81110ae1e1da78 | |
parent | e1d6232217120be879bb639681f61e46e2d48580 (diff) |
contrib/npclient: fix DataID race
There's a race with how the freetrack protocol operates.
Reported-by: @Len62
cf. https://github.com/opentrack/opentrack/issues/688#issuecomment-356606126
-rw-r--r-- | bin/NPClient.dll | bin | 16384 -> 16384 bytes | |||
-rw-r--r-- | bin/NPClient64.dll | bin | 17408 -> 17408 bytes | |||
-rw-r--r-- | contrib/npclient/npclient.c | 6 |
3 files changed, 3 insertions, 3 deletions
diff --git a/bin/NPClient.dll b/bin/NPClient.dll Binary files differindex ddfa667e..54a2d0f6 100644 --- a/bin/NPClient.dll +++ b/bin/NPClient.dll diff --git a/bin/NPClient64.dll b/bin/NPClient64.dll Binary files differindex eb56a256..f8315d50 100644 --- a/bin/NPClient64.dll +++ b/bin/NPClient64.dll diff --git a/contrib/npclient/npclient.c b/contrib/npclient/npclient.c index 6ffa7f34..71c5ec2a 100644 --- a/contrib/npclient/npclient.c +++ b/contrib/npclient/npclient.c @@ -332,19 +332,19 @@ NP_EXPORT(int) NP_GetData(tir_data_t * data) frameno++; data->frame = frameno; - int data_id = InterlockedDecrement((LONG volatile*) &pMemData->data.DataID); - + int data_id = InterlockedCompareExchange((LONG volatile*) &pMemData->data.DataID, -1, -1); bool running; if (data_id == 0) { running = true; y = 0, r = 0, p = 0, tx = 0, ty = 0, tz = 0; - InterlockedCompareExchange((LONG volatile*) &pMemData->data.DataID, -1, 0); + (void)InterlockedCompareExchange((LONG volatile*) &pMemData->data.DataID, -1, 0); } else if (data_id > 0) { running = true; + (void)InterlockedCompareExchange((LONG volatile*) &pMemData->data.DataID, data_id - 1, data_id); } else { |