summaryrefslogtreecommitdiffhomepage
path: root/x-plane-plugin
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2017-10-27 13:51:33 +0200
committerStanislaw Halik <sthalik@misaki.pl>2017-10-27 16:43:03 +0200
commit52e73f03f27104c094a9b8e66076a9c593a3c869 (patch)
tree8d474c033871da0845fc931e960c0e1595029f52 /x-plane-plugin
parent257189b17867ce3ad8e35dc18c80831b4c9b5530 (diff)
x-plane: fix buffer overflow
Also, mismatched lock/release and bad logic
Diffstat (limited to 'x-plane-plugin')
-rw-r--r--x-plane-plugin/plugin.c32
1 files changed, 9 insertions, 23 deletions
diff --git a/x-plane-plugin/plugin.c b/x-plane-plugin/plugin.c
index 26ea18e9..88962442 100644
--- a/x-plane-plugin/plugin.c
+++ b/x-plane-plugin/plugin.c
@@ -54,7 +54,6 @@ typedef struct WineSHM
static shm_wrapper* lck_posix = NULL;
static WineSHM* shm_posix = NULL;
-static WineSHM* data_last = NULL;
static void *view_x, *view_y, *view_z, *view_heading, *view_pitch, *view_roll;
static float offset_x, offset_y, offset_z;
static XPLMCommandRef track_toggle = NULL, translation_disable_toggle = NULL;
@@ -113,29 +112,16 @@ float write_head_position(
void * unused(inRefcon) )
{
if (lck_posix != NULL && shm_posix != NULL) {
- if(data_last == NULL){
- data_last = calloc(1, sizeof(WineSHM));
+ shm_wrapper_lock(lck_posix);
+ if (!translation_disabled)
+ {
+ XPLMSetDataf(view_x, shm_posix->data[TX] * 1e-3 + offset_x);
+ XPLMSetDataf(view_y, shm_posix->data[TY] * 1e-3 + offset_y);
+ XPLMSetDataf(view_z, shm_posix->data[TZ] * 1e-3 + offset_z);
}
-
- //only set the view if tracking is running
- if(memcmp(shm_posix, data_last, sizeof(shm_posix->data)) != 0){
- shm_wrapper_lock(lck_posix);
- if (!translation_disabled)
- {
- XPLMSetDataf(view_x, shm_posix->data[TX] * 1e-3 + offset_x);
- XPLMSetDataf(view_y, shm_posix->data[TY] * 1e-3 + offset_y);
- XPLMSetDataf(view_z, shm_posix->data[TZ] * 1e-3 + offset_z);
- }
- XPLMSetDataf(view_heading, shm_posix->data[Yaw] * 180 / M_PI);
- XPLMSetDataf(view_pitch, shm_posix->data[Pitch] * 180 / M_PI);
- XPLMSetDataf(view_roll, shm_posix->data[Roll] * 180 / M_PI);
- } else {
- //reset roll, otherwise it would be stuck at last angle
- XPLMSetDataf(view_roll, 0);
- }
-
- memcpy(&data_last, &shm_posix, sizeof(WineSHM));
-
+ XPLMSetDataf(view_heading, shm_posix->data[Yaw] * 180 / M_PI);
+ XPLMSetDataf(view_pitch, shm_posix->data[Pitch] * 180 / M_PI);
+ XPLMSetDataf(view_roll, shm_posix->data[Roll] * 180 / M_PI);
shm_wrapper_unlock(lck_posix);
}
return -1.0;