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
timestamp = int64_t(ts.tv_sec) * NSEC_PER_SEC + ts.tv_nsec;
}
-class SensorBase : public sensor_t {
+class sensor_base : public sensor_t {
+ protected:
+ sensor_base() { memset(this, 0, sizeof(*this)); }
+
+ bool enabled;
+ char *path;
+ const char ***nodes;
+ struct timespec delay;
+};
+
+class SensorBase : public sensor_base {
public:
SensorBase();
virtual ~SensorBase();
int read_sysfs_str(const char *file, char *buf);
int read_sysfs_int(const char *file);
float read_sysfs_float(const char *file);
-
- bool enabled;
- char *path;
- const char ***nodes;
- struct timespec delay;
};
SensorBase::SensorBase()
{
- memset(this, 0, sizeof(SensorBase));
-
vendor = "Android-x86 Open Source Project";
version = 1;