refactor: use std::size to get size of arrays
This commit is contained in:
parent
6bf25c0089
commit
d1b810baa5
6 changed files with 11 additions and 10 deletions
|
|
@ -106,7 +106,8 @@ std::string sprintf(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
char tmp[1024];
|
char tmp[1024];
|
||||||
char *buffer = tmp;
|
char *buffer = tmp;
|
||||||
auto len = (int)(sizeof(tmp) / sizeof(tmp[0]));
|
auto len = static_cast<int>(std::size(tmp));
|
||||||
|
|
||||||
std::string result;
|
std::string result;
|
||||||
while (buffer != nullptr) {
|
while (buffer != nullptr) {
|
||||||
// try printing into the buffer
|
// try printing into the buffer
|
||||||
|
|
|
||||||
|
|
@ -1028,7 +1028,7 @@ void KeyState::addKeypadEntries()
|
||||||
// map every numpad key to its equivalent non-numpad key if it's not
|
// map every numpad key to its equivalent non-numpad key if it's not
|
||||||
// on the keyboard.
|
// on the keyboard.
|
||||||
for (int32_t g = 0, n = m_keyMap.getNumGroups(); g < n; ++g) {
|
for (int32_t g = 0, n = m_keyMap.getNumGroups(); g < n; ++g) {
|
||||||
for (size_t i = 0; i < sizeof(s_numpadTable) / sizeof(s_numpadTable[0]); i += 2) {
|
for (size_t i = 0; i < std::size(s_numpadTable); i += 2) {
|
||||||
m_keyMap.addKeyCombinationEntry(s_numpadTable[i], g, s_numpadTable + i + 1, 1);
|
m_keyMap.addKeyCombinationEntry(s_numpadTable[i], g, s_numpadTable + i + 1, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -249,8 +249,7 @@ QTextStream &operator<<(QTextStream &outStream, const ServerConfig &config)
|
||||||
for (int i = 0; i < config.screens().size(); i++) {
|
for (int i = 0; i < config.screens().size(); i++) {
|
||||||
if (!config.screens()[i].isNull()) {
|
if (!config.screens()[i].isNull()) {
|
||||||
outStream << "\t" << config.screens()[i].name() << ":" << Qt::endl;
|
outStream << "\t" << config.screens()[i].name() << ":" << Qt::endl;
|
||||||
|
for (unsigned int j = 0; j < std::size(neighbourDirs); j++) {
|
||||||
for (unsigned int j = 0; j < sizeof(neighbourDirs) / sizeof(neighbourDirs[0]); j++) {
|
|
||||||
int idx = config.adjacentScreenIndex(i, neighbourDirs[j].x, neighbourDirs[j].y);
|
int idx = config.adjacentScreenIndex(i, neighbourDirs[j].x, neighbourDirs[j].y);
|
||||||
if (idx != -1 && !config.screens()[idx].isNull())
|
if (idx != -1 && !config.screens()[idx].isNull())
|
||||||
outStream << "\t\t" << neighbourDirs[j].name << " = " << config.screens()[idx].name() << Qt::endl;
|
outStream << "\t\t" << neighbourDirs[j].name << " = " << config.screens()[idx].name() << Qt::endl;
|
||||||
|
|
|
||||||
|
|
@ -113,12 +113,13 @@ TCPSocket::JobResult SecureSocket::doRead()
|
||||||
{
|
{
|
||||||
using enum JobResult;
|
using enum JobResult;
|
||||||
static uint8_t buffer[4096];
|
static uint8_t buffer[4096];
|
||||||
memset(buffer, 0, sizeof(buffer));
|
static const auto bufferSize = std::size(buffer);
|
||||||
|
memset(buffer, 0, bufferSize);
|
||||||
int bytesRead = 0;
|
int bytesRead = 0;
|
||||||
int status = 0;
|
int status = 0;
|
||||||
|
|
||||||
if (isSecureReady()) {
|
if (isSecureReady()) {
|
||||||
status = secureRead(buffer, sizeof(buffer), bytesRead);
|
status = secureRead(buffer, bufferSize, bytesRead);
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
return Break;
|
return Break;
|
||||||
} else if (status == 0) {
|
} else if (status == 0) {
|
||||||
|
|
@ -139,7 +140,7 @@ TCPSocket::JobResult SecureSocket::doRead()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = secureRead(buffer, sizeof(buffer), bytesRead);
|
status = secureRead(buffer, bufferSize, bytesRead);
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
return Break;
|
return Break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -556,7 +556,7 @@ uint32_t XWindowsScreen::registerHotKey(KeyID key, KeyModifierMask mask)
|
||||||
};
|
};
|
||||||
|
|
||||||
XModifierKeymap *modKeymap = XGetModifierMapping(m_display);
|
XModifierKeymap *modKeymap = XGetModifierMapping(m_display);
|
||||||
for (size_t j = 0; j < sizeof(s_hotKeyModifiers) / sizeof(s_hotKeyModifiers[0]) && !err; ++j) {
|
for (size_t j = 0; j < std::size(s_hotKeyModifiers) && !err; ++j) {
|
||||||
// skip modifier if not in mask
|
// skip modifier if not in mask
|
||||||
if ((mask & s_hotKeyModifiers[j]) == 0) {
|
if ((mask & s_hotKeyModifiers[j]) == 0) {
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -1728,7 +1728,7 @@ KeyID XWindowsScreen::mapKeyFromX(XKeyEvent *event) const
|
||||||
// do multibyte lookup. can only call XmbLookupString with a
|
// do multibyte lookup. can only call XmbLookupString with a
|
||||||
// key press event and a valid XIC so we checked those above.
|
// key press event and a valid XIC so we checked those above.
|
||||||
char scratch[32];
|
char scratch[32];
|
||||||
int n = sizeof(scratch) / sizeof(scratch[0]);
|
auto n = static_cast<int>(std::size(scratch));
|
||||||
char *buffer = scratch;
|
char *buffer = scratch;
|
||||||
int status;
|
int status;
|
||||||
n = XmbLookupString(m_ic, event, buffer, n, &keysym, &status);
|
n = XmbLookupString(m_ic, event, buffer, n, &keysym, &status);
|
||||||
|
|
|
||||||
|
|
@ -1885,7 +1885,7 @@ Bool XWindowsUtil::propertyNotifyPredicate(Display *, XEvent *xevent, XPointer a
|
||||||
void XWindowsUtil::initKeyMaps()
|
void XWindowsUtil::initKeyMaps()
|
||||||
{
|
{
|
||||||
if (s_keySymToUCS4.empty()) {
|
if (s_keySymToUCS4.empty()) {
|
||||||
for (size_t i = 0; i < sizeof(s_keymap) / sizeof(s_keymap[0]); ++i) {
|
for (size_t i = 0; i < std::size(s_keymap); ++i) {
|
||||||
s_keySymToUCS4[s_keymap[i].keysym] = s_keymap[i].ucs4;
|
s_keySymToUCS4[s_keymap[i].keysym] = s_keymap[i].ucs4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue