Skip to content

Commit

Permalink
Resolve [-Wzero-as-null-pointer-constant]
Browse files Browse the repository at this point in the history
  • Loading branch information
get committed Mar 30, 2023
1 parent 8ee9249 commit 1702935
Show file tree
Hide file tree
Showing 22 changed files with 96 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Externals/cpp-optparse/OptionParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Values {
class Option {
public:
Option(const OptionParser& p) :
_parser(p), _action("store"), _type("string"), _nargs(1), _callback(0) {}
_parser(p), _action("store"), _type("string"), _nargs(1), _callback(nullptr) {}
virtual ~Option() {}

Option& action(const std::string& a);
Expand Down
2 changes: 1 addition & 1 deletion Externals/picojson/picojson.h
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ template <typename Iter> inline std::string parse(value &out, Iter &pos, const I

template <typename Context, typename Iter> inline Iter _parse(Context &ctx, const Iter &first, const Iter &last, std::string *err) {
input<Iter> in(first, last);
if (!_parse(ctx, in) && err != NULL) {
if (!_parse(ctx, in) && err != nullptr) {
char buf[64];
SNPRINTF(buf, sizeof(buf), "syntax error at line %d near: ", in.line());
*err = buf;
Expand Down
2 changes: 1 addition & 1 deletion Source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ else()
#check_and_add_flag(SWITCH_DEFAULT -Wswitch-default)
#check_and_add_flag(FLOAT_EQUAL -Wfloat-equal)
#check_and_add_flag(CONVERSION -Wconversion)
#check_and_add_flag(ZERO_AS_NULL_POINTER_CONSTANT -Wzero-as-null-pointer-constant)
check_and_add_flag(ZERO_AS_NULL_POINTER_CONSTANT -Wzero-as-null-pointer-constant)
check_and_add_flag(TYPE_LIMITS -Wtype-limits)
check_and_add_flag(SIGN_COMPARE -Wsign-compare)
check_and_add_flag(IGNORED_QUALIFIERS -Wignored-qualifiers)
Expand Down
16 changes: 16 additions & 0 deletions Source/Core/Common/FatFsUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,15 @@ bool SyncSDFolderToSDImage(const std::function<bool()>& cancelled, bool determin
FatFsErrorToString(mount_error_code));
return false;
}

#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
#endif
Common::ScopeGuard unmount_guard{[] { f_unmount(""); }};
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif

if (!Pack(cancelled, root, true, tmp_buffer))
{
Expand Down Expand Up @@ -795,7 +803,15 @@ bool SyncSDImageToSDFolder(const std::function<bool()>& cancelled)
FatFsErrorToString(mount_error_code));
return false;
}

#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
#endif
Common::ScopeGuard unmount_guard{[] { f_unmount(""); }};
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif

// Unpack() and GetTempFilenameForAtomicWrite() don't want the trailing separator.
const std::string target_dir_without_slash = target_dir.substr(0, target_dir.length() - 1);
Expand Down
6 changes: 4 additions & 2 deletions Source/Core/Common/GL/GLInterface/GLX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ bool GLContextGLX::Initialize(const WindowSystemInfo& wsi, bool stereo, bool cor
GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, None}};

s_glxError = false;
m_context = glXCreateContextAttribs(m_display, m_fbconfig, 0, True, &context_attribs[0]);
m_context =
glXCreateContextAttribs(m_display, m_fbconfig, nullptr, True, &context_attribs[0]);
XSync(m_display, False);
if (!m_context || s_glxError)
continue;
Expand All @@ -174,7 +175,8 @@ bool GLContextGLX::Initialize(const WindowSystemInfo& wsi, bool stereo, bool cor
std::array<int, 5> context_attribs_legacy = {
{GLX_CONTEXT_MAJOR_VERSION_ARB, 1, GLX_CONTEXT_MINOR_VERSION_ARB, 0, None}};
s_glxError = false;
m_context = glXCreateContextAttribs(m_display, m_fbconfig, 0, True, &context_attribs_legacy[0]);
m_context =
glXCreateContextAttribs(m_display, m_fbconfig, nullptr, True, &context_attribs_legacy[0]);
XSync(m_display, False);
m_attribs.clear();
m_attribs.insert(m_attribs.end(), context_attribs_legacy.begin(), context_attribs_legacy.end());
Expand Down
7 changes: 7 additions & 0 deletions Source/Core/Core/IOS/Network/KD/VFF/VFFUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,14 @@ ErrorCode OpenVFF(const std::string& path, const std::string& filename,
return;
}

#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
#endif
Common::ScopeGuard unmount_guard{[] { f_unmount(""); }};
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif

const auto write_error_code = WriteFile(filename, data);
if (write_error_code != WC24_OK)
Expand Down
7 changes: 7 additions & 0 deletions Source/Core/Core/IOS/USB/Bluetooth/BTReal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@
#include <vector>

#include <fmt/format.h>
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
#endif
#include <libusb.h>
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif

#include "Common/ChunkFile.h"
#include "Common/Logging/Log.h"
Expand Down
7 changes: 7 additions & 0 deletions Source/Core/Core/IOS/USB/Host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@
#include <utility>

#ifdef __LIBUSB__
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
#endif
#include <libusb.h>
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#endif

#include "Common/Assert.h"
Expand Down
7 changes: 7 additions & 0 deletions Source/Core/Core/IOS/USB/LibusbDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@
#include <utility>
#include <vector>

#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
#endif
#include <libusb.h>
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif

#include "Common/Assert.h"
#include "Common/Logging/Log.h"
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/IOS/USB/USB_HID/HIDv4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ std::optional<IPCReply> USB_HIDv4::GetDeviceChange(const IOCtlRequest& request)
IPCReply USB_HIDv4::Shutdown(const IOCtlRequest& request)
{
std::lock_guard lk{m_devicechange_hook_address_mutex};
if (m_devicechange_hook_request != 0)
if (m_devicechange_hook_request)
{
auto& system = Core::System::GetInstance();
auto& memory = system.GetMemory();
Expand Down
7 changes: 7 additions & 0 deletions Source/Core/Core/LibusbUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@
#include <thread>

#if defined(__LIBUSB__)
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
#endif
#include <libusb.h>
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#endif

#include "Common/Assert.h"
Expand Down
7 changes: 7 additions & 0 deletions Source/Core/Core/PowerPC/Expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@
#include <string_view>
#include <utility>

#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
#endif
#include <expr.h>
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif

#include "Common/BitUtils.h"
#include "Common/CommonTypes.h"
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/PowerPC/GDBStub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,7 @@ void InitLocal(const char* socket)
addr.sun_family = AF_UNIX;
strcpy(addr.sun_path, socket);

InitGeneric(PF_LOCAL, (const sockaddr*)&addr, sizeof(addr), NULL, NULL);
InitGeneric(PF_LOCAL, (const sockaddr*)&addr, sizeof(addr), nullptr, nullptr);
}
#endif

Expand Down
4 changes: 2 additions & 2 deletions Source/Core/DolphinQt/QtUtils/FlowLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ QLayoutItem* FlowLayout::takeAt(int index)
if (index >= 0 && index < m_item_list.size())
return m_item_list.takeAt(index);
else
return 0;
return nullptr;
}

Qt::Orientations FlowLayout::expandingDirections() const
Expand Down Expand Up @@ -167,7 +167,7 @@ int FlowLayout::smartSpacing(QStyle::PixelMetric pm) const
else if (parent->isWidgetType())
{
QWidget* pw = static_cast<QWidget*>(parent);
return pw->style()->pixelMetric(pm, 0, pw);
return pw->style()->pixelMetric(pm, nullptr, pw);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/DolphinQt/Settings/GameCubePane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ void GameCubePane::BrowseMemcard(ExpansionInterface::Slot slot)
const QString filename = DolphinFileDialog::getSaveFileName(
this, tr("Choose a file to open or create"),
QString::fromStdString(File::GetUserPath(D_GCUSER_IDX)),
tr("GameCube Memory Cards (*.raw *.gcp)"), 0, QFileDialog::DontConfirmOverwrite);
tr("GameCube Memory Cards (*.raw *.gcp)"), nullptr, QFileDialog::DontConfirmOverwrite);

if (!filename.isEmpty())
SetMemcard(slot, filename);
Expand Down Expand Up @@ -618,7 +618,7 @@ void GameCubePane::BrowseAGPRom(ExpansionInterface::Slot slot)

QString filename = DolphinFileDialog::getSaveFileName(
this, tr("Choose a file to open"), QString::fromStdString(File::GetUserPath(D_GCUSER_IDX)),
tr("Game Boy Advance Carts (*.gba)"), 0, QFileDialog::DontConfirmOverwrite);
tr("Game Boy Advance Carts (*.gba)"), nullptr, QFileDialog::DontConfirmOverwrite);

if (!filename.isEmpty())
SetAGPRom(slot, filename);
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/DolphinQt/ToolBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,14 @@ void ToolBar::UpdatePausePlayButtonState(const bool playing_state)
{
if (playing_state)
{
disconnect(m_pause_play_action, 0, 0, 0);
disconnect(m_pause_play_action, nullptr, nullptr, nullptr);
m_pause_play_action->setText(tr("Pause"));
m_pause_play_action->setIcon(Resources::GetScaledThemeIcon("pause"));
connect(m_pause_play_action, &QAction::triggered, this, &ToolBar::PausePressed);
}
else
{
disconnect(m_pause_play_action, 0, 0, 0);
disconnect(m_pause_play_action, nullptr, nullptr, nullptr);
m_pause_play_action->setText(tr("Play"));
m_pause_play_action->setIcon(Resources::GetScaledThemeIcon("play"));
connect(m_pause_play_action, &QAction::triggered, this, &ToolBar::PlayPressed);
Expand Down
7 changes: 7 additions & 0 deletions Source/Core/InputCommon/GCAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@
#include <optional>

#if GCADAPTER_USE_LIBUSB_IMPLEMENTATION
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
#endif
#include <libusb.h>
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#elif GCADAPTER_USE_ANDROID_IMPLEMENTATION
#include <jni.h>
#endif
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/UICommon/Disassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ HostDisassemblerLLVM::HostDisassemblerLLVM(const std::string& host_disasm, int i
LLVMInitializeAllTargetMCs();
LLVMInitializeAllDisassemblers();

m_llvm_context = LLVMCreateDisasmCPU(host_disasm.c_str(), cpu.c_str(), nullptr, 0, 0, nullptr);
m_llvm_context = LLVMCreateDisasmCPU(host_disasm.c_str(), cpu.c_str(), nullptr, 0, nullptr, nullptr);

// Couldn't create llvm context
if (!m_llvm_context)
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/UICommon/ResourcePack/ResourcePack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ ResourcePack::ResourcePack(const std::string& path) : m_path(path)
return;
}

if (unzLocateFile(file, "manifest.json", 0) == UNZ_END_OF_LIST_OF_FILE)
if (unzLocateFile(file, "manifest.json", nullptr) == UNZ_END_OF_LIST_OF_FILE)
{
m_valid = false;
m_error = "Resource pack is missing a manifest.";
Expand All @@ -63,7 +63,7 @@ ResourcePack::ResourcePack(const std::string& path) : m_path(path)
return;
}

if (unzLocateFile(file, "logo.png", 0) != UNZ_END_OF_LIST_OF_FILE)
if (unzLocateFile(file, "logo.png", nullptr) != UNZ_END_OF_LIST_OF_FILE)
{
unz_file_info64 logo_info{};
unzGetCurrentFileInfo64(file, &logo_info, nullptr, 0, nullptr, 0, nullptr, 0);
Expand Down
7 changes: 7 additions & 0 deletions Source/Core/UICommon/USBUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@

#include <fmt/format.h>
#ifdef __LIBUSB__
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
#endif
#include <libusb.h>
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#endif

#include "Common/CommonTypes.h"
Expand Down
10 changes: 5 additions & 5 deletions Source/Core/VideoBackends/OGL/OGLTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ OGLStagingTexture::OGLStagingTexture(StagingTextureType type, const TextureConfi

OGLStagingTexture::~OGLStagingTexture()
{
if (m_fence != 0)
if (m_fence != nullptr)
glDeleteSync(m_fence);
if (m_map_pointer)
{
Expand Down Expand Up @@ -418,7 +418,7 @@ void OGLStagingTexture::CopyFromTexture(const AbstractTexture* src,
// If we support buffer storage, create a fence for synchronization.
if (UsePersistentStagingBuffers())
{
if (m_fence != 0)
if (m_fence != nullptr)
glDeleteSync(m_fence);

glMemoryBarrier(GL_CLIENT_MAPPED_BUFFER_BARRIER_BIT);
Expand Down Expand Up @@ -479,7 +479,7 @@ void OGLStagingTexture::CopyToTexture(const MathUtil::Rectangle<int>& src_rect,
// If we support buffer storage, create a fence for synchronization.
if (UsePersistentStagingBuffers())
{
if (m_fence != 0)
if (m_fence != nullptr)
glDeleteSync(m_fence);

m_fence = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
Expand All @@ -493,15 +493,15 @@ void OGLStagingTexture::Flush()
{
// No-op when not using buffer storage, as the transfers happen on Map().
// m_fence will always be zero in this case.
if (m_fence == 0)
if (m_fence == nullptr)
{
m_needs_flush = false;
return;
}

glClientWaitSync(m_fence, 0, GL_TIMEOUT_IGNORED);
glDeleteSync(m_fence);
m_fence = 0;
m_fence = nullptr;
m_needs_flush = false;
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/OGL/OGLTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class OGLStagingTexture final : public AbstractStagingTexture
GLenum m_target;
GLuint m_buffer_name;
size_t m_buffer_size;
GLsync m_fence = 0;
GLsync m_fence = nullptr;
};

class OGLFramebuffer final : public AbstractFramebuffer
Expand Down

0 comments on commit 1702935

Please sign in to comment.