From: <man...@us...> - 2013-05-20 16:39:29
|
Revision: 2149 http://sourceforge.net/p/modplug/code/2149 Author: manxorist Date: 2013-05-20 16:39:22 +0000 (Mon, 20 May 2013) Log Message: ----------- [Ref] Remove c99_snprintf and c99_vsnprintf which confusingly were not 100% c99 compliant. Replace the one single usage site and always zero-terminate strings by hand there. [Fix] Fix 64bit warning in libopenmpt_modplug. [Ref] Silence stupid 64bit warning in ITTools.cpp. Modified Paths: -------------- trunk/OpenMPT/common/mptString.h trunk/OpenMPT/common/typedefs.cpp trunk/OpenMPT/common/typedefs.h trunk/OpenMPT/libopenmpt/libopenmpt_modplug.c trunk/OpenMPT/soundlib/ITTools.cpp Modified: trunk/OpenMPT/common/mptString.h =================================================================== --- trunk/OpenMPT/common/mptString.h 2013-05-20 16:37:28 UTC (rev 2148) +++ trunk/OpenMPT/common/mptString.h 2013-05-20 16:39:22 UTC (rev 2149) @@ -11,6 +11,8 @@ #pragma once #include <string> +#include <cstdio> +#include <stdio.h> #if MPT_COMPILER_GCC || MPT_COMPILER_CLANG #include <strings.h> // for strcasecmp #endif @@ -99,3 +101,9 @@ return strncasecmp(a, b, count); #endif } + + +#if MPT_COMPILER_MSVC +#define snprintf _snprintf +#endif + Modified: trunk/OpenMPT/common/typedefs.cpp =================================================================== --- trunk/OpenMPT/common/typedefs.cpp 2013-05-20 16:37:28 UTC (rev 2148) +++ trunk/OpenMPT/common/typedefs.cpp 2013-05-20 16:39:22 UTC (rev 2149) @@ -57,36 +57,6 @@ #endif -#if MPT_COMPILER_MSVC - -int c99_vsnprintf(char *str, size_t size, const char *format, va_list args) -{ - int ret; - va_list ap; - va_copy(ap, args); - ret = _vsnprintf(str, size, format, ap); - va_end(ap); - if ( ret < 0 ) { - str[size - 1] = '\0'; - ret = size; - } - return ret; -} - - -int c99_snprintf(char *str, size_t size, const char *format, ...) -{ - int ret; - va_list ap; - va_start( ap, format ); - ret = c99_vsnprintf(str, size, format, ap); - va_end( ap ); - return ret; -} - -#endif - - static const std::size_t LOGBUF_SIZE = 1024; static void DoLog(const char *file, int line, const char *function, const char *format, va_list args) @@ -97,6 +67,7 @@ va_list va; va_copy(va, args); vsnprintf(message, LOGBUF_SIZE, format, va); + message[LOGBUF_SIZE - 1] = '\0'; va_end(va); #if defined(MODPLUG_TRACKER) char buf2[LOGBUF_SIZE]; @@ -104,6 +75,7 @@ if(file || function) { snprintf(buf2, LOGBUF_SIZE, "%s(%i): %s", file?file:"", line, message); + buf2[LOGBUF_SIZE - 1] = '\0'; verbose_message = buf2; } else { Modified: trunk/OpenMPT/common/typedefs.h =================================================================== --- trunk/OpenMPT/common/typedefs.h 2013-05-20 16:37:28 UTC (rev 2148) +++ trunk/OpenMPT/common/typedefs.h 2013-05-20 16:39:22 UTC (rev 2149) @@ -281,14 +281,6 @@ //To mark string that should be translated in case of multilingual version. #define GetStrI18N(x) (x) -#include <cstdio> -#include <stdio.h> -#if MPT_COMPILER_MSVC -int c99_vsnprintf(char *str, size_t size, const char *format, va_list args); -int c99_snprintf(char *str, size_t size, const char *format, ...); -#define snprintf c99_snprintf -#endif - #define MULTICHAR4_LE_MSVC(a,b,c,d) static_cast<uint32>( (static_cast<uint8>(a) << 24) | (static_cast<uint8>(b) << 16) | (static_cast<uint8>(c) << 8) | (static_cast<uint8>(d) << 0) ) Modified: trunk/OpenMPT/libopenmpt/libopenmpt_modplug.c =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt_modplug.c 2013-05-20 16:37:28 UTC (rev 2148) +++ trunk/OpenMPT/libopenmpt/libopenmpt_modplug.c 2013-05-20 16:39:22 UTC (rev 2149) @@ -29,6 +29,7 @@ #define LIBOPENMPT_MODPLUG_API #endif +#include <limits.h> #include <math.h> #include <memory.h> #include <stdio.h> @@ -235,11 +236,11 @@ frames = BUFFER_COUNT; } if(file->settings.mChannels==1){ - rendered = openmpt_module_read_mono(file->mod,file->settings.mFrequency,frames,&file->buf[frames*0]); + rendered = (int)openmpt_module_read_mono(file->mod,file->settings.mFrequency,frames,&file->buf[frames*0]); }else if(file->settings.mChannels==2){ - rendered = openmpt_module_read_stereo(file->mod,file->settings.mFrequency,frames,&file->buf[frames*0],&file->buf[frames*1]); + rendered = (int)openmpt_module_read_stereo(file->mod,file->settings.mFrequency,frames,&file->buf[frames*0],&file->buf[frames*1]); }else if(file->settings.mChannels==4){ - rendered = openmpt_module_read_quad(file->mod,file->settings.mFrequency,frames,&file->buf[frames*0],&file->buf[frames*1],&file->buf[frames*2],&file->buf[frames*3]); + rendered = (int)openmpt_module_read_quad(file->mod,file->settings.mFrequency,frames,&file->buf[frames*0],&file->buf[frames*1],&file->buf[frames*2],&file->buf[frames*3]); }else{ return 0; } @@ -486,6 +487,7 @@ { const char* str; unsigned int retval; + size_t tmpretval; if(!file) return 0; str = openmpt_module_get_sample_name(file->mod,qual-1); if(!str){ @@ -494,10 +496,14 @@ } return 0; } + tmpretval = strlen(str); + if(tmpretval>=INT_MAX){ + tmpretval = INT_MAX-1; + } + retval = (int)tmpretval; if(buff){ - strcpy(buff,str); + strncpy(buff,str,retval+1); } - retval = strlen(str); openmpt_free_string(str); return retval; } @@ -506,6 +512,7 @@ { const char* str; unsigned int retval; + size_t tmpretval; if(!file) return 0; str = openmpt_module_get_instrument_name(file->mod,qual-1); if(!str){ @@ -514,10 +521,14 @@ } return 0; } + tmpretval = strlen(str); + if(tmpretval>=INT_MAX){ + tmpretval = INT_MAX-1; + } + retval = (int)tmpretval; if(buff){ - strcpy(buff,str); + strncpy(buff,str,retval+1); } - retval = strlen(str); openmpt_free_string(str); return retval; } Modified: trunk/OpenMPT/soundlib/ITTools.cpp =================================================================== --- trunk/OpenMPT/soundlib/ITTools.cpp 2013-05-20 16:37:28 UTC (rev 2148) +++ trunk/OpenMPT/soundlib/ITTools.cpp 2013-05-20 16:39:22 UTC (rev 2149) @@ -177,7 +177,7 @@ mptIns.VolEnv.nNodes = 25; // Volume Envelope Data - for(size_t i = 0; i < 25; i++) + for(uint32 i = 0; i < 25; i++) { if((mptIns.VolEnv.Ticks[i] = nodes[i * 2]) == 0xFF) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |