Android-x86
Fork
Faire un don

  • R/O
  • HTTP
  • SSH
  • HTTPS

hardware-libsensors: Commit

hardware/libsensors


Commit MetaInfo

Révisionaacbecd62199ce115f3aa79c2d46ba5a774c6e44 (tree)
l'heure2017-11-23 15:18:27
AuteurChih-Wei Huang <cwhuang@linu...>
CommiterChih-Wei Huang

Message de Log

iio-sensors: avoid memset a dynamic class

A dynamic class doesn't support static initialization. The compiler
complains:

hardware/libsensors/iio-sensors.cpp:119:9: warning: destination for this 'memset' call is a pointer to dynamic class 'SensorBase'; vtable pointer will be overwritten [-Wdynamic-class-memaccess]

memset(this, 0, sizeof(SensorBase));

Move all data members of SensorBase to a trivial class which could be
statically initialized.

Refer: http://en.cppreference.com/w/cpp/types/is_trivial

Change Summary

Modification

--- a/iio-sensors.cpp
+++ b/iio-sensors.cpp
@@ -92,7 +92,17 @@ SensorEvent::SensorEvent(int32_t id, int32_t t)
9292 timestamp = int64_t(ts.tv_sec) * NSEC_PER_SEC + ts.tv_nsec;
9393 }
9494
95-class SensorBase : public sensor_t {
95+class sensor_base : public sensor_t {
96+ protected:
97+ sensor_base() { memset(this, 0, sizeof(*this)); }
98+
99+ bool enabled;
100+ char *path;
101+ const char ***nodes;
102+ struct timespec delay;
103+};
104+
105+class SensorBase : public sensor_base {
96106 public:
97107 SensorBase();
98108 virtual ~SensorBase();
@@ -107,17 +117,10 @@ class SensorBase : public sensor_t {
107117 int read_sysfs_str(const char *file, char *buf);
108118 int read_sysfs_int(const char *file);
109119 float read_sysfs_float(const char *file);
110-
111- bool enabled;
112- char *path;
113- const char ***nodes;
114- struct timespec delay;
115120 };
116121
117122 SensorBase::SensorBase()
118123 {
119- memset(this, 0, sizeof(SensorBase));
120-
121124 vendor = "Android-x86 Open Source Project";
122125 version = 1;
123126
Afficher sur ancien navigateur de dépôt.