OSDN Git Service

[VM][WIN32] Get rid of foo_s() (a.k.a. "SECURE FUNCTIONS"). These have no support...
authorK.Ohta <whatisthis.sowhat@gmail.com>
Sun, 15 Nov 2015 18:15:52 +0000 (03:15 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Sun, 15 Nov 2015 18:15:52 +0000 (03:15 +0900)
source/src/common.cpp
source/src/common.h
source/src/vm/disk.cpp
source/src/vm/disk.h
source/src/vm/mc6809.cpp

index d11c36b..0d60e56 100644 (file)
@@ -6,7 +6,7 @@
 
        [ common ]
 */
-#if defined(_USE_AGAR) || defined(_USE_QT)
+#if defined(_USE_QT)
 #include <string.h>
 #include "common.h"
 #include "config.h"
 
 #include "fileio.h"
 
-
-#ifndef SUPPORT_SECURE_FUNCTIONS
-//errno_t _tfopen_s(FILE** pFile, const _TCHAR *filename, const _TCHAR *mode)
-//{
-//     if((*pFile = _tfopen(filename, mode)) != NULL) {
-//             return 0;
-//     } else {
-//             return errno;
-//     }
-//}
+#if !defined(SUPPORT_SECURE_FUNCTIONS) || defined(Q_OS_WIN)
 errno_t _strcpy_s(char *strDestination, size_t numberOfElements, const char *strSource)
 {
        strcpy(strDestination, strSource);
        return 0;
 }
 
-# if !defined(Q_OS_WIN32)
+int _vsprintf_s(_TCHAR *buffer, size_t sizeOfBuffer, const _TCHAR *format, ...)
+{
+       va_list ap;
+       va_start(ap, format);
+       int result = vsprintf(buffer, format, ap);
+       va_end(ap);
+       return result;
+}
+       
+
+# if !defined(Q_OS_WIN)
 errno_t _tcscpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource)
 {
        _tcscpy(strDestination, strSource);
index 7a8811a..78f8d0c 100644 (file)
@@ -379,13 +379,6 @@ typedef union {
 } pair;
 
 // max/min from WinDef.h
-//#ifndef max
-//#define max(a,b) (((a) > (b)) ? (a) : (b))
-//#endif
-//#ifndef min
-//#define min(a,b) (((a) < (b)) ? (a) : (b))
-//#endif
-
 // rgb color
 #if !defined(_USE_QT)
 #define _RGB888
@@ -458,11 +451,18 @@ typedef char _TCHAR;
 typedef int errno_t;
 #endif
 // secture functions
-#ifndef SUPPORT_SECURE_FUNCTIONS
+#if !defined(SUPPORT_SECURE_FUNCTIONS) || defined(Q_OS_WIN)
 # ifndef errno_t
 typedef int errno_t;
 # endif
-//errno_t _tfopen_s(FILE** pFile, const _TCHAR *filename, const _TCHAR *mode);
+# if defined(Q_OS_WIN)
+#  define strcpy_s _strcpy_s
+#  define tcscpy_s _tcscpy_s
+#  define tcstok_s _tcstok_s
+#  define stprintf_s _stprintf_s
+#  define vstprintf_s _vstprintf_s
+#  define vsprintf_s _vsprintf_s
+# endif
 errno_t _strcpy_s(char *strDestination, size_t numberOfElements, const char *strSource);
 # if !defined(Q_OS_WIN) //&& !defined(Q_OS_CYGWIN)
 errno_t _tcscpy_s(_TCHAR *strDestination, size_t numberOfElements, const _TCHAR *strSource);
@@ -471,7 +471,7 @@ _TCHAR *_tcstok_s(_TCHAR *strToken, const char *strDelimit, _TCHAR **context);
 int _stprintf_s(_TCHAR *buffer, size_t sizeOfBuffer, const _TCHAR *format, ...);
 int _vstprintf_s(_TCHAR *buffer, size_t numberOfElements, const _TCHAR *format, va_list argptr);
 #else
-#define _strcpy_s strcpy_s
+# define _strcpy_s strcpy_s
 #endif
 
 // wav file header
@@ -497,7 +497,6 @@ typedef struct {
 #pragma pack()
 
 
-//#if defined(_USE_SDL) || defined(_USE_AGAR) || defined(_USE_QT)
 // misc
 #ifdef __cplusplus
 bool check_file_extension(const _TCHAR* file_path, const _TCHAR* ext);
index 98f43db..fcddb85 100644 (file)
@@ -1549,7 +1549,8 @@ bool DISK::teledisk_to_d88(FILEIO *fio)
        d88_sct_t d88_sct;
        
        memset(&d88_hdr, 0, sizeof(d88_hdr_t));
-       _strcpy_s(d88_hdr.title, sizeof(d88_hdr.title), "TELEDISK");
+       //_strcpy_s(d88_hdr.title, sizeof(d88_hdr.title), "TELEDISK");
+       strncpy(d88_hdr.title, "TELEDISK", sizeof(d88_hdr.title));
        d88_hdr.protect = 0; // non-protected
        
        file_size.d = 0;
@@ -1682,7 +1683,8 @@ bool DISK::imagedisk_to_d88(FILEIO *fio)
        d88_sct_t d88_sct;
        
        memset(&d88_hdr, 0, sizeof(d88_hdr_t));
-       _strcpy_s(d88_hdr.title, sizeof(d88_hdr.title), "IMAGEDISK");
+       strncpy(d88_hdr.title, "IMAGEDISK", sizeof(d88_hdr.title));
+       //_strcpy_s(d88_hdr.title, sizeof(d88_hdr.title), "IMAGEDISK");
        d88_hdr.protect = 0; // non-protected
        
        file_size.d = 0;
@@ -1885,7 +1887,8 @@ bool DISK::cpdread_to_d88(FILEIO *fio)
        d88_sct_t d88_sct;
        
        memset(&d88_hdr, 0, sizeof(d88_hdr_t));
-       _strcpy_s(d88_hdr.title, sizeof(d88_hdr.title), "CPDREAD");
+       strncpy(d88_hdr.title, "CPDREAD", sizeof(d88_hdr.title));
+       //_strcpy_s(d88_hdr.title, sizeof(d88_hdr.title), "CPDREAD");
        d88_hdr.protect = 0; // non-protected
        
        file_size.d = 0;
@@ -1967,7 +1970,8 @@ bool DISK::solid_to_d88(FILEIO *fio, int type, int ncyl, int nside, int nsec, in
        d88_sct_t d88_sct;
        
        memset(&d88_hdr, 0, sizeof(d88_hdr_t));
-       _strcpy_s(d88_hdr.title, sizeof(d88_hdr.title), "SOLID");
+       strncpy(d88_hdr.title, "SOLID", sizeof(d88_hdr.title));
+       //_strcpy_s(d88_hdr.title, sizeof(d88_hdr.title), "SOLID");
        d88_hdr.protect = 0; // non-protected
        
        file_size.d = 0;
index 802d807..c1997d2 100644 (file)
@@ -14,7 +14,9 @@
 #include "vm.h"
 #include "../emu.h"
 #else
-#include <windows.h>
+# if !defined(_USE_QT)
+#  include <windows.h>
+# endif
 #include "../common.h"
 #endif
 
index b3db887..d21602b 100644 (file)
@@ -1295,7 +1295,9 @@ int MC6809::debug_dasm(uint32 pc, _TCHAR *buffer, size_t buffer_len)
                ops[i] = d_mem_stored->read_data8(pc + i);
        }
        int length = cpu_disassemble_m6809(buffer_tmp, pc, ops, ops);
-       _strcpy_s(buffer, buffer_len, buffer_tmp);
+       //_strcpy_s(buffer, buffer_len, buffer_tmp);
+       memset(buffer_tmp, 0x00, sizeof(buffer_tmp));
+       strncpy(buffer, buffer_tmp, (buffer_len >= 1024) ? 1023 : buffer_len);
        return length;
 }
 #endif