summaryrefslogtreecommitdiffhomepage
path: root/contrib/npclient/npclient.c
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2018-01-11 14:38:06 +0100
committerStanislaw Halik <sthalik@misaki.pl>2018-01-11 14:38:06 +0100
commita2ec81696de98151bfdf1913042a739ef6d8a36c (patch)
tree0e7dc6cfcf23b13cdfc4af829a81110ae1e1da78 /contrib/npclient/npclient.c
parente1d6232217120be879bb639681f61e46e2d48580 (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
Diffstat (limited to 'contrib/npclient/npclient.c')
-rw-r--r--contrib/npclient/npclient.c6
1 files changed, 3 insertions, 3 deletions
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
{