Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use nullptr/NULL instead of 0 for pointers, two fixes for undefined behavior #4996

Merged
merged 1 commit into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/bios_disk.h
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ class imageDiskVHD : public imageDisk {
uint32_t currentBlock = 0xFFFFFFFF;
bool currentBlockAllocated = false;
uint32_t currentBlockSectorOffset = 0;
uint8_t* currentBlockDirtyMap = 0;
uint8_t* currentBlockDirtyMap = nullptr;
};

/* C++ class implementing El Torito floppy emulation */
Expand Down
2 changes: 1 addition & 1 deletion include/callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class CALLBACK_HandlerObject{
void Uninstall();

//Only allocate a callback number
void Allocate(CallBack_Handler handler,const char* description=0);
void Allocate(CallBack_Handler handler,const char* description=nullptr);
uint16_t Get_callback() {
return (uint16_t)m_callback;
}
Expand Down
2 changes: 1 addition & 1 deletion include/glidedef.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct GLIDE_Block
bool * fullscreen;
uint16_t width, height;
class GLIDE_PageHandler * lfb_pagehandler;
GLIDE_Block():enabled(false),fullscreen(0),width(0),height(0),lfb_pagehandler((GLIDE_PageHandler*)0) { }
GLIDE_Block():enabled(false),fullscreen(nullptr),width(0),height(0),lfb_pagehandler((GLIDE_PageHandler*)0) { }
};
extern GLIDE_Block glide;
extern void GLIDE_ResetScreen(bool update=false);
Expand Down
2 changes: 1 addition & 1 deletion include/sdlmain.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ struct SDL_Block {
uint32_t bpp = 0;
Bitu flags = 0;
double scalex = 0, scaley = 0;
GFX_CallBack_t callback = 0;
GFX_CallBack_t callback = nullptr;
} draw;
bool wait_on_error = false;
struct {
Expand Down
8 changes: 4 additions & 4 deletions src/cpu/callback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ uint8_t CALLBACK_Allocate(void) {
for (uint8_t i=1;(i<CB_MAX);i++) {
if (CallBack_Handlers[i]==&illegal_handler) {
if (CallBack_Description[i] != NULL) LOG_MSG("CALLBACK_Allocate() warning: empty slot still has description string!\n");
CallBack_Handlers[i]=0;
CallBack_Handlers[i]=nullptr;
return i;
}
}
Expand Down Expand Up @@ -273,7 +273,7 @@ void CALLBACK_SIF(bool const val) { CALLBACK_SET_FLAG<FLAG_IF>(val); }

void CALLBACK_SetDescription(Bitu nr, const char* descr) {
if (CallBack_Description[nr]) delete[] CallBack_Description[nr];
CallBack_Description[nr] = 0;
CallBack_Description[nr] = nullptr;

if (descr != NULL) {
CallBack_Description[nr] = new char[strlen(descr)+1];
Expand All @@ -282,7 +282,7 @@ void CALLBACK_SetDescription(Bitu nr, const char* descr) {
}

const char* CALLBACK_GetDescription(Bitu nr) {
if (nr>=CB_MAX) return 0;
if (nr>=CB_MAX) return nullptr;
return CallBack_Description[nr];
}

Expand Down Expand Up @@ -820,7 +820,7 @@ void CALLBACK_HandlerObject::Uninstall(){
//Do nothing. Merely DeAllocate the callback
} else E_Exit("what kind of callback is this!");
if(CallBack_Description[m_callback]) delete [] CallBack_Description[m_callback];
CallBack_Description[m_callback] = 0;
CallBack_Description[m_callback] = nullptr;
CALLBACK_DeAllocate(m_callback);
installed=false;
}
Expand Down
8 changes: 4 additions & 4 deletions src/cpu/core_dyn_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ Bits CPU_Core_Dyn_X86_Run(void) {
if (DEBUG_HeavyIsBreakpoint()) return debugCallback;
#endif
#endif
CodePageHandler * chandler=0;
CodePageHandler * chandler=nullptr;
if (GCC_UNLIKELY(MakeCodePage(ip_point,chandler))) {
CPU_Exception(cpu.exception.which,cpu.exception.error);
goto restart_core;
Expand Down Expand Up @@ -424,7 +424,7 @@ Bits CPU_Core_Dyn_X86_Run(void) {
}
}
run_block:
cache.block.running=0;
cache.block.running=nullptr;
core_dyn.pagefault = false;
BlockReturnDynX86 ret=safe_gen_runcode((uint8_t*)cache_rwtox(block->cache.start));

Expand Down Expand Up @@ -532,7 +532,7 @@ void CPU_Core_Dyn_X86_Shutdown(void) {
void CPU_Core_Dyn_X86_Init(void) {
Bits i;
/* Setup the global registers and their flags */
for (i=0;i<G_MAX;i++) DynRegs[i].genreg=0;
for (i=0;i<G_MAX;i++) DynRegs[i].genreg=nullptr;
DynRegs[G_EAX].data=&reg_eax;
DynRegs[G_EAX].flags=DYNFLG_HAS8|DYNFLG_HAS16|DYNFLG_LOAD|DYNFLG_SAVE;
DynRegs[G_ECX].data=&reg_ecx;
Expand Down Expand Up @@ -587,7 +587,7 @@ void CPU_Core_Dyn_X86_Init(void) {
DynRegs[G_TMPD].flags=DYNFLG_HAS16;
DynRegs[G_SHIFT].data=&extra_regs.shift;
DynRegs[G_SHIFT].flags=DYNFLG_HAS8|DYNFLG_HAS16;
DynRegs[G_EXIT].data=0;
DynRegs[G_EXIT].data=nullptr;
DynRegs[G_EXIT].flags=DYNFLG_HAS16;
/* Init the generator */
gen_init();
Expand Down
42 changes: 21 additions & 21 deletions src/cpu/core_dyn_x86/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,14 @@ class CodePageHandler : public PageHandler {
else cache.last_page=prev;
next=cache.free_pages;
cache.free_pages=this;
prev=0;
prev=nullptr;
}
void ClearRelease(void) {
for (Bitu index=0;index<(1+DYN_PAGE_HASH);index++) {
CacheBlock * block=hash_map[index];
while (block) {
CacheBlock * nextblock=block->hash.next;
block->page.handler=0; //No need, full clear
block->page.handler=nullptr; //No need, full clear
block->Clear();
block=nextblock;
}
Expand All @@ -317,7 +317,7 @@ class CodePageHandler : public PageHandler {
if (block->page.start==start) return block;
block=block->hash.next;
}
return 0;
return nullptr;
}
HostPt GetHostReadPt(Bitu phys_page) override {
hostmem=old_pagehandler->GetHostReadPt(phys_page);
Expand Down Expand Up @@ -349,7 +349,7 @@ static CacheBlock * cache_getblock(void) {
CacheBlock * ret=cache.block.free;
if (!ret) E_Exit("Ran out of CacheBlocks" );
cache.block.free=ret->cache.next;
ret->cache.next=0;
ret->cache.next=nullptr;
return ret;
}

Expand All @@ -358,10 +358,10 @@ void CacheBlock::Clear(void) {
/* Check if this is not a cross page block */
if (hash.index) for (ind=0;ind<2;ind++) {
CacheBlock * fromlink=link[ind].from;
link[ind].from=0;
link[ind].from=nullptr;
while (fromlink) {
CacheBlock * nextlink=fromlink->link[ind].next;
fromlink->link[ind].next=0;
fromlink->link[ind].next=nullptr;
fromlink->link[ind].to=&link_blocks[ind];
fromlink=nextlink;
}
Expand All @@ -378,13 +378,13 @@ void CacheBlock::Clear(void) {
} else
cache_addunsedblock(this);
if (crossblock) {
crossblock->crossblock=0;
crossblock->crossblock=nullptr;
crossblock->Clear();
crossblock=0;
crossblock=nullptr;
}
if (page.handler) {
page.handler->DelCacheBlock(this);
page.handler=0;
page.handler=nullptr;
}
if (cache.wmapmask){
free(cache.wmapmask);
Expand Down Expand Up @@ -422,10 +422,10 @@ static void cache_closeblock(void) {
CacheBlock * block=cache.block.active;
block->link[0].to=&link_blocks[0];
block->link[1].to=&link_blocks[1];
block->link[0].from=0;
block->link[1].from=0;
block->link[0].next=0;
block->link[1].next=0;
block->link[0].from=nullptr;
block->link[1].from=nullptr;
block->link[0].next=nullptr;
block->link[1].next=nullptr;
/* Close the block with correct alignments */
Bitu written=cache.pos-block->cache.start;
if (written>block->cache.size) {
Expand Down Expand Up @@ -540,7 +540,7 @@ static void cache_init(bool enable) {
block->cache.start=&cache_code[0];
block->cache.xstart=(uint8_t*)cache_rwtox(block->cache.start);
block->cache.size=CACHE_TOTAL;
block->cache.next=0; //Last block in the list
block->cache.next=nullptr; //Last block in the list
}
/* Setup the default blocks for block linkage returns */
cache.pos=&cache_code_link_blocks[0];
Expand All @@ -551,9 +551,9 @@ static void cache_init(bool enable) {
link_blocks[1].cache.start=cache.pos;
link_blocks[1].cache.xstart=(uint8_t*)cache_rwtox(link_blocks[1].cache.start);
gen_return(BR_Link2);
cache.free_pages=0;
cache.last_page=0;
cache.used_pages=0;
cache.free_pages=nullptr;
cache.last_page=nullptr;
cache.used_pages=nullptr;
/* Setup the code pages */
for (i=0;i<CACHE_PAGES;i++) {
CodePageHandler * newpage=new CodePageHandler();
Expand Down Expand Up @@ -620,7 +620,7 @@ static void cache_reset(void) {
block->cache.start=&cache_code[0];
block->cache.xstart=(uint8_t*)cache_rwtox(block->cache.start);
block->cache.size=CACHE_TOTAL;
block->cache.next=0; //Last block in the list
block->cache.next=nullptr; //Last block in the list

/* Setup the default blocks for block linkage returns */
cache.pos=&cache_code_link_blocks[0];
Expand All @@ -631,9 +631,9 @@ static void cache_reset(void) {
link_blocks[1].cache.start=cache.pos;
link_blocks[1].cache.xstart=(uint8_t*)cache_rwtox(link_blocks[1].cache.start);
gen_return(BR_Link2);
cache.free_pages=0;
cache.last_page=0;
cache.used_pages=0;
cache.free_pages=nullptr;
cache.last_page=nullptr;
cache.used_pages=nullptr;
/* Setup the code pages */
for (Bitu i=0;i<CACHE_PAGES;i++) {
CodePageHandler * newpage=new CodePageHandler();
Expand Down
Loading