Tidy up the source code

* Replaced push_back calls with emplace_back where applicable.
* Replaced size() == 0 and size() != 0 with empty() and !empty().
* Replaced C style loops for range for loops where applicable.
* Fixed mismatching arg names between function declarations and definitions.
* Replaced NULL and 0 (in the context of pointers) with nullptr.
* Remove unnecessary calls to string::c_str() where applicable.
* Replaced deprecated C headers with proper C++ headers.
* Removed unnecessary null pointer checks when deleting pointers
(deleting a null pointer has no effect).
* Fixed a potential memory leak in apngloader.cpp file.
* Replaced unsafe strcpy with strncpy in the demangle_name function.
This commit is contained in:
Kamil Chojnowski
2019-10-10 00:21:26 +02:00
parent caae18dbce
commit 869de6886f
59 changed files with 202 additions and 199 deletions

View File

@@ -150,8 +150,8 @@ void PlatformWindow::releaseAllKeys()
m_inputEvent.keyboardModifiers = 0;
for(int i=0;i<4;++i)
m_mouseButtonStates[i] = false;
for(auto &mouseButtonState: m_mouseButtonStates)
mouseButtonState = false;
}
void PlatformWindow::fireKeysPress()

View File

@@ -30,9 +30,9 @@
#define __USE_GNU
#endif
#include <csignal>
#include <execinfo.h>
#include <ucontext.h>
#include <signal.h>
#define MAX_BACKTRACE_DEPTH 128
#define DEMANGLE_BACKTRACE_SYMBOLS
@@ -129,10 +129,10 @@ void installCrashHandler()
sigemptyset (&sa.sa_mask);
sa.sa_flags = SA_RESTART | SA_SIGINFO;
sigaction(SIGILL, &sa, NULL); // illegal instruction
sigaction(SIGSEGV, &sa, NULL); // segmentation fault
sigaction(SIGFPE, &sa, NULL); // floating-point exception
sigaction(SIGABRT, &sa, NULL); // process aborted (asserts)
sigaction(SIGILL, &sa, nullptr); // illegal instruction
sigaction(SIGSEGV, &sa, nullptr); // segmentation fault
sigaction(SIGFPE, &sa, nullptr); // floating-point exception
sigaction(SIGABRT, &sa, nullptr); // process aborted (asserts)
}
#endif

View File

