From a2ec81696de98151bfdf1913042a739ef6d8a36c Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 11 Jan 2018 14:38:06 +0100 Subject: 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 --- contrib/npclient/npclient.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'contrib/npclient/npclient.c') 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 { -- cgit v1.2.3