From: <man...@us...> - 2015-05-22 18:57:32
|
Revision: 5135 http://sourceforge.net/p/modplug/code/5135 Author: manxorist Date: 2015-05-22 18:57:26 +0000 (Fri, 22 May 2015) Log Message: ----------- [Ref] Add -Wcast-qual option to Makefile builds. -Wcast-qual emits a warning when a C-style cast casts away constness or volatility. const_cast does not trigger a warning. This enforces const-correctness when no const_cast is used. Fix the fallout. Modified Paths: -------------- trunk/OpenMPT/Makefile trunk/OpenMPT/libopenmpt/libopenmpt_c.cpp trunk/OpenMPT/libopenmpt/libopenmpt_modplug.c trunk/OpenMPT/soundlib/Load_mdl.cpp trunk/OpenMPT/soundlib/Load_med.cpp Modified: trunk/OpenMPT/Makefile =================================================================== --- trunk/OpenMPT/Makefile 2015-05-21 15:39:09 UTC (rev 5134) +++ trunk/OpenMPT/Makefile 2015-05-22 18:57:26 UTC (rev 5135) @@ -291,8 +291,8 @@ CFLAGS += -g endif -CXXFLAGS += -Wall -Wextra -Wcast-align $(CXXFLAGS_WARNINGS) -CFLAGS += -Wall -Wextra -Wcast-align $(CFLAGS_WARNINGS) +CXXFLAGS += -Wall -Wextra -Wcast-qual -Wcast-align $(CXXFLAGS_WARNINGS) +CFLAGS += -Wall -Wextra -Wcast-qual -Wcast-align $(CFLAGS_WARNINGS) endif Modified: trunk/OpenMPT/libopenmpt/libopenmpt_c.cpp =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt_c.cpp 2015-05-21 15:39:09 UTC (rev 5134) +++ trunk/OpenMPT/libopenmpt/libopenmpt_c.cpp 2015-05-22 18:57:26 UTC (rev 5135) @@ -156,7 +156,7 @@ void openmpt_free_string( const char * str ) { try { - std::free( (void*)str ); + std::free( const_cast< char * >( str ) ); } catch ( ... ) { openmpt::report_exception( __FUNCTION__ ); } Modified: trunk/OpenMPT/libopenmpt/libopenmpt_modplug.c =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt_modplug.c 2015-05-21 15:39:09 UTC (rev 5134) +++ trunk/OpenMPT/libopenmpt/libopenmpt_modplug.c 2015-05-22 18:57:26 UTC (rev 5135) @@ -81,8 +81,8 @@ openmpt_module* mod; signed short* buf; signed int* mixerbuf; - const char* name; - const char* message; + char* name; + char* message; ModPlug_Settings settings; ModPlugMixerProc mixerproc; unsigned char * * patterns; @@ -124,6 +124,8 @@ LIBOPENMPT_MODPLUG_API ModPlugFile* ModPlug_Load(const void* data, int size) { ModPlugFile* file = malloc(sizeof(ModPlugFile)); + const char* name = NULL; + const char* message = NULL; if(!file) return NULL; memset(file,0,sizeof(ModPlugFile)); memcpy(&file->settings,&globalsettings,sizeof(ModPlug_Settings)); @@ -139,8 +141,34 @@ return NULL; } openmpt_module_set_repeat_count(file->mod,file->settings.mLoopCount); - file->name = openmpt_module_get_metadata(file->mod,"title"); - file->message = openmpt_module_get_metadata(file->mod,"message"); + name = openmpt_module_get_metadata(file->mod,"title"); + if(name){ + file->name = malloc(strlen(name)+1); + if(file->name){ + strcpy(file->name,name); + } + openmpt_free_string(name); + name = NULL; + }else{ + file->name = malloc(strlen("")+1); + if(file->name){ + strcpy(file->name,""); + } + } + message = openmpt_module_get_metadata(file->mod,"message"); + if(message){ + file->message = malloc(strlen(message)+1); + if(file->message){ + strcpy(file->message,message); + } + openmpt_free_string(message); + message = NULL; + }else{ + file->message = malloc(strlen("")+1); + if(file->message){ + strcpy(file->message,""); + } + } #ifndef LIBOPENMPT_MODPLUG_0_8_7 openmpt_module_set_render_param(file->mod,OPENMPT_MODULE_RENDER_STEREOSEPARATION_PERCENT,file->settings.mStereoSeparation*100/128); #endif @@ -168,9 +196,9 @@ } openmpt_module_destroy(file->mod); file->mod = NULL; - openmpt_free_string(file->name); + free(file->name); file->name = NULL; - openmpt_free_string(file->message); + free(file->message); file->message = NULL; free(file->buf); file->buf = NULL; @@ -423,7 +451,7 @@ LIBOPENMPT_MODPLUG_API char* ModPlug_GetMessage(ModPlugFile* file) { if(!file) return NULL; - return (char*)file->message; + return file->message; } LIBOPENMPT_MODPLUG_API unsigned int ModPlug_NumInstruments(ModPlugFile* file) Modified: trunk/OpenMPT/soundlib/Load_mdl.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_mdl.cpp 2015-05-21 15:39:09 UTC (rev 5134) +++ trunk/OpenMPT/soundlib/Load_mdl.cpp 2015-05-22 18:57:26 UTC (rev 5135) @@ -309,7 +309,7 @@ const uint8 *lpStream = reinterpret_cast<const uint8 *>(file.GetRawData()); DWORD dwMemPos, dwPos, blocklen, dwTrackPos; - MDLInfoBlock *pmib; + const MDLInfoBlock *pmib; UINT i,j, norders = 0, npatterns = 0, ntracks = 0; UINT ninstruments = 0, nsamples = 0; WORD block; @@ -352,7 +352,7 @@ #ifdef MDL_LOG Log("infoblock: %d bytes\n", blocklen); #endif - pmib = (MDLInfoBlock *)(lpStream+dwMemPos); + pmib = (const MDLInfoBlock *)(lpStream+dwMemPos); mpt::String::Read<mpt::String::maybeNullTerminated>(songName, pmib->songname); mpt::String::Read<mpt::String::maybeNullTerminated>(songArtist, pmib->composer); Modified: trunk/OpenMPT/soundlib/Load_med.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_med.cpp 2015-05-21 15:39:09 UTC (rev 5134) +++ trunk/OpenMPT/soundlib/Load_med.cpp 2015-05-22 18:57:26 UTC (rev 5135) @@ -568,11 +568,11 @@ dwSmplArr = BigEndian(pmmh.smplarr); dwExpData = BigEndian(pmmh.expdata); if ((dwExpData) && (dwExpData < dwMemLength - sizeof(MMD0EXP))) - pmex = (MMD0EXP *)(lpStream+dwExpData); + pmex = (const MMD0EXP *)(lpStream+dwExpData); else pmex = NULL; - pmsh = (MMD0SONGHEADER *)(lpStream + dwSong); - pmsh2 = (MMD2SONGHEADER *)pmsh; + pmsh = (const MMD0SONGHEADER *)(lpStream + dwSong); + pmsh2 = (const MMD2SONGHEADER *)pmsh; #ifdef MED_LOG if (version < '2') { @@ -716,7 +716,7 @@ } if ((pseq) && (pseq < dwMemLength - sizeof(MMD2PLAYSEQ))) { - MMD2PLAYSEQ *pmps = (MMD2PLAYSEQ *)(lpStream + pseq); + const MMD2PLAYSEQ *pmps = (const MMD2PLAYSEQ *)(lpStream + pseq); if(songName.empty()) mpt::String::Read<mpt::String::maybeNullTerminated>(songName, pmps->name); uint16 n = BigEndianW(pmps->length); if (pseq+n <= dwMemLength) @@ -816,14 +816,14 @@ { UINT dwPos = BigEndian(pdwTable[iSmp]); if ((dwPos >= dwMemLength) || (dwPos + sizeof(MMDSAMPLEHEADER) >= dwMemLength)) continue; - MMDSAMPLEHEADER *psdh = (MMDSAMPLEHEADER *)(lpStream + dwPos); + const MMDSAMPLEHEADER *psdh = (const MMDSAMPLEHEADER *)(lpStream + dwPos); UINT len = BigEndian(psdh->length); #ifdef MED_LOG Log("SampleData %d: stype=0x%02X len=%d\n", iSmp, BigEndianW(psdh->type), len); #endif if(dwPos + len + 6 > dwMemLength) len = 0; UINT stype = BigEndianW(psdh->type); - char *psdata = (char *)(lpStream + dwPos + 6); + const char *psdata = (const char *)(lpStream + dwPos + 6); SampleIO sampleIO( SampleIO::_8bit, @@ -899,13 +899,13 @@ } } else { - MMD1BLOCK *pmb = (MMD1BLOCK *)(lpStream + dwPos); + const MMD1BLOCK *pmb = (const MMD1BLOCK *)(lpStream + dwPos); #ifdef MED_LOG Log("MMD1BLOCK: lines=%2d, tracks=%2d, offset=0x%04X\n", BigEndianW(pmb->lines), BigEndianW(pmb->numtracks), BigEndian(pmb->info)); #endif - MMD1BLOCKINFO *pbi = NULL; - BYTE *pcmdext = NULL; + const MMD1BLOCKINFO *pbi = NULL; + const BYTE *pcmdext = NULL; lines = (pmb->lines >> 8) + 1; tracks = pmb->numtracks >> 8; if (!tracks) tracks = m_nChannels; @@ -913,7 +913,7 @@ DWORD dwBlockInfo = BigEndian(pmb->info); if ((dwBlockInfo) && (dwBlockInfo < dwMemLength - sizeof(MMD1BLOCKINFO))) { - pbi = (MMD1BLOCKINFO *)(lpStream + dwBlockInfo); + pbi = (const MMD1BLOCKINFO *)(lpStream + dwBlockInfo); #ifdef MED_LOG Log(" BLOCKINFO: blockname=0x%04X namelen=%d pagetable=0x%04X &cmdexttable=0x%04X\n", BigEndian(pbi->blockname), BigEndian(pbi->blocknamelen), BigEndian(pbi->pagetable), BigEndian(pbi->cmdexttable)); @@ -924,7 +924,7 @@ UINT namelen = BigEndian(pbi->blocknamelen); if ((nameofs < dwMemLength) && (namelen < dwMemLength - nameofs)) { - Patterns[iBlk].SetName((char *)(lpStream + nameofs), namelen); + Patterns[iBlk].SetName((const char *)(lpStream + nameofs), namelen); } } if (pbi->cmdexttable) @@ -935,7 +935,7 @@ cmdexttable = BigEndian(*const_unaligned_ptr_le<DWORD>(lpStream + cmdexttable)); if ((cmdexttable) && (cmdexttable <= dwMemLength - lines*tracks)) { - pcmdext = (BYTE *)(lpStream + cmdexttable); + pcmdext = (const BYTE *)(lpStream + cmdexttable); } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |