Use nullptr instead of NULL in the code and documentation

This is a combination of running clang-tidy with modernize-use-nullptr
check for some ports (GTK, X11, OSX) and manual changes to the ports for
which it couldn't be used easily (MSW, DFB) and also manually updating
the docs.

Also replace NULL with null or nullptr in the comments as this is more
consistent with the use of nullptr in the code and makes it simpler to
grep for the remaining occurrences of NULL itself.

And also use null in the assert messages.

Only a few occurrences of "NULL" are still left in non-C files, mostly
corresponding to unclear comments or string output which it might not be
safe to change.
This commit is contained in:
Vadim Zeitlin 2022-10-16 01:24:34 +02:00
parent 39ea524943
commit 4f4c5fcfdf
1844 changed files with 13721 additions and 13734 deletions

View file

@ -32,7 +32,7 @@ wxIMPLEMENT_APP(BombsApp);
// Called to initialize the program
bool BombsApp::OnInit()
{
srand((unsigned) time(NULL));
srand((unsigned) time(nullptr));
m_frame = new BombsFrame(&m_game);
@ -52,7 +52,7 @@ wxBEGIN_EVENT_TABLE(BombsFrame, wxFrame)
wxEND_EVENT_TABLE()
BombsFrame::BombsFrame(BombsGame *game)
: wxFrame(NULL, wxID_ANY, wxT("wxBombs"), wxDefaultPosition,
: wxFrame(nullptr, wxID_ANY, wxT("wxBombs"), wxDefaultPosition,
wxSize(300, 300), wxDEFAULT_DIALOG_STYLE|wxMINIMIZE_BOX)
{
m_game = game;
@ -248,7 +248,7 @@ BombsCanvas::BombsCanvas(wxFrame *parent, BombsGame *game)
m_cellWidth = (sx+3+X_UNIT)/X_UNIT;
m_cellHeight = (sy+3+Y_UNIT)/Y_UNIT;
dc.SetMapMode(wxMM_TEXT);
m_bmp = NULL;
m_bmp = nullptr;
}
BombsCanvas::~BombsCanvas()
@ -256,7 +256,7 @@ BombsCanvas::~BombsCanvas()
if (m_bmp)
{
delete m_bmp;
m_bmp = NULL;
m_bmp = nullptr;
}
}
@ -302,7 +302,7 @@ void BombsCanvas::UpdateGridSize()
if (m_bmp)
{
delete m_bmp;
m_bmp = NULL;
m_bmp = nullptr;
}
SetSize(GetGridSizeInPixels());
Refresh();

View file

@ -26,7 +26,7 @@ public:
BombsGame()
{
m_width = m_height = 0;
m_field = NULL;
m_field = nullptr;
}
~BombsGame();

View file

@ -179,7 +179,7 @@ void Game::DoMove(wxDC& dc, Pile* src, Pile* dest)
if (HaveYouWon())
{
wxWindow *frame = wxTheApp->GetTopWindow();
wxWindow *canvas = (wxWindow *) NULL;
wxWindow *canvas = nullptr;
if (frame)
{

View file

@ -57,7 +57,7 @@ Pile::Pile(int x, int y, int dx, int dy)
//+-------------------------------------------------------------+
//| Description: |
//| Redraw the pile on the screen. If the pile is empty |
//| just draw a NULL card as a place holder for the pile. |
//| just draw a null card as a place holder for the pile. |
//| Otherwise draw the pile from the bottom up, starting |
//| at the origin of the pile, shifting each subsequent |
//| card by the pile's x and y offsets. |
@ -65,7 +65,7 @@ Pile::Pile(int x, int y, int dx, int dy)
void Pile::Redraw(wxDC& dc )
{
FortyFrame *frame = (FortyFrame*) wxTheApp->GetTopWindow();
wxWindow *canvas = (wxWindow *) NULL;
wxWindow *canvas = nullptr;
if (frame)
{
canvas = frame->GetCanvas();
@ -103,7 +103,7 @@ void Pile::Redraw(wxDC& dc )
//| Pile::GetTopCard() |
//+-------------------------------------------------------------+
//| Description: |
//| Return a pointer to the top card in the pile or NULL |
//| Return a pointer to the top card in the pile or nullptr |
//| if the pile is empty. |
//| NB: Gets a copy of the card without removing it from the |
//| pile. |
@ -126,7 +126,7 @@ Card* Pile::GetTopCard()
//| Description: |
//| If the pile is not empty, remove the top card from the |
//| pile and return the pointer to the removed card. |
//| If the pile is empty return a NULL pointer. |
//| If the pile is empty return a null pointer. |
//+-------------------------------------------------------------+
Card* Pile::RemoveTopCard()
{
@ -229,7 +229,7 @@ int Pile::CalcDistance(int x, int y)
// Return the card at x, y. Check the top card first, then
// work down the pile. If a card is found then return a pointer
// to the card, otherwise return NULL
// to the card, otherwise return nullptr
Card* Pile::GetCard(int x, int y)
{
int cardX;

View file

@ -40,12 +40,12 @@ hack doesn't fix.
#include <time.h>
#define Random(x) (rand() % x)
#define Randomize() (srand((unsigned int)time(NULL)))
#define Randomize() (srand((unsigned int)time(nullptr)))
static int detail = 9; // CHANGE THIS... 7,8,9 etc
static bool running = false;
static wxMenuBar *menuBar = NULL;
static wxMenuBar *menuBar = nullptr;
// Define a new application type
class MyApp: public wxApp
@ -89,7 +89,7 @@ private:
bool MyApp::OnInit()
{
// Create the main frame window
MyFrame *frame = new MyFrame(NULL, wxT("Fractal Mountains for wxWidgets"), wxDefaultPosition, wxSize(640, 480));
MyFrame *frame = new MyFrame(nullptr, wxT("Fractal Mountains for wxWidgets"), wxDefaultPosition, wxSize(640, 480));
// Make a menubar
wxMenu *file_menu = new wxMenu;

View file

@ -89,7 +89,7 @@ LifeSamplesDialog::LifeSamplesDialog(wxWindow *parent)
m_list = new wxListBox( this, ID_LISTBOX,
wxDefaultPosition,
listSize,
0, NULL,
0, nullptr,
wxLB_SINGLE | wxLB_NEEDED_SB | wxLB_HSCROLL );
for (unsigned i = 0; i < (sizeof(g_patterns) / sizeof(LifePattern)); i++)

View file

@ -112,10 +112,10 @@ Life::Life()
// pattern data
m_numcells = 0;
m_boxes = new LifeCellBox *[HASHSIZE];
m_head = NULL;
m_available = NULL;
m_head = nullptr;
m_available = nullptr;
for (int i = 0; i < HASHSIZE; i++)
m_boxes[i] = NULL;
m_boxes[i] = nullptr;
// state vars for BeginFind & FindMore
m_cells = new LifeCell[CELLSARRAYSIZE];
@ -141,7 +141,7 @@ void Life::Clear()
// clear the hash table pointers
for (int i = 0; i < HASHSIZE; i++)
m_boxes[i] = NULL;
m_boxes[i] = nullptr;
// free used boxes
c = m_head;
@ -151,7 +151,7 @@ void Life::Clear()
delete c;
c = nc;
}
m_head = NULL;
m_head = nullptr;
// free available boxes
c = m_available;
@ -161,7 +161,7 @@ void Life::Clear()
delete c;
c = nc;
}
m_available = NULL;
m_available = nullptr;
// reset state
m_name = wxEmptyString;
@ -295,7 +295,7 @@ LifeCellBox* Life::CreateBox(wxInt32 x, wxInt32 y, wxUint32 hv)
// LinkBox:
// Returns a pointer to the box (x, y); if it didn't exist yet,
// it returns NULL or creates a new one, depending on the value
// it returns nullptr or creates a new one, depending on the value
// of the 'create' parameter.
//
LifeCellBox* Life::LinkBox(wxInt32 x, wxInt32 y, bool create)
@ -312,7 +312,7 @@ LifeCellBox* Life::LinkBox(wxInt32 x, wxInt32 y, bool create)
if ((c->m_x == x) && (c->m_y == y)) return c;
// if not found, and (create == true), create a new one
return create? CreateBox(x, y, hv) : (LifeCellBox*) NULL;
return create? CreateBox(x, y, hv) : nullptr;
}
// KillBox:
@ -338,10 +338,10 @@ void Life::KillBox(LifeCellBox *c)
// update neighbours
if (c->m_next) c->m_next->m_prev = c->m_prev;
if (c->m_hnext) c->m_hnext->m_hprev = c->m_hprev;
if (c->m_up) c->m_up->m_dn = NULL;
if (c->m_dn) c->m_dn->m_up = NULL;
if (c->m_lf) c->m_lf->m_rt = NULL;
if (c->m_rt) c->m_rt->m_lf = NULL;
if (c->m_up) c->m_up->m_dn = nullptr;
if (c->m_dn) c->m_dn->m_up = nullptr;
if (c->m_lf) c->m_lf->m_rt = nullptr;
if (c->m_rt) c->m_rt->m_lf = nullptr;
// append to the list of available boxes
c->m_next = m_available;
@ -515,7 +515,7 @@ bool Life::FindMore(LifeCell *cells[], size_t *ncells)
for ( ; m_y <= m_y1; m_y += 8, m_x = m_x0)
for ( ; m_x <= m_x1; m_x += 8)
{
if ((c = LinkBox(m_x, m_y, false)) == NULL)
if ((c = LinkBox(m_x, m_y, false)) == nullptr)
continue;
// check whether there is enough space left in the array
@ -540,7 +540,7 @@ bool Life::FindMore(LifeCell *cells[], size_t *ncells)
for ( ; m_y <= m_y1; m_y += 8, m_x = m_x0)
for ( ; m_x <= m_x1; m_x += 8)
{
if ((c = LinkBox(m_x, m_y, false)) == NULL)
if ((c = LinkBox(m_x, m_y, false)) == nullptr)
continue;
// check whether there is enough space left in the array

View file

@ -173,8 +173,8 @@ bool LifeApp::OnInit()
// frame constructor
LifeFrame::LifeFrame() :
wxFrame( (wxFrame *) NULL, wxID_ANY, _("Life!"), wxDefaultPosition ),
m_navigator(NULL)
wxFrame( nullptr, wxID_ANY, _("Life!"), wxDefaultPosition ),
m_navigator(nullptr)
{
// frame icon
SetIcon(wxICON(mondrian));
@ -1104,12 +1104,12 @@ void LifeCanvas::OnScroll(wxScrollWinEvent& event)
if (orient == wxHORIZONTAL)
{
m_viewportX += scrollinc;
ScrollWindow( -m_cellsize * scrollinc, 0, (const wxRect *) NULL);
ScrollWindow( -m_cellsize * scrollinc, 0, nullptr);
}
else
{
m_viewportY += scrollinc;
ScrollWindow( 0, -m_cellsize * scrollinc, (const wxRect *) NULL);
ScrollWindow( 0, -m_cellsize * scrollinc, nullptr);
}
}

View file

@ -62,8 +62,8 @@ static int XPos; // Startup X position
static int YPos; // Startup Y position
static int pointSize = 12; // Font size
static const wxChar *index_filename = NULL; // Index filename
static const wxChar *data_filename = NULL; // Data filename
static const wxChar *index_filename = nullptr; // Index filename
static const wxChar *data_filename = nullptr; // Data filename
static wxChar error_buf[300]; // Error message buffer
static bool loaded_ok = false; // Poem loaded ok
static bool index_ok = false; // Index loaded ok
@ -72,7 +72,7 @@ static bool paging = false; // Are we paging?
static int current_page = 0; // Currently viewed page
// Backing bitmap
wxBitmap *backingBitmap = NULL;
wxBitmap *backingBitmap = nullptr;
void PoetryError(const wxChar *, const wxChar *caption=wxT("wxPoem Error"));
void PoetryNotify(const wxChar *Msg, const wxChar *caption=wxT("wxPoem"));
@ -90,7 +90,7 @@ void FindMax(int *max_thing, int thing);
wxIMPLEMENT_APP(MyApp);
MainWindow *TheMainWindow = NULL;
MainWindow *TheMainWindow = nullptr;
// Create the fonts
void MainWindow::CreateFonts()
@ -110,7 +110,7 @@ MainWindow::MainWindow(wxFrame *frame, wxWindowID id, const wxString& title,
const wxPoint& pos, const wxSize& size, long style):
wxFrame(frame, id, title, pos, size, style)
{
m_corners[0] = m_corners[1] = m_corners[2] = m_corners[3] = NULL;
m_corners[0] = m_corners[1] = m_corners[2] = m_corners[3] = nullptr;
ReadPreferences();
CreateFonts();
@ -510,7 +510,7 @@ bool MyApp::OnInit()
// randomize();
pages[0] = 0;
TheMainWindow = new MainWindow(NULL,
TheMainWindow = new MainWindow(nullptr,
wxID_ANY,
wxT("wxPoem"),
wxPoint(XPos, YPos),
@ -592,7 +592,7 @@ MyCanvas::~MyCanvas()
// Note: this must be done before the main window/canvas are destroyed
// or we get an error (no parent window for menu item button)
delete m_popupMenu;
m_popupMenu = NULL;
m_popupMenu = nullptr;
}
// Define the repainting behaviour
@ -693,13 +693,13 @@ int LoadIndex(const wxChar *file_name)
wxChar buf[100];
if (file_name == NULL)
if (file_name == nullptr)
return 0;
wxSprintf(buf, wxT("%s.idx"), file_name);
index_file = wxFopen(buf, wxT("r"));
if (index_file == NULL)
if (index_file == nullptr)
return 0;
wxFscanf(index_file, wxT("%ld"), &nitems);
@ -769,7 +769,7 @@ bool LoadPoem(const wxChar *file_name, long position)
paging = false;
current_page = 0;
if (file_name == NULL)
if (file_name == nullptr)
{
wxSprintf(error_buf, wxT("Error in Poem loading."));
PoetryError(error_buf);
@ -779,7 +779,7 @@ bool LoadPoem(const wxChar *file_name, long position)
wxSprintf(buf, wxT("%s.dat"), file_name);
data_file = wxFopen(buf, wxT("rb"));
if (data_file == NULL)
if (data_file == nullptr)
{
wxSprintf(error_buf, wxT("Data file %s not found."), buf);
PoetryError(error_buf);