Skip to content

Commit

Permalink
merged changes from master for build with mingw gcc 9.3 used by ubunt…
Browse files Browse the repository at this point in the history
…u 20.04

SHA-1: 0aead1a

* - test with docker image of ubuntu focal 20.04 LTS (#267)

- "fix" compiler warnings from -Werror=stringop-truncation
  • Loading branch information
chcg committed Oct 3, 2021
1 parent 029b929 commit c49f77f
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 38 deletions.
9 changes: 5 additions & 4 deletions UTCP/include/UTDataSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,6 +26,7 @@ Remove pragma statements
#ifndef UTDATASOURCE_H
#define UTDATASOURCE_H

#include <string>
#include <stdio.h>
#include "utstrlst.h"
#include "utfile.h"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions UTCP/include/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ inline bool isdigit(char c) {
return (c >= '0' && c <= '9');
}

#ifndef _MSC_VER
#include <algorithm>
#define min(a,b) std::min(a,b)
#define max(a,b) std::max(a,b)
#endif
//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
30 changes: 14 additions & 16 deletions UTCP/src/UTDataSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}

/***********************************************
Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 ))
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions UTCP/src/UT_Queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 5 additions & 3 deletions UTCP/src/ftp_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
12 changes: 6 additions & 6 deletions UTCP/src/ut_clnt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();

Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit c49f77f

Please sign in to comment.