Revision: 9464 https://osdn.net/projects/ttssh2/scm/svn/commits/9464 Author: zmatsuo Date: 2021-10-14 23:51:19 +0900 (Thu, 14 Oct 2021) Log Message: ----------- printf系関数にアトリビュートを追加 - 引数誤りをチェックできるよう attribute を追加 - コメントの誤りを修正 - _Printf_format_string_ を追加 - Visual Studioでビルドするときのみ有効 Modified Paths: -------------- trunk/teraterm/common/asprintf.cpp trunk/teraterm/common/asprintf.h trunk/teraterm/common/ttlib.h -------------- next part -------------- Modified: trunk/teraterm/common/asprintf.cpp =================================================================== --- trunk/teraterm/common/asprintf.cpp 2021-10-14 14:51:10 UTC (rev 9463) +++ trunk/teraterm/common/asprintf.cpp 2021-10-14 14:51:19 UTC (rev 9464) @@ -34,11 +34,16 @@ #include "asprintf.h" +// Visual Studio \x82ł͂Ȃ\xA2\x8E\x9E\x81A\x96\xB3\x8C\xF8\x89\xBB(\x8F\xC1\x82\xB7) +#if !defined(_MSC_VER) +#define _Printf_format_string_ +#endif + /** * \x97̈\xE6\x82\xF0\x8Am\x95ۂ\xB5\x82āA\x95\xB6\x8E\x9A\x97\xF1\x82\xF0\x83t\x83H\x81[\x83}\x83b\x83g\x82\xB5\x82āA\x83|\x83C\x83\x93\x83^\x95Ԃ\xB7 * \x95s\x97v\x82ɂȂ\xC1\x82\xBD\x82\xE7 free() \x82\xB7\x82邱\x82\xC6 * @retval \x8Fo\x97͕\xB6\x8E\x9A\x90\x94(\x8FI\x92[\x82\xCC'\0'\x82\xF0\x8A܂\xDE) - * \x83G\x83\x89\x81[\x8E\x9E\x82\xCD -1 + * \x83G\x83\x89\x81[\x8E\x9E -1 */ int vasprintf(char **strp, const char *fmt, va_list ap) { @@ -72,8 +77,7 @@ * \x97̈\xE6\x82\xF0\x8Am\x95ۂ\xB5\x82āA\x95\xB6\x8E\x9A\x97\xF1\x82\xF0\x83t\x83H\x81[\x83}\x83b\x83g\x82\xB5\x82āA\x83|\x83C\x83\x93\x83^\x95Ԃ\xB7 * \x95s\x97v\x82ɂȂ\xC1\x82\xBD\x82\xE7 free() \x82\xB7\x82邱\x82\xC6 * @retval \x8Fo\x97͕\xB6\x8E\x9A\x90\x94(\x8FI\x92[\x82\xCCL'\0'\x82\xF0\x8A܂\xDE) - * \x83t\x83H\x81[\x83}\x83b\x83g\x95\xB6\x8E\x9A\x97\xA8\x82\xA9\x82\xB5\x82\xA2\x82Ƃ\xAB\x82\xCDL"EILSEQ" - * \x82\xBB\x82̑\xBC\x83G\x83\x89\x81[\x8E\x9E\x82\xCD -1 + * \x83G\x83\x89\x81[\x8E\x9E -1 */ int vaswprintf(wchar_t **strp, const wchar_t *fmt, va_list ap) { @@ -107,10 +111,9 @@ * \x97̈\xE6\x82\xF0\x8Am\x95ۂ\xB5\x82āA\x95\xB6\x8E\x9A\x97\xF1\x82\xF0\x83t\x83H\x81[\x83}\x83b\x83g\x82\xB5\x82āA\x83|\x83C\x83\x93\x83^\x95Ԃ\xB7 * \x95s\x97v\x82ɂȂ\xC1\x82\xBD\x82\xE7 free() \x82\xB7\x82邱\x82\xC6 * @retval \x8Fo\x97͕\xB6\x8E\x9A\x90\x94(\x8FI\x92[\x82\xCC'\0'\x82\xF0\x8A܂\xDE) - * \x83t\x83H\x81[\x83}\x83b\x83g\x95\xB6\x8E\x9A\x97\xA8\x82\xA9\x82\xB5\x82\xA2\x82Ƃ\xAB\x82\xCD"EILSEQ" - * \x82\xBB\x82̑\xBC\x83G\x83\x89\x81[\x8E\x9E\x82\xCD -1 + * \x83G\x83\x89\x81[\x8E\x9E -1 */ -int asprintf(char **strp, const char *fmt, ...) +int asprintf(char **strp, _Printf_format_string_ const char *fmt, ...) { int r; va_list ap; @@ -124,10 +127,9 @@ * \x97̈\xE6\x82\xF0\x8Am\x95ۂ\xB5\x82āA\x95\xB6\x8E\x9A\x97\xF1\x82\xF0\x83t\x83H\x81[\x83}\x83b\x83g\x82\xB5\x82āA\x83|\x83C\x83\x93\x83^\x95Ԃ\xB7 * \x95s\x97v\x82ɂȂ\xC1\x82\xBD\x82\xE7 free() \x82\xB7\x82邱\x82\xC6 * @retval \x8Fo\x97͕\xB6\x8E\x9A\x90\x94(\x8FI\x92[\x82\xCC'\0'\x82\xF0\x8A܂\xDE) - * \x83t\x83H\x81[\x83}\x83b\x83g\x95\xB6\x8E\x9A\x97\xA8\x82\xA9\x82\xB5\x82\xA2\x82Ƃ\xAB\x82\xCDL"EILSEQ" - * \x82\xBB\x82̑\xBC\x83G\x83\x89\x81[\x8E\x9E\x82\xCD -1 + * \x83G\x83\x89\x81[\x8E\x9E -1 */ -int aswprintf(wchar_t **strp, const wchar_t *fmt, ...) +int aswprintf(wchar_t **strp, _Printf_format_string_ const wchar_t *fmt, ...) { int r; va_list ap; Modified: trunk/teraterm/common/asprintf.h =================================================================== --- trunk/teraterm/common/asprintf.h 2021-10-14 14:51:10 UTC (rev 9463) +++ trunk/teraterm/common/asprintf.h 2021-10-14 14:51:19 UTC (rev 9464) @@ -34,8 +34,21 @@ extern "C" { #endif +#if defined(_MSC_VER) && !defined(_Printf_format_string_) +// \x92\xE8\x8B`\x82\xB3\x82\xEA\x82Ă\xA2\x82Ȃ\xA2\x82Ƃ\xAB\x82͉\xBD\x82\xE0\x82\xB5\x82Ȃ\xA2\x82悤\x82ɒ\xE8\x8B`\x82\xB5\x82Ă\xA8\x82\xAD +#define _Printf_format_string_ +#endif + +#if defined(_MSC_VER) +int asprintf(char **strp, _Printf_format_string_ const char *fmt, ...); +int aswprintf(wchar_t **strp, _Printf_format_string_ const wchar_t *fmt, ...); +#elif defined(__GNUC__) +int asprintf(char **strp, const char *fmt, ...) __attribute__ ((format (printf, 2, 3))); +int aswprintf(wchar_t **strp, const wchar_t *fmt, ...); // __attribute__ ((format (wprintf, 2, 3))); +#else int asprintf(char **strp, const char *fmt, ...); int aswprintf(wchar_t **strp, const wchar_t *fmt, ...); +#endif int vasprintf(char **strp, const char *fmt, va_list ap); int vaswprintf(wchar_t **strp, const wchar_t *fmt, va_list ap); Modified: trunk/teraterm/common/ttlib.h =================================================================== --- trunk/teraterm/common/ttlib.h 2021-10-14 14:51:10 UTC (rev 9463) +++ trunk/teraterm/common/ttlib.h 2021-10-14 14:51:19 UTC (rev 9464) @@ -41,6 +41,11 @@ #define DllExport __declspec(dllexport) #endif +#if defined(_MSC_VER) && !defined(_Printf_format_string_) +// \x92\xE8\x8B`\x82\xB3\x82\xEA\x82Ă\xA2\x82Ȃ\xA2\x82Ƃ\xAB\x82͉\xBD\x82\xE0\x82\xB5\x82Ȃ\xA2\x82悤\x82ɒ\xE8\x8B`\x82\xB5\x82Ă\xA8\x82\xAD +#define _Printf_format_string_ +#endif + BOOL GetFileNamePos(const char *PathName, int *DirLen, int *FNPos); BOOL GetFileNamePosU8(const char *PathName, int *DirLen, int *FNPos); BOOL GetFileNamePosW(const wchar_t *PathName, size_t *DirLen, size_t *FNPos); @@ -97,8 +102,16 @@ int get_lang_font(const char *key, HWND dlg, PLOGFONT logfont, HFONT *font, const char *iniFile); DllExport BOOL doSelectFolder(HWND hWnd, char *path, int pathlen, const char *def, const char *msg); BOOL doSelectFolderW(HWND hWnd, const wchar_t *def, const wchar_t *msg, wchar_t **folder); +#if defined(_MSC_VER) +DllExport void OutputDebugPrintf(_Printf_format_string_ const char *fmt, ...); +void OutputDebugPrintfW(_Printf_format_string_ const wchar_t *fmt, ...); +#elif defined(__GNUC__) +DllExport void OutputDebugPrintf(_Printf_format_string_ const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); +void OutputDebugPrintfW(const wchar_t *fmt, ...); // __attribute__ ((format (wprintf, 1, 2))); +#else DllExport void OutputDebugPrintf(const char *fmt, ...); void OutputDebugPrintfW(const wchar_t *fmt, ...); +#endif void OutputDebugHexDump(const void *data, size_t len); DllExport DWORD get_OPENFILENAME_SIZEA(); DllExport DWORD get_OPENFILENAME_SIZEW();