From f0030e33e04ef29ae4e35084ef9f66166dce7aa8 Mon Sep 17 00:00:00 2001 From: Peter Wortmann Date: Mon, 31 Aug 2015 19:52:39 +0100 Subject: [PATCH] Warning fixes Actually pretty sure a few of them were bugs. Hopefully no new ones were introduced here. --- src/c4group/C4Group.cpp | 21 ++++++++++++----- src/c4group/C4GroupMain.cpp | 6 ++--- src/c4group/CStdFile.cpp | 6 ++--- src/control/C4Record.cpp | 4 ++-- src/editor/C4ObjectListDlg.cpp | 2 ++ src/graphics/Bitmap256.cpp | 6 ++--- src/graphics/C4FontLoader.cpp | 4 ++-- src/graphics/C4Shader.cpp | 2 +- src/gui/C4StartupNetDlg.cpp | 3 ++- src/network/C4NetIO.cpp | 6 ++--- src/platform/C4AppGTK.cpp | 42 +--------------------------------- src/platform/C4FileMonitor.cpp | 8 +++---- src/script/C4AulExec.cpp | 4 ++-- src/script/C4StringTable.cpp | 4 ++++ 14 files changed, 47 insertions(+), 71 deletions(-) diff --git a/src/c4group/C4Group.cpp b/src/c4group/C4Group.cpp index 0d3f5ec69..34b396328 100644 --- a/src/c4group/C4Group.cpp +++ b/src/c4group/C4Group.cpp @@ -672,7 +672,7 @@ bool C4Group::AddEntry(C4GroupEntry::EntryStatus status, return false; return true; - case C4GroupEntry::C4GRES_InMemory: // Save buffer to file in folder + case C4GroupEntry::C4GRES_InMemory: { // Save buffer to file in folder CStdFile hFile; bool fOkay = false; if (hFile.Create(tfname, !!childgroup)) @@ -683,8 +683,9 @@ bool C4Group::AddEntry(C4GroupEntry::EntryStatus status, if (fHoldBuffer) { if (fBufferIsStdbuf) StdBuf::DeletePointer(membuf); else delete [] membuf; } return fOkay; + } - // InGrp & Deleted ignored + default: break; // InGrp & Deleted ignored } return Error("Add to folder: Invalid request"); @@ -1025,6 +1026,7 @@ void C4Group::ResetSearch(bool reload_contents) case GRPF_File: SearchPtr=FirstEntry; break; + default: break; // InGrp & Deleted ignored } } @@ -1073,6 +1075,7 @@ C4GroupEntry* C4Group::SearchNextEntry(const char *szName) } break; // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + default: break; // InGrp & Deleted ignored } // No entry found: reset search pointer SearchPtr=NULL; @@ -1151,6 +1154,7 @@ bool C4Group::Read(void *pBuffer, size_t iSize) case GRPF_Folder: if (!StdFile.Read(pBuffer,iSize)) return Error("Read: Error reading from folder contents"); break; + default: break; // InGrp & Deleted ignored } return true; @@ -1412,6 +1416,7 @@ bool C4Group::DeleteEntry(const char *szFilename, bool fRecycle) break; // refresh file list ResetSearch(true); + default: break; // InGrp & Deleted ignored } return true; } @@ -1443,6 +1448,7 @@ bool C4Group::Rename(const char *szFile, const char *szNewName) // refresh file list ResetSearch(true); break; + default: break; // InGrp & Deleted ignored } return true; @@ -1570,6 +1576,7 @@ bool C4Group::ExtractEntry(const char *szFilename, const char *szExtractTo) if (!CopyItem(szPath,szTargetFName)) return Error("ExtractEntry: Cannot copy item"); break; + default: break; // InGrp & Deleted ignored } return true; } @@ -1751,13 +1758,15 @@ bool C4Group::SetFilePtr2Entry(const char *szName, bool NeedsToBeAGroup) if ((!centry) || (centry->Status != C4GroupEntry::C4GRES_InGroup)) return false; return SetFilePtr(centry->Offset); - case GRPF_Folder: + case GRPF_Folder: { StdFile.Close(); char path[_MAX_FNAME+1]; SCopy(FileName,path,_MAX_FNAME); AppendBackslash(path); SAppend(szName,path); bool fSuccess = StdFile.Open(path, NeedsToBeAGroup); return fSuccess; + } + default: break; // InGrp & Deleted ignored } return false; } @@ -1805,7 +1814,7 @@ bool C4Group::Add(const char *szName, StdBuf &pBuffer, bool fChild, bool fHoldBu szName, pBuffer.getSize(), szName, - (BYTE*) pBuffer.getData(), + (BYTE*) pBuffer.getMData(), false, fHoldBuffer, fExecutable, @@ -1822,7 +1831,7 @@ bool C4Group::Add(const char *szName, StdStrBuf &pBuffer, bool fChild, bool fHol szName, pBuffer.getLength(), szName, - (BYTE*) pBuffer.getData(), + (BYTE*) pBuffer.getMData(), false, fHoldBuffer, fExecutable, @@ -2240,4 +2249,4 @@ void C4Group::PreCacheEntry(C4GroupEntry * p) p->BufferIsStdbuf = true; p->Size = buf.getSize(); // update size in case group changed on disk between calls p->bpMemBuf = static_cast(buf.GrabPointer()); -} \ No newline at end of file +} diff --git a/src/c4group/C4GroupMain.cpp b/src/c4group/C4GroupMain.cpp index 180ae8081..d9e044f7d 100644 --- a/src/c4group/C4GroupMain.cpp +++ b/src/c4group/C4GroupMain.cpp @@ -72,8 +72,8 @@ void DisplayGroup(const C4Group &grp, const char *filter = NULL) if (filter != NULL && !WildcardMatch(filter, entry->FileName)) continue; - printf("%*s %8d Bytes", - max_fn_len, + printf("%*s %8u Bytes", + int(max_fn_len), entry->FileName, entry->Size); if (entry->ChildGroup != 0) @@ -85,7 +85,7 @@ void DisplayGroup(const C4Group &grp, const char *filter = NULL) ++file_count; byte_count += entry->Size; } - printf("%d Entries, %d Bytes\n", file_count, byte_count); + printf("%lu Entries, %lu Bytes\n", file_count, byte_count); } void PrintGroupInternals(C4Group &grp, int indent_level = 0) diff --git a/src/c4group/CStdFile.cpp b/src/c4group/CStdFile.cpp index 0ac4b8a0b..a4e1256c7 100644 --- a/src/c4group/CStdFile.cpp +++ b/src/c4group/CStdFile.cpp @@ -247,7 +247,7 @@ bool CStdFile::Write(const void *pBuffer, int iSize) int transfer; if (!pBuffer) return false; if (!ModeWrite) return false; - BYTE *bypBuffer= (BYTE*) pBuffer; + const BYTE *bypBuffer= (const BYTE*) pBuffer; while (iSize>0) { // Space in buffer: Transfer as much as possible @@ -268,10 +268,10 @@ bool CStdFile::Write(const void *pBuffer, int iSize) bool CStdFile::WriteString(const char *szStr) { thread_check.Check(); - BYTE nl[2]={0x0D,0x0A}; + BYTE nl[2]={0x0D,0x0A}; if (!szStr) return false; int size=SLen(szStr); - if (!Write((void*)szStr,size)) return false; + if (!Write((const void*)szStr,size)) return false; if (!Write(nl,2)) return false; return true; } diff --git a/src/control/C4Record.cpp b/src/control/C4Record.cpp index 9ce811f50..f03cef6e3 100644 --- a/src/control/C4Record.cpp +++ b/src/control/C4Record.cpp @@ -990,7 +990,7 @@ StdStrBuf GetDbgRecPktData(C4RecordChunkType eType, const StdBuf & RawData) break; default: for (unsigned int i=0; i(RawData, i)); break; } return r; @@ -1083,7 +1083,7 @@ void C4Playback::Check(C4RecordChunkType eType, const uint8_t *pData, int iSize) DebugRecError(FormatString("Type %s != %s", GetRecordChunkTypeName(PktInReplay.getType()), GetRecordChunkTypeName(eType)).getData()); return; } - if (PktInReplay.getSize() != iSize) + if (PktInReplay.getSize() != unsigned(iSize)) { DebugRecError(FormatString("Size %d != %d", (int) PktInReplay.getSize(), (int) iSize).getData()); } diff --git a/src/editor/C4ObjectListDlg.cpp b/src/editor/C4ObjectListDlg.cpp index be2e23369..c656baaaf 100644 --- a/src/editor/C4ObjectListDlg.cpp +++ b/src/editor/C4ObjectListDlg.cpp @@ -699,6 +699,7 @@ static void name_cell_data_func(GtkTreeViewColumn* column, GtkCellRenderer* rend enum { ICON_SIZE = 24 }; +#ifdef _UNUSED_ static void icon_cell_data_func(GtkTreeViewColumn* column, GtkCellRenderer* renderer, GtkTreeModel* model, GtkTreeIter* iter, gpointer data) { C4Object* object = c4_list_iter_get_C4Object(model, iter); @@ -755,6 +756,7 @@ static void icon_cell_data_func(GtkTreeViewColumn* column, GtkCellRenderer* rend g_object_set(G_OBJECT(renderer), "pixbuf", pixbuf, NULL); } +#endif // _UNUSED_ void C4ObjectListDlg::Open() { diff --git a/src/graphics/Bitmap256.cpp b/src/graphics/Bitmap256.cpp index cdfeee866..78749b56b 100644 --- a/src/graphics/Bitmap256.cpp +++ b/src/graphics/Bitmap256.cpp @@ -40,7 +40,7 @@ void C4BMPInfo::Set(int iWdt, int iHgt, int iBitDepth) { Default(); // Set header - Head.bfType=*((WORD*)"BM"); + Head.bfType=*((const WORD*)"BM"); Head.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+DWordAligned(iWdt)*iHgt; Head.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER); // Set bitmap info @@ -62,7 +62,7 @@ C4BMP256Info::C4BMP256Info() bool C4BMP256Info::Valid() { - if (Head.bfType != *((WORD*)"BM") ) return false; + if (Head.bfType != *((const WORD*)"BM") ) return false; if ((Info.biBitCount!=8) || (Info.biCompression!=0)) return false; return true; } @@ -76,7 +76,7 @@ void C4BMP256Info::Set(int iWdt, int iHgt, CStdPalette *Palette) { Default(); // Set header - Head.bfType=*((WORD*)"BM"); + Head.bfType=*((const WORD*)"BM"); Head.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+256*sizeof(RGBQUAD)+DWordAligned(iWdt)*iHgt; Head.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+256*sizeof(RGBQUAD); // Set bitmap info diff --git a/src/graphics/C4FontLoader.cpp b/src/graphics/C4FontLoader.cpp index 709169c84..e715622fb 100644 --- a/src/graphics/C4FontLoader.cpp +++ b/src/graphics/C4FontLoader.cpp @@ -380,9 +380,9 @@ bool CStdFont::AddRenderedChar(uint32_t dwChar, C4Facet *pfctTarget) int at_x = iCurrentSfcX + Max(slot->bitmap_left,0); // Copy to the surface if (!sfcCurrent->Lock()) return false; - for (int y = 0; y < slot->bitmap.rows + fDoShadow; ++y) + for (unsigned int y = 0; y < slot->bitmap.rows + fDoShadow; ++y) { - for (int x = 0; x < slot->bitmap.width + fDoShadow; ++x) + for (unsigned int x = 0; x < slot->bitmap.width + fDoShadow; ++x) { unsigned char bAlpha, bAlphaShadow; if (x < slot->bitmap.width && y < slot->bitmap.rows) diff --git a/src/graphics/C4Shader.cpp b/src/graphics/C4Shader.cpp index e4f12ac87..7c3665a3c 100644 --- a/src/graphics/C4Shader.cpp +++ b/src/graphics/C4Shader.cpp @@ -198,7 +198,7 @@ int C4Shader::ParsePosition(const char *szWhat, const char **ppPos) // Lookup name int iPosition = -1; - for (int i = 0; i < sizeof(C4SH_PosNames) / sizeof(*C4SH_PosNames); i++) { + for (unsigned int i = 0; i < sizeof(C4SH_PosNames) / sizeof(*C4SH_PosNames); i++) { if (SEqual(Name.getData(), C4SH_PosNames[i].Name)) { iPosition = C4SH_PosNames[i].Position; break; diff --git a/src/gui/C4StartupNetDlg.cpp b/src/gui/C4StartupNetDlg.cpp index 3064aa615..e196dfd9c 100644 --- a/src/gui/C4StartupNetDlg.cpp +++ b/src/gui/C4StartupNetDlg.cpp @@ -129,7 +129,8 @@ void C4StartupNetListEntry::SetRefQuery(const char *szAddress, enum QueryType eQ // safety: clear previous ClearRef(); // setup layout - ((C4Facet &) pIcon->GetFacet()) = (const C4Facet &) C4Startup::Get()->Graphics.fctNetGetRef; + const_cast(reinterpret_cast(pIcon->GetFacet())) + = (const C4Facet &) C4Startup::Get()->Graphics.fctNetGetRef; pIcon->SetAnimated(true, 1); pIcon->SetBounds(rctIconLarge); // init a new ref client to query diff --git a/src/network/C4NetIO.cpp b/src/network/C4NetIO.cpp index 53f04303d..618cb3286 100644 --- a/src/network/C4NetIO.cpp +++ b/src/network/C4NetIO.cpp @@ -1886,8 +1886,8 @@ bool C4NetIOUDP::InitBroadcast(addr_t *pBroadcastAddr) for (int iRetries = 1000; iRetries; iRetries--) { // create new - random - address - MCAddr.sin_addr.s_addr = MCAddr.sin_addr.s_addr = - 0x000000ef | ((rand() & 0xff) << 24) | ((rand() & 0xff) << 16) | ((rand() & 0xff) << 8); + MCAddr.sin_addr.s_addr = + 0x000000ef | ((rand() & 0xff) << 24) | ((rand() & 0xff) << 16) | ((rand() & 0xff) << 8); // init broadcast if (!C4NetIOSimpleUDP::InitBroadcast(&MCAddr)) return false; @@ -2634,7 +2634,7 @@ void C4NetIOUDP::Peer::OnRecv(const C4NetIOPacket &rPacket) // (mt-safe) } // set packet counter if (fBroadcasted) - iRIMCPacketCounter = iRIMCPacketCounter = pPkt->Nr; + iRIMCPacketCounter = iIMCPacketCounter = pPkt->Nr; else iRIPacketCounter = iIPacketCounter = pPkt->Nr; // clear incoming packets diff --git a/src/platform/C4AppGTK.cpp b/src/platform/C4AppGTK.cpp index 564637f5f..8b308d75f 100644 --- a/src/platform/C4AppGTK.cpp +++ b/src/platform/C4AppGTK.cpp @@ -153,7 +153,7 @@ bool C4AbstractApp::SetVideoMode(int iXRes, int iYRes, unsigned int iColorDepth, XRRScreenSize * sizes = XRRConfigSizes(conf, &n); for (int i = 0; i < n; ++i) { - if (sizes[i].width == iXRes && sizes[i].height == iYRes) + if (int(sizes[i].width) == iXRes && int(sizes[i].height) == iYRes) { #ifdef _DEBUG LogF("XRRSetScreenConfig %d", i); @@ -204,46 +204,6 @@ bool C4AbstractApp::GetIndexedDisplayMode(int32_t iIndex, int32_t *piXRes, int32 return false; } -static XRROutputInfo* GetXRROutputInfoForWindow(Display* dpy, Window w) -{ - XRRScreenResources * r = XRRGetScreenResources(dpy, w); - if (!r) return NULL; - - XRROutputInfo * info = NULL; - RROutput output = XRRGetOutputPrimary(dpy, w); - if(output != 0) - { - info = XRRGetOutputInfo(dpy, r, output); - if (!info) - { - XRRFreeScreenResources(r); - return NULL; - } - } - - if(!info || info->connection == RR_Disconnected || info->crtc == 0) - { - // The default "primary" output does not seem to be connected - // to a piece of actual hardware. As a fallback, go through - // all outputs and choose the first active one. - XRRFreeOutputInfo(info); - info = NULL; - for(int i = 0; i < r->noutput; ++i) - { - info = XRRGetOutputInfo(dpy, r, r->outputs[i]); - if(info->connection != RR_Disconnected && info->crtc != 0) - break; - - XRRFreeOutputInfo(info); - info = NULL; - } - } - XRRFreeScreenResources(r); - if(!info) return NULL; - - return info; -} - // Copy the text to the clipboard or the primary selection bool C4AbstractApp::Copy(const StdStrBuf & text, bool fClipboard) { diff --git a/src/platform/C4FileMonitor.cpp b/src/platform/C4FileMonitor.cpp index a9a279374..227f72339 100644 --- a/src/platform/C4FileMonitor.cpp +++ b/src/platform/C4FileMonitor.cpp @@ -74,13 +74,13 @@ bool C4FileMonitor::Execute(int iTimeout, pollfd * pfd) // some other thread uint32_t mask = event->mask; C4InteractiveThread &Thread = Application.InteractiveThread; if (mask & IN_CREATE) - Thread.PushEvent(Ev_FileChange, (void*)file); + Thread.PushEvent(Ev_FileChange, const_cast(file)); if (mask & IN_MODIFY) - Thread.PushEvent(Ev_FileChange, (void*)file); + Thread.PushEvent(Ev_FileChange, const_cast(file)); if (mask & IN_MOVED_TO) - Thread.PushEvent(Ev_FileChange, (void*)file); + Thread.PushEvent(Ev_FileChange, const_cast(file)); if (mask & IN_MOVE_SELF) - Thread.PushEvent(Ev_FileChange, (void*)file); + Thread.PushEvent(Ev_FileChange, const_cast(file)); // FIXME: (*(inotify_event*)buf).name); } else diff --git a/src/script/C4AulExec.cpp b/src/script/C4AulExec.cpp index c92cab6ac..c2003256f 100644 --- a/src/script/C4AulExec.cpp +++ b/src/script/C4AulExec.cpp @@ -310,7 +310,7 @@ C4Value C4AulExec::Exec(C4AulBCC *pCPos, bool fPassErrors) if (!pPar2->_getInt()) throw new C4AulExecError("division by zero"); // INT_MIN/-1 cannot be represented in an int and would cause an uncaught exception - if (pPar1->_getInt()==0x80000000 && pPar2->_getInt()==-1) + if (pPar1->_getInt()==INT32_MIN && pPar2->_getInt()==-1) throw new C4AulExecError("division overflow"); pPar1->SetInt(pPar1->_getInt() / pPar2->_getInt()); PopValue(); @@ -329,7 +329,7 @@ C4Value C4AulExec::Exec(C4AulBCC *pCPos, bool fPassErrors) CheckOpPars(C4V_Int, C4V_Int, "%"); C4Value *pPar1 = pCurVal - 1, *pPar2 = pCurVal; // INT_MIN%-1 cannot be represented in an int and would cause an uncaught exception - if (pPar1->_getInt()==0x80000000 && pPar2->_getInt()==-1) + if (pPar1->_getInt()==INT32_MIN && pPar2->_getInt()==-1) throw new C4AulExecError("modulo division overflow"); if (pPar2->_getInt()) pPar1->SetInt(pPar1->_getInt() % pPar2->_getInt()); diff --git a/src/script/C4StringTable.cpp b/src/script/C4StringTable.cpp index e8498e781..b78906c2c 100644 --- a/src/script/C4StringTable.cpp +++ b/src/script/C4StringTable.cpp @@ -57,11 +57,15 @@ C4String::C4String() C4String::~C4String() { // unreg +#ifdef _DEBUG static bool remove = false; assert(!remove); (void)remove; remove = true; +#endif Strings.Set.Remove(this); +#ifdef _DEBUG remove = false; +#endif } void C4String::operator=(const char * s)