From c49f77f7ba372ba781e6ccae4d74197abd2a4851 Mon Sep 17 00:00:00 2001 From: Christian Grasser Date: Sun, 3 Oct 2021 20:49:21 +0200 Subject: [PATCH] merged changes from master for build with mingw gcc 9.3 used by ubuntu 20.04 SHA-1: 0aead1a75bfeb4805d4c700e9f166f3b34113f35 * - test with docker image of ubuntu focal 20.04 LTS (#267) - "fix" compiler warnings from -Werror=stringop-truncation --- UTCP/include/UTDataSource.h | 9 +++++---- UTCP/include/stdafx.h | 6 ++---- UTCP/src/UTDataSource.cpp | 30 ++++++++++++++---------------- UTCP/src/UT_Queue.cpp | 8 ++++---- UTCP/src/ftp_c.cpp | 8 +++++--- UTCP/src/ut_clnt.cpp | 12 ++++++------ appveyor.yml | 2 +- 7 files changed, 37 insertions(+), 38 deletions(-) diff --git a/UTCP/include/UTDataSource.h b/UTCP/include/UTDataSource.h index 749084f..7c78eaa 100644 --- a/UTCP/include/UTDataSource.h +++ b/UTCP/include/UTDataSource.h @@ -10,7 +10,7 @@ // ================================================================= // Ultimate TCP/IP v4.2 // This software along with its related components, documentation and files ("The Libraries") -// is © 1994-2007 The Code Project (1612916 Ontario Limited) and use of The Libraries is +// is © 1994-2007 The Code Project (1612916 Ontario Limited) and use of The Libraries is // governed by a software license agreement ("Agreement"). Copies of the Agreement are // available at The Code Project (www.codeproject.com), as part of the package you downloaded // to obtain this file, or directly from our office. For a copy of the license governing @@ -26,6 +26,7 @@ Remove pragma statements #ifndef UTDATASOURCE_H #define UTDATASOURCE_H +#include #include #include "utstrlst.h" #include "utfile.h" @@ -134,9 +135,9 @@ class CUT_BufferDataSource : public CUT_DataSource { // v4.2 changed to size_t size_t m_nSize; // Buffer or data size size_t m_nDataSize; // Buffer or data size - char m_szName[MAX_PATH+1]; // Datasource name + std::string m_szName; // Datasource name size_t m_nCurPosition; // Current reading/writing position - BOOL m_bCleanUp; // TRUE if we need to cleen up the buffer ourselfs + BOOL m_bCleanUp; // TRUE if we need to clean up the buffer ourselfs public: // v4.2 buffer sizes changed to size_t @@ -178,7 +179,7 @@ class CUT_BufferDataSource : public CUT_DataSource { class CUT_MapFileDataSource : public CUT_DataSource { protected: _TCHAR m_szFileName[MAX_PATH + 1]; // File name - char m_szName[MAX_PATH + 1]; // Datasource name + std::string m_szName; // Datasource name HANDLE m_hFile; // File handle HANDLE m_hMapFile; // File map handle diff --git a/UTCP/include/stdafx.h b/UTCP/include/stdafx.h index 5449a3d..d871ec1 100644 --- a/UTCP/include/stdafx.h +++ b/UTCP/include/stdafx.h @@ -9,8 +9,6 @@ inline bool isdigit(char c) { return (c >= '0' && c <= '9'); } -#ifndef _MSC_VER #include -#define min(a,b) std::min(a,b) -#define max(a,b) std::max(a,b) -#endif \ No newline at end of file +//avoid issues with std::min and std::max and ms compilers +//see https://stackoverflow.com/questions/5004858/why-is-stdmin-failing-when-windows-h-is-included diff --git a/UTCP/src/UTDataSource.cpp b/UTCP/src/UTDataSource.cpp index eecff7b..fcb3f27 100644 --- a/UTCP/src/UTDataSource.cpp +++ b/UTCP/src/UTDataSource.cpp @@ -11,7 +11,7 @@ //================================================================= // Ultimate TCP/IP v4.2 // This software along with its related components, documentation and files ("The Libraries") -// is © 1994-2007 The Code Project (1612916 Ontario Limited) and use of The Libraries is +// is © 1994-2007 The Code Project (1612916 Ontario Limited) and use of The Libraries is // governed by a software license agreement ("Agreement"). Copies of the Agreement are // available at The Code Project (www.codeproject.com), as part of the package you downloaded // to obtain this file, or directly from our office. For a copy of the license governing @@ -432,9 +432,9 @@ CUT_BufferDataSource::CUT_BufferDataSource(LPSTR buffer, size_t size, LPCSTR nam m_lpszBuffer = buffer; // Remember the buffer name - m_szName[0] = 0; - if(name) - strncpy(m_szName, name, MAX_PATH); + if(name) { + m_szName = name; + } } /*********************************************** @@ -450,7 +450,7 @@ CUT_DataSource * CUT_BufferDataSource::clone() char *buffer = new char[m_nSize + 1]; memcpy(buffer, m_lpszBuffer, m_nSize); *(buffer + m_nSize) = 0; - CUT_BufferDataSource *ptr = new CUT_BufferDataSource(buffer, m_nSize, m_szName); + CUT_BufferDataSource *ptr = new CUT_BufferDataSource(buffer, m_nSize, m_szName.c_str()); ptr->m_bCleanUp = TRUE; ptr->m_nDataSize = m_nDataSize; return ptr; @@ -559,7 +559,7 @@ int CUT_BufferDataSource::WriteLine(LPCSTR buffer) { // Write line to the buffer int rt = 0; size_t len = strlen(buffer); - size_t nBytesNumber = min(len, (m_nSize - m_nCurPosition)); + size_t nBytesNumber = (std::min)(len, (m_nSize - m_nCurPosition)); if(len > 0) if((rt = Write(buffer, (unsigned int)nBytesNumber)) == -1) @@ -588,7 +588,7 @@ int CUT_BufferDataSource::Read(LPSTR buffer, size_t count) { if(buffer == NULL) return -1; // Read data from the buffer - int nBytesNumber = (int)min( count, (m_nDataSize - m_nCurPosition)); + int nBytesNumber = (int)(std::min)( count, (m_nDataSize - m_nCurPosition)); memcpy(buffer, (m_lpszBuffer + m_nCurPosition), nBytesNumber); buffer[nBytesNumber] = 0; m_nCurPosition += nBytesNumber; @@ -611,7 +611,7 @@ int CUT_BufferDataSource::Write(LPCSTR buffer, size_t count) { if(buffer == NULL) return -1; // Write data to the buffer - unsigned int nBytesNumber = (unsigned int)min(count, (m_nSize - m_nCurPosition)); + unsigned int nBytesNumber = (unsigned int)(std::min)(count, (m_nSize - m_nCurPosition)); memcpy((m_lpszBuffer + m_nCurPosition), buffer, nBytesNumber); m_nCurPosition += nBytesNumber; m_lpszBuffer[m_nCurPosition] = 0; @@ -695,10 +695,8 @@ CUT_MapFileDataSource::CUT_MapFileDataSource(DWORD SizeHigh, DWORD SizeLow, LPCS m_lnActualSize = m_lnSize; // Initialize data source name - m_szName[0] = 0; if(name != NULL) { - strncpy(m_szName, name,MAX_PATH); - m_szName[MAX_PATH] = 0; + m_szName = name; } // Initialize map file name @@ -727,7 +725,7 @@ clone CUT_DataSource * CUT_MapFileDataSource::clone() { // Create object - CUT_MapFileDataSource *ptrNewDataSource = new CUT_MapFileDataSource(m_lnActualSize.HighPart, m_lnActualSize.LowPart, m_szName, (m_hFile == INVALID_HANDLE_VALUE) ? m_szFileName : NULL ); + CUT_MapFileDataSource *ptrNewDataSource = new CUT_MapFileDataSource(m_lnActualSize.HighPart, m_lnActualSize.LowPart, m_szName.c_str(), (m_hFile == INVALID_HANDLE_VALUE) ? m_szFileName : NULL ); // Copy the data if nessesary if(m_hMapFile != NULL && m_lpMapAddress) @@ -811,7 +809,7 @@ int CUT_MapFileDataSource::Open(OpenMsgType type) m_lnActualSize.QuadPart = m_lnSize.QuadPart; // Initialize increment value. Size divided by 8 ( or shifted by 3) - m_lnIncrement.QuadPart = max(Int64ShraMod32(m_lnSize.QuadPart, 3), LONGLONG(4096)); + m_lnIncrement.QuadPart = (std::max)(Int64ShraMod32(m_lnSize.QuadPart, 3), LONGLONG(4096)); // If file is opened in append mode - increase it size if(type == UTM_OM_APPEND || (type == UTM_OM_WRITING && m_lnSize.HighPart == 0 && m_lnSize.LowPart == 0 )) @@ -981,7 +979,7 @@ int CUT_MapFileDataSource::Read(LPSTR buffer, size_t count) // Calculate number of bytes to read lnDiff.QuadPart = m_lnActualSize.QuadPart - m_lnPosition.QuadPart; - lnBytesToRead.QuadPart = min(lnBufferSize.QuadPart, lnDiff.QuadPart); + lnBytesToRead.QuadPart = (std::min)(lnBufferSize.QuadPart, lnDiff.QuadPart); // Read data if(lnBytesToRead.QuadPart > 0) { @@ -1029,7 +1027,7 @@ int CUT_MapFileDataSource::Write(LPCSTR buffer, size_t count) { m_bTempFileName = FALSE; // Increase buffer size - m_lnActualSize.QuadPart = m_lnSize.QuadPart + max(m_lnIncrement.QuadPart, lnDataSize.QuadPart+100); + m_lnActualSize.QuadPart = m_lnSize.QuadPart + (std::max)(m_lnIncrement.QuadPart, lnDataSize.QuadPart+100); // Reopen int rt = Open(m_OpenType); @@ -1047,7 +1045,7 @@ int CUT_MapFileDataSource::Write(LPCSTR buffer, size_t count) { // Write data memcpy((m_lpMapAddress + m_lnPosition.QuadPart), buffer, count); m_lnPosition.QuadPart += count; - m_lnActualSize.QuadPart = max(m_lnActualSize.QuadPart, m_lnPosition.QuadPart); + m_lnActualSize.QuadPart = (std::max)(m_lnActualSize.QuadPart, m_lnPosition.QuadPart); *(m_lpMapAddress + m_lnPosition.QuadPart) = 0; return (int)count; diff --git a/UTCP/src/UT_Queue.cpp b/UTCP/src/UT_Queue.cpp index 2289807..fd0f2b3 100644 --- a/UTCP/src/UT_Queue.cpp +++ b/UTCP/src/UT_Queue.cpp @@ -10,7 +10,7 @@ //================================================================= // Ultimate TCP/IP v4.2 // This software along with its related components, documentation and files ("The Libraries") -// is © 1994-2007 The Code Project (1612916 Ontario Limited) and use of The Libraries is +// is © 1994-2007 The Code Project (1612916 Ontario Limited) and use of The Libraries is // governed by a software license agreement ("Agreement"). Copies of the Agreement are // available at The Code Project (www.codeproject.com), as part of the package you downloaded // to obtain this file, or directly from our office. For a copy of the license governing @@ -137,7 +137,7 @@ Read ************************************************/ int CUT_FIFO_Queue::Read(LPBYTE pbBuffer, unsigned int count) { - int nNumToRead = min(GetDataSize(), (int)count); + int nNumToRead = (std::min)(GetDataSize(), (int)count); int nNumRead = 0; if(m_iReadPointer + nNumToRead > m_cbBuffer) { @@ -172,7 +172,7 @@ Peek int CUT_FIFO_Queue::Peek(LPBYTE pbBuffer, unsigned int count) { int iReadPointer = m_iReadPointer; - int nNumToRead = min(GetDataSize(), (int)count); + int nNumToRead = (std::min)(GetDataSize(), (int)count); int nNumRead = 0; if(iReadPointer + nNumToRead > m_cbBuffer) { @@ -205,7 +205,7 @@ Write ************************************************/ int CUT_FIFO_Queue::Write(LPBYTE pbBuffer, unsigned int count) { - int nNumToWrite = min(GetFreeSize(), (int)count); + int nNumToWrite = (std::min)(GetFreeSize(), (int)count); int nNumWritten = 0; if(m_iWritePointer + nNumToWrite > m_cbBuffer) { diff --git a/UTCP/src/ftp_c.cpp b/UTCP/src/ftp_c.cpp index ed29971..b561d20 100644 --- a/UTCP/src/ftp_c.cpp +++ b/UTCP/src/ftp_c.cpp @@ -2815,7 +2815,7 @@ void CUT_FTPClient::GetInfoInDOSFormat( CUT_DIRINFOA * di){ ++ loop; } else if(nSpaces == 3) { - strncpy(di->fileName, &m_szBuf[loop], sizeof(di->fileName)); + strncpy(di->fileName, &m_szBuf[loop], sizeof(di->fileName)-1); break; } else @@ -2852,6 +2852,8 @@ void CUT_FTPClient::GetInfoInDOSFormat( CUT_DIRINFOA * di){ CUT_StrMethods::ParseString(m_szBuf," ",0,dateBuf,sizeof(dateBuf)); strncpy(dateBuf, &dateBuf[6],2); + dateBuf[2] = '\0'; + int temp = atoi(dateBuf); if( 70 > temp) temp+= 100; @@ -2915,7 +2917,7 @@ void CUT_FTPClient::GetInfoInUNIXFormat( CUT_DIRINFOA * di){ } else if(nSpaces == 8 +linksIncluded) { - strncpy(di->fileName, &m_szBuf[loop], sizeof(di->fileName)); + strncpy(di->fileName, &m_szBuf[loop], sizeof(di->fileName)-1); break; } else @@ -3243,7 +3245,7 @@ int CUT_FTPClient::SocketOnConnected(SOCKET /*s*/, const char * /*lpszName*/){ bool performAuth = (m_sMode == FTPES); bool performProt = (m_sMode != FTP); - m_dataSecLevel = performProt?1:0; //do not call the function yet, let FTPConnecth andle that after authentication + m_dataSecLevel = performProt?1:0; //do not call the function yet, let FTPConnect handle that after authentication if (m_sMode == FTPS) { //just connect ssl rt = ConnectSSL(); diff --git a/UTCP/src/ut_clnt.cpp b/UTCP/src/ut_clnt.cpp index 6dd860f..e9919bf 100644 --- a/UTCP/src/ut_clnt.cpp +++ b/UTCP/src/ut_clnt.cpp @@ -14,7 +14,7 @@ // =================================================================== // Ultimate TCP/IP v4.2 // This software along with its related components, documentation and files ("The Libraries") -// is © 1994-2007 The Code Project (1612916 Ontario Limited) and use of The Libraries is +// is © 1994-2007 The Code Project (1612916 Ontario Limited) and use of The Libraries is // governed by a software license agreement ("Agreement"). Copies of the Agreement are // available at The Code Project (www.codeproject.com), as part of the package you downloaded // to obtain this file, or directly from our office. For a copy of the license governing @@ -146,7 +146,7 @@ int CUT_WSClient::Connect(unsigned int port, LPCSTR address, long timeout, int f return OnError(UTE_INVALID_ADDRESS); } else - strncpy(m_szAddress, address, sizeof(m_szAddress)); + strncpy(m_szAddress, address, sizeof(m_szAddress)-1); m_nFamily = family; m_nSockType = sockType; @@ -252,7 +252,7 @@ int CUT_WSClient::ConnectBound(unsigned int localPort,unsigned int remotePort, return OnError(UTE_SOCK_ALREADY_OPEN); //copy the params - strncpy(m_szAddress, remoteAddress, sizeof(m_szAddress)); + strncpy(m_szAddress, remoteAddress, sizeof(m_szAddress)-1); m_nFamily = family; m_nSockType = sockType; @@ -1553,7 +1553,7 @@ int CUT_WSClient::Receive(CUT_DataSource & dest, OpenMsgType type, int timeOut, } if(lMaxToReceive > 0) { - nSize = min((long)sizeof(data), lMaxToReceive - bytesReceived); + nSize = (std::min)((long)sizeof(data), lMaxToReceive - bytesReceived); if(nSize == 0) break; } @@ -1624,7 +1624,7 @@ int CUT_WSClient::Receive(CUT_Queue & dest, int timeOut, long lMaxToReceive){ //we cannot receive more than the free size of the queue if(lMaxToReceive > 0) - lMaxToReceive = min(lMaxToReceive, (long)dest.GetFreeSize()); + lMaxToReceive = (std::min)(lMaxToReceive, (long)dest.GetFreeSize()); else lMaxToReceive = dest.GetFreeSize(); @@ -1637,7 +1637,7 @@ int CUT_WSClient::Receive(CUT_Queue & dest, int timeOut, long lMaxToReceive){ } } - nSize = min((long)sizeof(data), lMaxToReceive - bytesReceived); + nSize = (std::min)((long)sizeof(data), lMaxToReceive - bytesReceived); if(nSize == 0) break; diff --git a/appveyor.yml b/appveyor.yml index f54cae6..23854f9 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -51,7 +51,7 @@ before_build: build_script: - cd "%APPVEYOR_BUILD_FOLDER%" # Python 3 needed for python build_3rdparty.py - - set PATH=C:\Python37-x64;C:\Python37-x64\Scripts;%PATH% + - set PATH=C:\Python38-x64;C:\Python38-x64\Scripts;%PATH% - mkdir _build - cd _build