ソースを参照

Fix or hide most compiler warnings reported by gcc 7.3 (#132)

* Share _hid_to_unix_path function

Share the rift version of _hid_to_unix_path with deepoon and nolo drivers.
This fixes the following compiler warnings:

  drv_deepoon/deepoon.c: In function ‘open_device’:
  drv_deepoon/deepoon.c:198:21: warning: ‘
     ’ directive writing 1 byte into a region of size between 0 and 4 [-Wformat-overflow=]
    sprintf (bus, "%.*s\n", 4, path);
                       ^~
  drv_deepoon/deepoon.c:198:2: note: ‘sprintf’ output between 2 and 6 bytes into a destination of size 4
    sprintf (bus, "%.*s\n", 4, path);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  drv_deepoon/deepoon.c:199:21: warning: ‘
     ’ directive writing 1 byte into a region of size between 0 and 4 [-Wformat-overflow=]
    sprintf (dev, "%.*s\n", 4, path + 5);
                       ^~
  drv_deepoon/deepoon.c:199:2: note: ‘sprintf’ output between 2 and 6 bytes into a destination of size 4
    sprintf (dev, "%.*s\n", 4, path + 5);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  drv_nolo/nolo.c: In function ‘open_device’:
  drv_nolo/nolo.c:150:21: warning: ‘
     ’ directive writing 1 byte into a region of size between 0 and 16 [-Wformat-overflow=]
    sprintf (bus, "%.*s\n", len, path);
                       ^~
  drv_nolo/nolo.c:150:2: note: ‘sprintf’ output between 2 and 18 bytes into a destination of size 16
    sprintf (bus, "%.*s\n", len, path);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  drv_nolo/nolo.c:151:21: warning: ‘
     ’ directive writing 1 byte into a region of size between 0 and 16 [-Wformat-overflow=]
    sprintf (dev, "%.*s\n", len, path + 5);
                       ^~
  drv_nolo/nolo.c:151:2: note: ‘sprintf’ output between 2 and 18 bytes into a destination of size 16
    sprintf (dev, "%.*s\n", len, path + 5);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

* nolo: remove unused send_feature_report function

This fixes the following compiler warning:

  drv_nolo/nolo.c:32:12: warning: ‘send_feature_report’ defined but not used [-Wunused-function]
   static int send_feature_report(drv_priv* priv, const unsigned char *data, size_t length)
              ^~~~~~~~~~~~~~~~~~~

* psvr: remove unused local idx variable

This fixes the following compiler warning:

  drv_psvr/psvr.c: In function ‘open_device’:
  drv_psvr/psvr.c:190:6: warning: unused variable ‘idx’ [-Wunused-variable]
    int idx = atoi(desc->path);
        ^~~

* vive: ignore misleading indentation compiler warnings for miniz.c

This hides the following compiler warnings:

  In file included from drv_htc_vive/vive_config.h:8:0,
                   from drv_htc_vive/packet.c:2:
  drv_htc_vive/../ext_deps/miniz.c: In function ‘tinfl_decompress’:
  drv_htc_vive/../ext_deps/miniz.c:1500:9: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation]
           for ( i = 0; i <= 143; ++i) *p++ = 8; for ( ; i <= 255; ++i) *p++ = 9; for ( ; i <= 279; ++i) *p++ = 7; for ( ; i <= 287; ++i) *p++ = 8;
           ^~~
  drv_htc_vive/../ext_deps/miniz.c:1500:47: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’
           for ( i = 0; i <= 143; ++i) *p++ = 8; for ( ; i <= 255; ++i) *p++ = 9; for ( ; i <= 279; ++i) *p++ = 7; for ( ; i <= 287; ++i) *p++ = 8;
                                                 ^~~
  drv_htc_vive/../ext_deps/miniz.c: In function ‘tdefl_find_match’:
  drv_htc_vive/../ext_deps/miniz.c:2284:5: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
       if (!dist) break; q = (const mz_uint16*)(d->m_dict + probe_pos); if (TDEFL_READ_UNALIGNED_WORD(q) != s01) continue; p = s; probe_len = 32;
       ^~
  drv_htc_vive/../ext_deps/miniz.c:2284:23: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’
       if (!dist) break; q = (const mz_uint16*)(d->m_dict + probe_pos); if (TDEFL_READ_UNALIGNED_WORD(q) != s01) continue; p = s; probe_len = 32;
                         ^

