Skip to content

Commit

Permalink
Use C++11 struct initializer
Browse files Browse the repository at this point in the history
  • Loading branch information
jbleyel committed Sep 23, 2024
1 parent 4c75add commit 717ec7c
Show file tree
Hide file tree
Showing 43 changed files with 123 additions and 128 deletions.
4 changes: 2 additions & 2 deletions lib/actions/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,8 @@ void eActionMap::keyPressed(const std::string &device, int key, int flags)
(k->second.m_device == device || k->second.m_device == "generic"))
{
ePyObject pArgs = PyTuple_New(2);
PyTuple_SET_ITEM(pArgs, 0, PyString_FromString(k->first.c_str()));
PyTuple_SET_ITEM(pArgs, 1, PyString_FromString(k->second.m_action.c_str()));
PyTuple_SET_ITEM(pArgs, 0, PyUnicode_FromString(k->first.c_str()));
PyTuple_SET_ITEM(pArgs, 1, PyUnicode_FromString(k->second.m_action.c_str()));
Py_INCREF(c->second.m_fnc);
call_list.push_back(call_entry(c->second.m_fnc, pArgs));
}
Expand Down
2 changes: 1 addition & 1 deletion lib/base/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ eConsoleAppContainer::eConsoleAppContainer():

int eConsoleAppContainer::setCWD( const char *path )
{
struct stat dir_stat;
struct stat dir_stat = {};

if (stat(path, &dir_stat) == -1)
return -1;
Expand Down
6 changes: 3 additions & 3 deletions lib/base/ebase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ int eMainloop::processOneEvent(long user_timeout, PyObject **res, ePyObject addi
{
eTimer *tmr = *it;
/* get current time */
timespec now;
timespec now = {};
clock_gettime(CLOCK_MONOTONIC, &now);
/* process all timers which are ready. first remove them out of the list. */
while (tmr->needsActivation(now))
Expand Down Expand Up @@ -223,7 +223,7 @@ int eMainloop::processOneEvent(long user_timeout, PyObject **res, ePyObject addi
fdcount += PyDict_Size(additional);

// build the poll aray
pollfd pfd[fdcount]; // make new pollfd array
pollfd pfd[fdcount] = {}; // make new pollfd array
std::map<int,eSocketNotifier*>::iterator it = notifiers.begin();

int i=0;
Expand Down Expand Up @@ -335,7 +335,7 @@ int eMainloop::iterate(unsigned int twisted_timeout, PyObject **res, ePyObject d
int to = -1;
if (twisted_timeout)
{
timespec now, timeout;
timespec now = {}, timeout = {};
clock_gettime(CLOCK_MONOTONIC, &now);
if (m_twisted_timer<=now) // timeout
return 0;
Expand Down
14 changes: 7 additions & 7 deletions lib/base/ebase.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static inline timespec &operator+=( timespec &t1, const timespec &t2 )

static inline timespec operator+( const timespec &t1, const timespec &t2 )
{
timespec tmp;
timespec tmp = {};
tmp.tv_sec = t1.tv_sec + t2.tv_sec;
if ( (tmp.tv_nsec = t1.tv_nsec + t2.tv_nsec) >= 1000000000 )
{
Expand All @@ -58,7 +58,7 @@ static inline timespec operator+( const timespec &t1, const timespec &t2 )

static inline timespec operator-( const timespec &t1, const timespec &t2 )
{
timespec tmp;
timespec tmp = {};
tmp.tv_sec = t1.tv_sec - t2.tv_sec;
if ( (tmp.tv_nsec = t1.tv_nsec - t2.tv_nsec) < 0 )
{
Expand Down Expand Up @@ -92,7 +92,7 @@ static inline timespec &operator+=( timespec &t1, const long msek )

static inline timespec operator+( const timespec &t1, const long msek )
{
timespec tmp;
timespec tmp = {};
tmp.tv_sec = t1.tv_sec + msek / 1000;
if ( (tmp.tv_nsec = t1.tv_nsec + (msek % 1000) * 1000000) >= 1000000000 )
{
Expand All @@ -104,7 +104,7 @@ static inline timespec operator+( const timespec &t1, const long msek )

static inline timespec operator-( const timespec &t1, const long msek )
{
timespec tmp;
timespec tmp = {};
tmp.tv_sec = t1.tv_sec - msek / 1000;
if ( (tmp.tv_nsec = t1.tv_nsec - (msek % 1000)*1000000) < 0 )
{
Expand All @@ -127,7 +127,7 @@ static inline timespec operator-=( timespec &t1, const long msek )

static inline long timeout_usec ( const timespec & orig )
{
timespec now, diff;
timespec now = {}, diff = {};
clock_gettime(CLOCK_MONOTONIC, &now);
diff = orig - now;
if (diff.tv_sec > 2000)
Expand Down Expand Up @@ -194,7 +194,7 @@ class eMainloop
int retval;
eSocketNotifier *m_inActivate;
int m_interrupt_requested;
timespec m_twisted_timer;
timespec m_twisted_timer = {};

/* user_timeout < 0 - forever
* user_timeout = 0 - immediately
Expand Down Expand Up @@ -279,7 +279,7 @@ class eTimer: iObject
friend class eMainloop;

eMainloop &context;
timespec nextActivation;
timespec nextActivation = {};
long interval;
bool bSingleShot;
bool bActive;
Expand Down
6 changes: 3 additions & 3 deletions lib/base/eerror.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ int formatTime(char *buf, int bufferSize, int flags)
{
if (debugTime & 6)
{
struct tm loctime;
struct timeval tim;
struct tm loctime = {};
struct timeval tim = {};
gettimeofday(&tim, NULL);
localtime_r(&tim.tv_sec, &loctime);
if (debugTime & 4)
Expand All @@ -159,7 +159,7 @@ int formatTime(char *buf, int bufferSize, int flags)
}
if (debugTime & 1)
{
struct timespec tp;
struct timespec tp = {};
clock_gettime(CLOCK_MONOTONIC, &tp);
// Cast to (long long) is to cater for older 32-bit time fields
pos += snprintf(buf + pos, bufferSize - pos, "<%6lld.%06lld> ", (long long)tp.tv_sec, (long long)tp.tv_nsec / 1000);
Expand Down
2 changes: 1 addition & 1 deletion lib/base/esimpleconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace eSimpleConfig
{
std::string file = eEnv::resolve("${sysconfdir}/enigma2/settings");

struct stat settings_stat;
struct stat settings_stat = {};
if (stat(file.c_str(), &settings_stat) == -1 || settings_stat.st_mtime <= lastModified)
return;

Expand Down
2 changes: 1 addition & 1 deletion lib/base/etpm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

eTPM::eTPM()
{
struct sockaddr_un addr;
struct sockaddr_un addr = {};
unsigned char buf[8];
unsigned int tag;
size_t len;
Expand Down
2 changes: 1 addition & 1 deletion lib/base/internetcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ int checkLinkStatus()
}

int sock;
struct ifreq ifr;
struct ifreq ifr = {};
// Create a socket
sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock < 0)
Expand Down
2 changes: 1 addition & 1 deletion lib/base/rawfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ off_t eRawFile::length()
}
else
{
struct stat st;
struct stat st = {};
if (::fstat(m_fd, &st) < 0)
return -1;
return st.st_size;
Expand Down
2 changes: 1 addition & 1 deletion lib/base/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ int eThread::runAsync(int prio, int policy)

if (prio || policy)
{
struct sched_param p;
struct sched_param p = {};
p.__sched_priority=prio;
pthread_attr_setschedpolicy(&attr, policy);
pthread_attr_setschedparam(&attr, &p);
Expand Down
10 changes: 5 additions & 5 deletions lib/base/wrappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ int Select(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, stru
{
int retval;
fd_set rset, wset, xset;
timeval interval;
timeval interval = {};

/* make a backup of all fd_set's and timeval struct */
if (readfds) rset = *readfds;
Expand Down Expand Up @@ -64,7 +64,7 @@ ssize_t singleRead(int fd, void *buf, size_t count)
if (retval < 0)
{
if (errno == EINTR) continue;
eDebug("[singleRead] error: %m");
eDebug("[singleRead] error: %d (%m)", errno);
}
return retval;
}
Expand All @@ -73,7 +73,7 @@ ssize_t singleRead(int fd, void *buf, size_t count)
ssize_t timedRead(int fd, void *buf, size_t count, int initialtimeout, int interbytetimeout)
{
fd_set rset;
struct timeval timeout;
struct timeval timeout = {};
int result;
size_t totalread = 0;

Expand Down Expand Up @@ -132,7 +132,7 @@ int Connect(const char *hostname, int port, int timeoutsec)
int sd = -1;
std::vector<struct addrinfo *> addresses;
struct addrinfo *info = NULL;
struct addrinfo hints;
struct addrinfo hints = {};
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC; /* both ipv4 and ipv6 */
hints.ai_socktype = SOCK_STREAM;
Expand Down Expand Up @@ -188,7 +188,7 @@ int Connect(const char *hostname, int port, int timeoutsec)
{
int error;
socklen_t len = sizeof(error);
timeval timeout;
timeval timeout = {};
fd_set wset;
FD_ZERO(&wset);
FD_SET(sd, &wset);
Expand Down
2 changes: 1 addition & 1 deletion lib/components/file_eraser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void eBackgroundFileEraser::gotMessage(const Message &msg )
if ((((erase_flags & ERASE_FLAG_HDD) != 0) && (strncmp(c_filename, "/media/hdd/", 11) == 0)) ||
((erase_flags & ERASE_FLAG_OTHER) != 0))
{
struct stat st;
struct stat st = {}
int i = ::stat(c_filename, &st);
// truncate only if the file exists and does not have any hard links
if ((i == 0) && (st.st_nlink == 1))
Expand Down
2 changes: 1 addition & 1 deletion lib/driver/avcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ eAVControl *eAVControl::m_instance = nullptr;

eAVControl::eAVControl()
{
struct stat buffer;
struct stat buffer = {};

#ifdef HAVE_HDMIIN_DM
m_b_has_proc_hdmi_rx_monitor = (stat(proc_hdmi_rx_monitor, &buffer) == 0);
Expand Down
12 changes: 6 additions & 6 deletions lib/driver/hdmi_cec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ eHdmiCEC *eHdmiCEC::getInstance()

void eHdmiCEC::reportPhysicalAddress()
{
struct cec_message txmessage;
struct cec_message txmessage = {};
memset(&txmessage, 0, sizeof(txmessage));
txmessage.address = 0x0f; /* broadcast */
txmessage.data[0] = 0x84; /* report address */
Expand All @@ -192,7 +192,7 @@ void eHdmiCEC::getAddressInfo()
if (hdmiFd >= 0)
{
bool hasdata = false;
struct addressinfo addressinfo;
struct addressinfo addressinfo = {};

if (linuxCEC)
{
Expand Down Expand Up @@ -330,7 +330,7 @@ void eHdmiCEC::hdmiEvent(int what)
{
if (linuxCEC)
{
struct cec_event cecevent;
struct cec_event cecevent = {};
::ioctl(hdmiFd, CEC_DQEVENT, &cecevent);
if (cecevent.event == CEC_EVENT_STATE_CHANGE)
{
Expand All @@ -343,10 +343,10 @@ void eHdmiCEC::hdmiEvent(int what)
if (what & eSocketNotifier::Read)
{
bool hasdata = false;
struct cec_rx_message rxmessage;
struct cec_rx_message rxmessage = {};
if (linuxCEC)
{
struct cec_msg msg;
struct cec_msg msg = {};
if (::ioctl(hdmiFd, CEC_RECEIVE, &msg) >= 0)
{
rxmessage.length = msg.len - 1;
Expand Down Expand Up @@ -565,7 +565,7 @@ void eHdmiCEC::sendMessage(struct cec_message &message)

void eHdmiCEC::sendMessage(unsigned char address, unsigned char cmd, char *data, int length)
{
struct cec_message message;
struct cec_message message = {};
message.address = address;
if (length > (int)(sizeof(message.data) - 1)) length = sizeof(message.data) - 1;
message.length = length + 1;
Expand Down
2 changes: 1 addition & 1 deletion lib/driver/rc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ eRCShortDriver::~eRCShortDriver()

void eRCInputEventDriver::keyPressed(int)
{
struct input_event ev;
struct input_event ev = {};
while (1)
{
if (read(handle, &ev, sizeof(struct input_event))!=sizeof(struct input_event))
Expand Down
2 changes: 1 addition & 1 deletion lib/driver/rcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ eRCConsoleDriver::eRCConsoleDriver(const char *filename): eRCDriver(eRCInput::ge
if (handle >= 0)
{
/* set console mode */
struct termios t;
struct termios t = {};
tcgetattr(handle, &t);
ot = t;
t.c_lflag &= ~(ECHO | ICANON | ECHOK | ECHOE | ECHONL);
Expand Down
2 changes: 1 addition & 1 deletion lib/driver/rcdreambox2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class eRCDeviceDreambox2Init
eRCDeviceDreambox2Init()
: m_driver(NULL), m_device(NULL), m_buttondriver(NULL), m_buttondevice(NULL)
{
struct stat s;
struct stat s = {};
if (::access("/dev/rawir2", R_OK) >= 0)
{
m_driver = new eRCShortDriver("/dev/rawir2");
Expand Down
2 changes: 1 addition & 1 deletion lib/driver/rcinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void eRCDeviceInputDev::handleCode(long rccode)
{
if (consoleFd >= 0)
{
struct kbentry ke;
struct kbentry ke = {};
/* off course caps is not the same as shift, but this will have to do for now */
ke.kb_table = (shiftState || capsState) ? K_SHIFTTAB : K_NORMTAB;
ke.kb_index = ev->code;
Expand Down
Loading

0 comments on commit 717ec7c

Please sign in to comment.