@@ -23,9 +23,9 @@
#ifndef WIN32
#include "platform.h"
#include <cstring>
#include <fstream>
#include <unistd.h>
#include <string.h>
#include <framework/stdext/stdext.h>
#include <sys/stat.h>
@@ -51,7 +51,7 @@ bool Platform::spawnProcess(std::string process, const std::vector<std::string>&
cargs[0] = (char*)process.c_str();
for(uint i=1;i<=args.size();++i)
cargs[i] = (char*)args[i-1].c_str();
cargs[args.size()+1] = 0;
cargs[args.size()+1] = nullptr;
if(execv(process.c_str(), cargs) == -1)
_exit(EXIT_FAILURE);
@@ -84,7 +84,7 @@ std::string Platform::getCurrentDir()
{
std::string res;
char cwd[2048];
if(getcwd(cwd, sizeof(cwd)) != NULL) {
if(getcwd(cwd, sizeof(cwd)) != nullptr) {
res = cwd;
res += "/";
}

View File

@@ -31,15 +31,15 @@
X11Window::X11Window()
{
m_display = 0;
m_visual = 0;
m_display = nullptr;
m_visual = nullptr;
m_window = 0;
m_rootWindow = 0;
m_colormap = 0;
m_cursor = 0;
m_hiddenCursor = 0;
m_xim = 0;
m_xic = 0;
m_xim = nullptr;
m_xic = nullptr;
m_screen = 0;
m_wmDelete = 0;
m_minimumSize = Size(600,480);
@@ -51,8 +51,8 @@ X11Window::X11Window()
m_eglDisplay = 0;
m_eglSurface = 0;
#else
m_fbConfig = 0;
m_glxContext = 0;
m_fbConfig = nullptr;
m_glxContext = nullptr;
#endif
m_keyMap[XK_Escape] = Fw::KeyEscape;
@@ -247,22 +247,22 @@ void X11Window::terminate()
if(m_visual) {
XFree(m_visual);
m_visual = 0;
m_visual = nullptr;
}
if(m_xic) {
XDestroyIC(m_xic);
m_xic = 0;
m_xic = nullptr;
}
if(m_xim) {
XCloseIM(m_xim);
m_xim = 0;
m_xim = nullptr;
}
if(m_display) {
XCloseDisplay(m_display);
m_display = 0;
m_display = nullptr;
}
m_visible = false;
@@ -270,7 +270,7 @@ void X11Window::terminate()
void X11Window::internalOpenDisplay()
{
m_display = XOpenDisplay(NULL);
m_display = XOpenDisplay(nullptr);
if(!m_display)
g_logger.fatal("Unable to open X11 display");
m_screen = DefaultScreen(m_display);
@@ -343,7 +343,7 @@ bool X11Window::internalSetupWindowInput()
}
XSetLocaleModifiers("");
m_xim = XOpenIM(m_display, NULL, NULL, NULL);
m_xim = XOpenIM(m_display, nullptr, nullptr, nullptr);
if(!m_xim) {
g_logger.error("XOpenIM failed");
return false;
@@ -368,7 +368,7 @@ void X11Window::internalCheckGL()
if(!eglInitialize(m_eglDisplay, NULL, NULL))
g_logger.fatal("Unable to initialize EGL");
#else
if(!glXQueryExtension(m_display, NULL, NULL))
if(!glXQueryExtension(m_display, nullptr, nullptr))
g_logger.fatal("GLX not supported");
#endif
}
@@ -450,7 +450,7 @@ void X11Window::internalCreateGLContext()
if(m_eglContext == EGL_NO_CONTEXT )
g_logger.fatal(stdext::format("Unable to create EGL context: %s", eglGetError()));
#else
m_glxContext = glXCreateContext(m_display, m_visual, NULL, True);
m_glxContext = glXCreateContext(m_display, m_visual, nullptr, True);
if(!m_glxContext)
g_logger.fatal("Unable to create GLX context");
@@ -477,9 +477,9 @@ void X11Window::internalDestroyGLContext()
}
#else
if(m_glxContext) {
glXMakeCurrent(m_display, None, NULL);
glXMakeCurrent(m_display, None, nullptr);
glXDestroyContext(m_display, m_glxContext);
m_glxContext = 0;
m_glxContext = nullptr;
}
#endif
}
@@ -606,7 +606,7 @@ void X11Window::poll()
// lookup keysym and translate it
KeySym keysym;
char buf[32];
XLookupString(&xkey, buf, sizeof(buf), &keysym, 0);
XLookupString(&xkey, buf, sizeof(buf), &keysym, nullptr);
Fw::Key keyCode = Fw::KeyUnknown;
if(m_keyMap.find(keysym) != m_keyMap.end())
@@ -651,7 +651,7 @@ void X11Window::poll()
Atom wmStateMaximizedHorz = XInternAtom(m_display, "_NET_WM_STATE_MAXIMIZED_HORZ", False);
Atom actualType;
ulong i, numItems, bytesAfter;
uchar *propertyValue = NULL;
uchar *propertyValue = nullptr;
int actualFormat;
if(XGetWindowProperty(m_display, m_window, wmState,
@@ -740,7 +740,7 @@ void X11Window::poll()
Status status;
len = XmbLookupString(m_xic, &event.xkey, buf, sizeof(buf), &keysym, &status);
} else { // otherwise use XLookupString, but often it doesn't work right with dead keys
static XComposeStatus compose = {NULL, 0};
static XComposeStatus compose = {nullptr, 0};
len = XLookupString(&event.xkey, buf, sizeof(buf), &keysym, &compose);
}
@@ -972,7 +972,7 @@ void X11Window::setVerticalSync(bool enable)
//TODO
#else
typedef GLint (*glSwapIntervalProc)(GLint);
glSwapIntervalProc glSwapInterval = NULL;
glSwapIntervalProc glSwapInterval = nullptr;
if(isExtensionSupported("GLX_MESA_swap_control"))
glSwapInterval = (glSwapIntervalProc)getExtensionProcAddress("glXSwapIntervalMESA");