* wmr: work around false positive warning on ancient gcc

Declare the raw gyro and accelerometer values passed to the vec3f conversion
helpers as non-const to avoid the following compiler warnings on ancient
gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4:

  drv_wmr/wmr.c: In function 'handle_tracker_sensor_msg':
  drv_wmr/wmr.c:93:3: warning: passing argument 1 of 'vec3f_from_hololens_gyro' from incompatible pointer type [enabled by default]
     vec3f_from_hololens_gyro(s->gyro, i, &priv->raw_gyro);
     ^
  drv_wmr/wmr.c:38:13: note: expected 'const int16_t (*)[32]' but argument is of type 'int16_t (*)[32]'
   static void vec3f_from_hololens_gyro(const int16_t smp[3][32], int i, vec3f* out_vec)
               ^
  drv_wmr/wmr.c:94:3: warning: passing argument 1 of 'vec3f_from_hololens_accel' from incompatible pointer type [enabled by default]
     vec3f_from_hololens_accel(s->accel, i, &priv->raw_accel);
     ^
  drv_wmr/wmr.c:66:13: note: expected 'const int32_t (*)[4]' but argument is of type 'int32_t (*)[4]'
   static void vec3f_from_hololens_accel(const int32_t smp[3][4], int i, vec3f* out_vec)
               ^
Philipp Zabel 7 年 前
コミット
3e0a641d35

+ 1 - 15
src/drv_deepoon/deepoon.c

@@ -15,6 +15,7 @@
 #include <assert.h>
 
 #include "deepoon.h"
+#include "../hid.h"
 
 #define TICK_LEN (1.0f / 1000000.0f) // 1000 Hz ticks
 #define KEEP_ALIVE_VALUE (10 * 1000)
@@ -189,21 +190,6 @@ static void close_device(ohmd_device* device)
 	free(priv);
 }
 
-static char* _hid_to_unix_path(char* path)
-{
-	char bus [4];
-	char dev [4];
-	char *result = malloc( sizeof(char) * ( 20 + 1 ) );
-
-	sprintf (bus, "%.*s\n", 4, path);
-	sprintf (dev, "%.*s\n", 4, path + 5);
-
-	sprintf (result, "/dev/bus/usb/%03d/%03d",
-		(int)strtol(bus, NULL, 16),
-		(int)strtol(dev, NULL, 16));
-	return result;
-}
-
 static ohmd_device* open_device(ohmd_driver* driver, ohmd_device_desc* desc)
 {
 	rift_priv* priv = ohmd_alloc(driver->ctx, sizeof(rift_priv));

+ 1 - 0
src/drv_htc_vive/vive_config.h

@@ -5,6 +5,7 @@
 #pragma GCC diagnostic ignored "-Wstrict-aliasing"
 #pragma GCC diagnostic ignored "-Wswitch"
 #pragma GCC diagnostic ignored "-Wimplicit-function-declaration"
+#pragma GCC diagnostic ignored "-Wmisleading-indentation"
 #include "../ext_deps/miniz.c"
 #include "../ext_deps/mjson.h"
 #pragma GCC diagnostic pop

+ 1 - 22
src/drv_nolo/nolo.c

@@ -16,6 +16,7 @@
 #include <assert.h>
 
 #include "nolo.h"
+#include "../hid.h"
 
 #define NOLO_ID					0x0483 //ST microcontroller
 #define NOLO_HMD				0x5750
@@ -28,11 +29,6 @@ static drv_priv* drv_priv_get(ohmd_device* device)
 	return (drv_priv*)device;
 }
 
-static int send_feature_report(drv_priv* priv, const unsigned char *data, size_t length)
-{
-	return hid_send_feature_report(priv->handle, data, length);
-}
-
 static void update_device(ohmd_device* device)
 {
 	drv_priv* priv = drv_priv_get(device);
@@ -145,23 +141,6 @@ static void close_device(ohmd_device* device)
 	free(priv);
 }
 
