Created a proper DEBUG build (specified using DEBUG=1). Set warnings to fatal for release builds and fixed the warnings throughout the code

This commit is contained in:
akuker
2020-07-10 17:49:02 -05:00
parent 853d37ea81
commit 32af6cf169
5 changed files with 43 additions and 34 deletions

View File

@@ -3,16 +3,18 @@
CC = gcc CC = gcc
CXX = g++ CXX = g++
# Debug CFLAGS DEBUG ?= 0
#CFLAGS = -DDISK_LOG -O0 -g -Wall ifeq ($(DEBUG), 1)
#CXXFLAGS = -DDISK_LOG -O0 -g -Wall # Debug CFLAGS
#CFLAGS = -O0 -g -Wall CFLAGS = -DDISK_LOG -O0 -g -Wall -DDEBUG
#CXXFLAGS = -O0 -g -Wall CXXFLAGS = -DDISK_LOG -O0 -g -Wall -DDEBUG
# Release CFLAGS BUILD_TYPE = Debug
CFLAGS = -O3 -Wall else
CXXFLAGS = -O3 -Wall # Release CFLAGS
CFLAGS ?= -O3 -Wall -Werror
CXXFLAGS ?= -O3 -Wall -Werror
BUILD_TYPE = Release
endif
# If its not specified, build for STANDARD configuration # If its not specified, build for STANDARD configuration
CONNECT_TYPE ?= STANDARD CONNECT_TYPE ?= STANDARD
@@ -76,10 +78,14 @@ OBJ_ALL := $(OBJ_RASCSI) $(OBJ_RASCTL) $(OBJ_RASDUMP) $(OBJ_SASIDUMP)
%.o: %.cpp %.o: %.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@ $(CXX) $(CXXFLAGS) -c $< -o $@
docs: $(DOC_DIR)/rascsi_man_page.txt $(DOC_DIR)/rasctl_man_page.txt
ALL: $(BIN_ALL) docs
.DEFAULT_GOAL := all
.PHONY: all ALL docs
all: $(BIN_ALL) docs all: $(BIN_ALL) docs
ALL: all
docs: $(DOC_DIR)/rascsi_man_page.txt $(DOC_DIR)/rasctl_man_page.txt
$(RASCSI): $(OBJ_RASCSI) $(RASCSI): $(OBJ_RASCSI)
$(CXX) -o $@ $(OBJ_RASCSI) -lpthread $(CXX) -o $@ $(OBJ_RASCSI) -lpthread

View File