-static char* _hid_to_unix_path(char* path)
-{
-	const int len = 16;
-	char bus [16];
-	char dev [16];
-	char *result = malloc( sizeof(char) * ( 20 + 1 ) );
-
-	sprintf (bus, "%.*s\n", len, path);
-	sprintf (dev, "%.*s\n", len, path + 5);
-
-	sprintf (result, "/dev/bus/usb/%03d/%03d",
-		(int)strtol(bus, NULL, 16),
-		(int)strtol(dev, NULL, 16));
-	return result;
-}
-
-
 void push_device(devices_t * head, drv_nolo* val) {
 	devices_t* current = head;
 

+ 1 - 15
src/drv_oculus_rift/rift.c

@@ -15,6 +15,7 @@
 #include <assert.h>
 
 #include "rift.h"
+#include "../hid.h"
 
 #define TICK_LEN (1.0f / 1000.0f) // 1000 Hz ticks
 #define KEEP_ALIVE_VALUE (10 * 1000)
@@ -219,21 +220,6 @@ static void close_device(ohmd_device* device)
 	free(priv);
 }
 
-static char* _hid_to_unix_path(char* path)
-{
-	char bus [5];
-	char dev [5];
-	char *result = malloc( sizeof(char) * ( 20 + 1 ) );
-
-	sprintf (bus, "%.*s", 4, path);
-	sprintf (dev, "%.*s", 4, path + 5);
-
-	sprintf (result, "/dev/bus/usb/%03d/%03d",
-		(int)strtol(bus, NULL, 16),
-		(int)strtol(dev, NULL, 16));
-	return result;
-}
-
 #define UDEV_WIKI_URL "https://github.com/OpenHMD/OpenHMD/wiki/Udev-rules-list"
 
 static ohmd_device* open_device(ohmd_driver* driver, ohmd_device_desc* desc)

+ 0 - 2
src/drv_psvr/psvr.c

@@ -187,8 +187,6 @@ static ohmd_device* open_device(ohmd_driver* driver, ohmd_device_desc* desc)
 
 	priv->base.ctx = driver->ctx;
 
-	int idx = atoi(desc->path);
-
 	// Open the HMD device
 	priv->hmd_handle = open_device_idx(SONY_ID, PSVR_HMD, 0, 0, 4);
 

+ 2 - 2
src/drv_wmr/wmr.c

@@ -35,7 +35,7 @@ typedef struct {
 
 } wmr_priv;
 
-static void vec3f_from_hololens_gyro(const int16_t smp[3][32], int i, vec3f* out_vec)
+static void vec3f_from_hololens_gyro(int16_t smp[3][32], int i, vec3f* out_vec)
 {
 	out_vec->x = (float)(smp[1][8*i+0] +
 			     smp[1][8*i+1] +
@@ -63,7 +63,7 @@ static void vec3f_from_hololens_gyro(const int16_t smp[3][32], int i, vec3f* out
 			     smp[2][8*i+7]) * 0.001f * -0.125f;
 }
 
-static void vec3f_from_hololens_accel(const int32_t smp[3][4], int i, vec3f* out_vec)
+static void vec3f_from_hololens_accel(int32_t smp[3][4], int i, vec3f* out_vec)
 {
 	out_vec->x = (float)smp[1][i] * 0.001f * -1.0f;
 	out_vec->y = (float)smp[0][i] * 0.001f * -1.0f;

+ 15 - 0
src/hid.h

@@ -0,0 +1,15 @@
+static inline char* _hid_to_unix_path(char* path)
+{
+	char bus [5];
+	char dev [5];
+	char *result = malloc( sizeof(char) * ( 20 + 1 ) );
+
+	sprintf (bus, "%.*s", 4, path);
+	sprintf (dev, "%.*s", 4, path + 5);
+
+	sprintf (result, "/dev/bus/usb/%03d/%03d",
+		(int)strtol(bus, NULL, 16),
+		(int)strtol(dev, NULL, 16));
+	return result;
+}
+