@@ -1894,7 +1894,7 @@ void CHostPath::Refresh()
if (stat(S2U(szPath), &sb)) if (stat(S2U(szPath), &sb))
#else #else
if (f_stat(S2U(szPath), NULL) != FR_OK) if (f_stat(S2U(szPath), NULL) != FR_OK)
#endif // BAREMETAL #endif // BAREMETAL
break; // 利用可能パターンを発見 break; // 利用可能パターンを発見
} }
} }
@@ -1957,7 +1957,7 @@ void CHostPath::Refresh()
// 日付時刻 // 日付時刻
pFilename->SetEntryDate(fno.fdate); pFilename->SetEntryDate(fno.fdate);
pFilename->SetEntryTime(fno.ftime); pFilename->SetEntryTime(fno.ftime);
#endif // BAREMETAL #endif // BAREMETAL
// クラスタ番号設定 // クラスタ番号設定
pFilename->SetEntryCluster(0); pFilename->SetEntryCluster(0);
@@ -2045,7 +2045,7 @@ void CHostPath::Backup()
m_tBackupT = fno.ftime; m_tBackupT = fno.ftime;
} }
} }
#endif // BAREMETAL #endif // BAREMETAL
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@@ -2613,9 +2613,8 @@ void CHostFiles::AddFilename()
{ {
ASSERT(this); ASSERT(this);
ASSERT(strlen(m_szHostResult) + strlen((const char*)m_szHumanFilename) < FILEPATH_MAX); ASSERT(strlen(m_szHostResult) + strlen((const char*)m_szHumanFilename) < FILEPATH_MAX);
/// @warning Unicode未対応。いずれUnicodeの世界に飮まれた時はここで変換を行なう → 済 /// @warning Unicode未対応。いずれUnicodeの世界に飮まれた時はここで変換を行なう → 済
strcat(m_szHostResult, (const char*)m_szHumanFilename); strncat(m_szHostResult, (const char*)m_szHumanFilename, ARRAY_SIZE(m_szHumanFilename));
} }
//=========================================================================== //===========================================================================
@@ -2896,7 +2895,7 @@ BOOL CHostFcb::Open()
{ {
#ifndef BAREMETAL #ifndef BAREMETAL
struct stat st; struct stat st;
ASSERT(this); ASSERT(this);
ASSERT(strlen(m_szFilename) > 0); ASSERT(strlen(m_szFilename) > 0);

View File

@@ -1648,7 +1648,7 @@ int FASTCALL Disk::AddFormat(BOOL change, BYTE *buf)
buf[0] = 0x80 | 0x03; buf[0] = 0x80 | 0x03;
buf[1] = 0x16; buf[1] = 0x16;
// Show the number of bytes in the physical sector as changeable \ // Show the number of bytes in the physical sector as changeable
// (though it cannot be changed in practice) // (though it cannot be changed in practice)
if (change) { if (change) {
buf[0xc] = 0xff; buf[0xc] = 0xff;
@@ -2709,7 +2709,7 @@ BOOL FASTCALL SCSIHD::ModeSelect(const DWORD *cdb, const BYTE *buf, int length)
case 0x08: case 0x08:
// Debug code for Issue #2: // Debug code for Issue #2:
// https://github.com/akuker/RASCSI/issues/2 // https://github.com/akuker/RASCSI/issues/2
printf("\[Unhandled page code\] Received mode page code 8 with total length %d\n ", length); printf("[Unhandled page code] Received mode page code 8 with total length %d\n ", length);
for (int i = 0; i<length; i++) for (int i = 0; i<length; i++)
{ {
printf("%02X ", buf[i]); printf("%02X ", buf[i]);
@@ -7878,9 +7878,9 @@ void FASTCALL SASIDEV::FlushUnit()
// Debug code related to Issue #2 on github, where we get an unhandled Model select when // Debug code related to Issue #2 on github, where we get an unhandled Model select when
// the mac is rebooted // the mac is rebooted
// https://github.com/akuker/RASCSI/issues/2 // https://github.com/akuker/RASCSI/issues/2
Log(Log::Warning, "Received \'Mode Select\' \[%02X\]\n"); Log(Log::Warning, "Received \'Mode Select\'\n");
Log(Log::Warning, " Operation Code: \[%02X\]\n", ctrl.cmd[0]); Log(Log::Warning, " Operation Code: [%02X]\n", ctrl.cmd[0]);
Log(Log::Warning, " Logical Unit %01X, PF %01X, SP %01X \[%02X\]\n", ctrl.cmd[1] >> 5, 1 & (ctrl.cmd[1] >> 4), ctrl.cmd[1] & 1, ctrl.cmd[1]); Log(Log::Warning, " Logical Unit %01X, PF %01X, SP %01X [%02X]\n", ctrl.cmd[1] >> 5, 1 & (ctrl.cmd[1] >> 4), ctrl.cmd[1] & 1, ctrl.cmd[1]);
Log(Log::Warning, " Reserved: %02X\n", ctrl.cmd[2]); Log(Log::Warning, " Reserved: %02X\n", ctrl.cmd[2]);
Log(Log::Warning, " Reserved: %02X\n", ctrl.cmd[3]); Log(Log::Warning, " Reserved: %02X\n", ctrl.cmd[3]);
Log(Log::Warning, " Parameter List Len %02X\n", ctrl.cmd[4]); Log(Log::Warning, " Parameter List Len %02X\n", ctrl.cmd[4]);
@@ -7890,13 +7890,13 @@ void FASTCALL SASIDEV::FlushUnit()
if (!ctrl.unit[lun]->ModeSelect( if (!ctrl.unit[lun]->ModeSelect(
ctrl.cmd, ctrl.buffer, ctrl.offset)) { ctrl.cmd, ctrl.buffer, ctrl.offset)) {
// MODE SELECT failed // MODE SELECT failed
Log(Log::Warning, "Error occured while processing Mode Select command %02X\n", ctrl.cmd[0]); Log(Log::Warning, "Error occured while processing Mode Select command %02X\n", (unsigned char)ctrl.cmd[0]);
return; return;
} }
break; break;
default: default:
printf("Received an invalid flush command %08X!!!!!\n",ctrl.cmd[0]); Log(Log::Warning, "Received an invalid flush command %02X!!!!!\n",ctrl.cmd[0]);
ASSERT(FALSE); ASSERT(FALSE);
break; break;
} }
@@ -7961,10 +7961,12 @@ void SASIDEV::GetPhaseStr(char *str)
void FASTCALL SASIDEV::Log(Log::loglevel level, const char *format, ...) void FASTCALL SASIDEV::Log(Log::loglevel level, const char *format, ...)
{ {
#if !defined(BAREMETAL) #if !defined(BAREMETAL)
#ifdef DISK_LOG
char buffer[0x200]; char buffer[0x200];
char buffer2[0x250]; char buffer2[0x250];
char buffer3[0x250]; char buffer3[0x250];
char phase_str[20]; char phase_str[20];
#endif
va_list args; va_list args;
va_start(args, format); va_start(args, format);

View File

@@ -101,14 +101,14 @@ char* dirname(char *path)
dirtmp[1] = '\0'; dirtmp[1] = '\0';
return dirtmp; return dirtmp;
} }
p = path + strlen(path) - 1; p = path + strlen(path) - 1;
while( *p == '/' ) { while( *p == '/' ) {
if( p == path ) if( p == path )
return path; return path;
*p-- = '\0'; *p-- = '\0';
} }
while( p >= path && *p != '/' ) { while( p >= path && *p != '/' ) {
p--; p--;
} }
@@ -143,7 +143,7 @@ char* basename(char *path)
basetmp[1] = '\0'; basetmp[1] = '\0';
return basetmp; return basetmp;
} }
p = path + strlen(path) - 1; p = path + strlen(path) - 1;
while( *p == '/' ) { while( *p == '/' ) {
if( p == path ) { if( p == path ) {
@@ -151,11 +151,11 @@ char* basename(char *path)
} }
*p-- = '\0'; *p-- = '\0';
} }
while( p >= path && *p != '/' ) { while( p >= path && *p != '/' ) {
p--; p--;
} }
return p + 1; return p + 1;
} }
#endif // BAREMETAL #endif // BAREMETAL
@@ -219,9 +219,9 @@ void FASTCALL Filepath::Make()
m_szPath[0] = _T('\0'); m_szPath[0] = _T('\0');
// 合成 // 合成
strcat(m_szPath, m_szDir); strncat(m_szPath, m_szDir, ARRAY_SIZE(m_szPath) - strlen(m_szPath));
strcat(m_szPath, m_szFile); strncat(m_szPath, m_szFile, ARRAY_SIZE(m_szPath) - strlen(m_szPath));
strcat(m_szPath, m_szExt); strncat(m_szPath, m_szExt, ARRAY_SIZE(m_szPath) - strlen(m_szPath));
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
@@ -343,4 +343,4 @@ char Filepath::ShortName[_MAX_FNAME + _MAX_DIR];
// ファイル名+拡張子 // ファイル名+拡張子
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
TCHAR Filepath::FileExt[_MAX_FNAME + _MAX_DIR]; TCHAR Filepath::FileExt[_MAX_FNAME + _MAX_DIR];

View File

@@ -114,6 +114,8 @@
#endif // NDEBUG #endif // NDEBUG
#endif // ASSERT_DIAG #endif // ASSERT_DIAG
#define ARRAY_SIZE(x) (sizeof(x)/(sizeof(x[0])))
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
// //
// 基本型定義 // 基本型定義