avoid risky c style string functions
This commit is contained in:
@ -536,7 +536,7 @@ printf("r = %d, left = %d, bufleft = %d\n", r, left, bufleft);
|
||||
#else
|
||||
// int ires = SJIS2UTF8N(sjis,buf,bufleft);
|
||||
int nBytesOut;
|
||||
strcpy(buf,(const char *)CUnicodeF::sjis_to_euc((const unsigned char *)sjis/*, &nBytesOut*/));
|
||||
strncpy(buf, sizeof(buf) -1, (const char *)CUnicodeF::sjis_to_euc((const unsigned char *)sjis/*, &nBytesOut*/));
|
||||
// QTextCodec* codec = QTextCodec::codecForName("eucJP");
|
||||
// data3.text = codec->toUnicode(buf);
|
||||
#endif
|
||||
|
@ -281,8 +281,8 @@ public:
|
||||
if (value && value[0] != '\0') {
|
||||
double ret;
|
||||
if (strchr(value, ',') != NULL) {
|
||||
char* tmp = new char[strlen(value)+1];
|
||||
strcpy(tmp, value);
|
||||
char* tmp = new char[strnlen(value, 20)+1];
|
||||
strncpy(tmp, value, 20);
|
||||
DL_WriterA::strReplace(tmp, ',', '.');
|
||||
ret = atof(tmp);
|
||||
delete[] tmp;
|
||||
|
@ -75,7 +75,7 @@ void DRW_TextCodec::setVersion(const std::string &v, bool dxfFormat){
|
||||
version = DRW::UNKNOWNV;
|
||||
for ( auto it = DRW::dwgVersionStrings.begin(); it != DRW::dwgVersionStrings.end(); ++it )
|
||||
{
|
||||
if ( std::strcmp( v.c_str(), it->first ) == 0 ) {
|
||||
if ( std::strncmp( v.c_str(), it->first, 32) == 0 ) {
|
||||
version = it->second;
|
||||
setVersion( it->second, dxfFormat);
|
||||
break;
|
||||
|
@ -237,7 +237,7 @@ bool dwgR::openFile(std::ifstream *filestr){
|
||||
version = DRW::UNKNOWNV;
|
||||
for ( auto it = DRW::dwgVersionStrings.begin(); it != DRW::dwgVersionStrings.end(); ++it )
|
||||
{
|
||||
if ( strcmp( line, it->first ) == 0 ) {
|
||||
if ( strncmp( line, it->first, 32) == 0 ) {
|
||||
version = it->second;
|
||||
break;
|
||||
}
|
||||
|
@ -85,7 +85,7 @@ bool dxfRW::read(DRW_Interface *interface_, bool ext){
|
||||
filestr.close();
|
||||
iface = interface_;
|
||||
DRW_DBG("dxfRW::read 2\n");
|
||||
if (strcmp(line, line2) == 0) {
|
||||
if (strncmp(line, line2, 21) == 0) {
|
||||
filestr.open (fileName.c_str(), std::ios_base::in | std::ios::binary);
|
||||
binFile = true;
|
||||
//skip sentinel
|
||||
|
@ -1704,10 +1704,10 @@ char* RS_FilterDXF1::getBufLineCh() {
|
||||
|
||||
// Copy buffer from a given string:
|
||||
//
|
||||
void RS_FilterDXF1::copyBufFrom(const char* _buf) {
|
||||
void RS_FilterDXF1::copyBufFrom(const char* _buf, int length) {
|
||||
if(_buf) {
|
||||
fBuf = new char[strlen(_buf)+16];
|
||||
strcpy(fBuf, _buf);
|
||||
fBuf = new char[strnlen(_buf, length-1)+16];
|
||||
strncpy(fBuf, _buf, length);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,7 @@ public:
|
||||
void setFSize(unsigned _s) {
|
||||
fSize=_s;
|
||||
}
|
||||
void copyBufFrom(const char* _buf);
|
||||
void copyBufFrom(const char* _buf, int length);
|
||||
bool gotoBufLine(char* _lstr);
|
||||
bool gotoBufLineString(char* _lstr);
|
||||
|
||||
|
@ -274,8 +274,8 @@ static int DBFFlushRecord( DBFHandle psDBF )
|
||||
psDBF->nRecordLength,
|
||||
1, psDBF->fp ) != 1 )
|
||||
{
|
||||
char szMessage[128];
|
||||
sprintf( szMessage, "Failure writing DBF record %d.",
|
||||
char szMessage[128] = {};
|
||||
snprintf( szMessage, 127, "Failure writing DBF record %d.",
|
||||
psDBF->nCurrentRecord );
|
||||
psDBF->sHooks.Error( szMessage );
|
||||
return FALSE;
|
||||
@ -304,8 +304,8 @@ static int DBFLoadRecord( DBFHandle psDBF, int iRecord )
|
||||
|
||||
if( psDBF->sHooks.FSeek( psDBF->fp, nRecordOffset, SEEK_SET ) != 0 )
|
||||
{
|
||||
char szMessage[128];
|
||||
sprintf( szMessage, "fseek(%ld) failed on DBF file.\n",
|
||||
char szMessage[128] = {};
|
||||
snprintf( szMessage, 127, "fseek(%ld) failed on DBF file.\n",
|
||||
(long) nRecordOffset );
|
||||
psDBF->sHooks.Error( szMessage );
|
||||
return FALSE;
|
||||
@ -314,8 +314,8 @@ static int DBFLoadRecord( DBFHandle psDBF, int iRecord )
|
||||
if( psDBF->sHooks.FRead( psDBF->pszCurrentRecord,
|
||||
psDBF->nRecordLength, 1, psDBF->fp ) != 1 )
|
||||
{
|
||||
char szMessage[128];
|
||||
sprintf( szMessage, "fread(%d) failed on DBF file.\n",
|
||||
char szMessage[128] = {};
|
||||
snprintf( szMessage, 127, "fread(%d) failed on DBF file.\n",
|
||||
psDBF->nRecordLength );
|
||||
psDBF->sHooks.Error( szMessage );
|
||||
return FALSE;
|
||||
@ -393,24 +393,24 @@ DBFOpenLL( const char * pszFilename, const char * pszAccess, SAHooks *psHooks )
|
||||
/* -------------------------------------------------------------------- */
|
||||
/* We only allow the access strings "rb" and "r+". */
|
||||
/* -------------------------------------------------------------------- */
|
||||
if( strcmp(pszAccess,"r") != 0 && strcmp(pszAccess,"r+") != 0
|
||||
&& strcmp(pszAccess,"rb") != 0 && strcmp(pszAccess,"rb+") != 0
|
||||
&& strcmp(pszAccess,"r+b") != 0 )
|
||||
if( strncmp(pszAccess,"r", 2) != 0 && strncmp(pszAccess,"r+", 3) != 0
|
||||
&& strncmp(pszAccess,"rb", 3) != 0 && strncmp(pszAccess,"rb+", 4) != 0
|
||||
&& strncmp(pszAccess,"r+b", 4) != 0 )
|
||||
return( NULL );
|
||||
|
||||
if( strcmp(pszAccess,"r") == 0 )
|
||||
if( strncmp(pszAccess,"r", 2) == 0 )
|
||||
pszAccess = "rb";
|
||||
|
||||
if( strcmp(pszAccess,"r+") == 0 )
|
||||
if( strncmp(pszAccess,"r+", 3) == 0 )
|
||||
pszAccess = "rb+";
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/* Compute the base (layer) name. If there is any extension */
|
||||
/* on the passed in filename we will strip it off. */
|
||||
/* -------------------------------------------------------------------- */
|
||||
pszBasename = (char *) malloc(strlen(pszFilename)+5);
|
||||
strcpy( pszBasename, pszFilename );
|
||||
for( i = strlen(pszBasename)-1;
|
||||
pszBasename = (char *) malloc(strnlen(pszFilename, 127)+5);
|
||||
strncpy( pszBasename, pszFilename, malloc_usable_size(pszBasename));
|
||||
for( i = strnlen(pszBasename, malloc_usable_size(pszBasename)-1)-1;
|
||||
i > 0 && pszBasename[i] != '.' && pszBasename[i] != '/'
|
||||
&& pszBasename[i] != '\\';
|
||||
i-- ) {}
|
||||
@ -418,8 +418,8 @@ DBFOpenLL( const char * pszFilename, const char * pszAccess, SAHooks *psHooks )
|
||||
if( pszBasename[i] == '.' )
|
||||
pszBasename[i] = '\0';
|
||||
|
||||
pszFullname = (char *) malloc(strlen(pszBasename) + 5);
|
||||
sprintf( pszFullname, "%s.dbf", pszBasename );
|
||||
pszFullname = (char *) malloc(strnlen(pszBasename, 128) + 5);
|
||||
snprintf( pszFullname, malloc_usable_size(pszFullname), "%s.dbf", pszBasename );
|
||||
|
||||
psDBF = (DBFHandle) calloc( 1, sizeof(DBFInfo) );
|
||||
psDBF->fp = psHooks->FOpen( pszFullname, pszAccess );
|
||||
@ -427,15 +427,15 @@ DBFOpenLL( const char * pszFilename, const char * pszAccess, SAHooks *psHooks )
|
||||
|
||||
if( psDBF->fp == NULL )
|
||||
{
|
||||
sprintf( pszFullname, "%s.DBF", pszBasename );
|
||||
snprintf( pszFullname, malloc_usable_size(pszFullname),"%s.DBF", pszBasename );
|
||||
psDBF->fp = psDBF->sHooks.FOpen(pszFullname, pszAccess );
|
||||
}
|
||||
|
||||
sprintf( pszFullname, "%s.cpg", pszBasename );
|
||||
snprintf( pszFullname, malloc_usable_size(pszFullname),"%s.cpg", pszBasename );
|
||||
pfCPG = psHooks->FOpen( pszFullname, "r" );
|
||||
if( pfCPG == NULL )
|
||||
{
|
||||
sprintf( pszFullname, "%s.CPG", pszBasename );
|
||||
snprintf( pszFullname, malloc_usable_size(pszFullname),"%s.CPG", pszBasename );
|
||||
pfCPG = psHooks->FOpen( pszFullname, "r" );
|
||||
}
|
||||
|
||||
@ -501,15 +501,15 @@ DBFOpenLL( const char * pszFilename, const char * pszAccess, SAHooks *psHooks )
|
||||
{
|
||||
pabyBuf[n] = '\0';
|
||||
psDBF->pszCodePage = (char *) malloc(n + 1);
|
||||
memcpy( psDBF->pszCodePage, pabyBuf, n + 1 );
|
||||
memncpy( psDBF->pszCodePage, pabyBuf, n + 1, n );
|
||||
}
|
||||
psDBF->sHooks.FClose( pfCPG );
|
||||
}
|
||||
if( psDBF->pszCodePage == NULL && pabyBuf[29] != 0 )
|
||||
{
|
||||
sprintf( (char *) pabyBuf, "LDID/%d", psDBF->iLanguageDriver );
|
||||
psDBF->pszCodePage = (char *) malloc(strlen((char*)pabyBuf) + 1);
|
||||
strcpy( psDBF->pszCodePage, (char *) pabyBuf );
|
||||
snprintf( (char *) pabyBuf, malloc_usable_size(pabyBuf)-1, "LDID/%d", psDBF->iLanguageDriver );
|
||||
psDBF->pszCodePage = (char *) malloc(strnlen((char*)pabyBuf, malloc_usable_size(pabyBuf)-1) + 1);
|
||||
strncpy( psDBF->pszCodePage, (char *) pabyBuf , malloc_usable_size(psDBF->pszCodePage)-1);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
@ -669,9 +669,9 @@ DBFCreateLL( const char * pszFilename, const char * pszCodePage, SAHooks *psHook
|
||||
/* Compute the base (layer) name. If there is any extension */
|
||||
/* on the passed in filename we will strip it off. */
|
||||
/* -------------------------------------------------------------------- */
|
||||
pszBasename = (char *) malloc(strlen(pszFilename)+5);
|
||||
strcpy( pszBasename, pszFilename );
|
||||
for( i = strlen(pszBasename)-1;
|
||||
pszBasename = (char *) malloc(strnlen(pszFilename, 127)+5);
|
||||
strncpy( pszBasename, pszFilename, malloc_usable_size(pszBasename) );
|
||||
for( i = strnlen(pszBasename, malloc_usable_size(pszBasename)-1)-1;
|
||||
i > 0 && pszBasename[i] != '.' && pszBasename[i] != '/'
|
||||
&& pszBasename[i] != '\\';
|
||||
i-- ) {}
|
||||
@ -679,8 +679,8 @@ DBFCreateLL( const char * pszFilename, const char * pszCodePage, SAHooks *psHook
|
||||
if( pszBasename[i] == '.' )
|
||||
pszBasename[i] = '\0';
|
||||
|
||||
pszFullname = (char *) malloc(strlen(pszBasename) + 5);
|
||||
sprintf( pszFullname, "%s.dbf", pszBasename );
|
||||
pszFullname = (char *) malloc(strnlen(pszBasename, malloc_usable_size(pszBasename)-1) + 5);
|
||||
snprintf( pszFullname, malloc_usable_size(pszFullname), "%s.dbf", pszBasename );
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/* Create the file. */
|
||||
@ -705,7 +705,7 @@ DBFCreateLL( const char * pszFilename, const char * pszCodePage, SAHooks *psHook
|
||||
}
|
||||
|
||||
|
||||
sprintf( pszFullname, "%s.cpg", pszBasename );
|
||||
snprintf( pszFullname, malloc_usable_size(pszFullname), "%s.cpg", pszBasename );
|
||||
if( pszCodePage != NULL )
|
||||
{
|
||||
if( strncmp( pszCodePage, "LDID/", 5 ) == 0 )
|
||||
@ -717,7 +717,7 @@ DBFCreateLL( const char * pszFilename, const char * pszCodePage, SAHooks *psHook
|
||||
if( ldid < 0 )
|
||||
{
|
||||
SAFile fpCPG = psHooks->FOpen( pszFullname, "w" );
|
||||
psHooks->FWrite( (char*) pszCodePage, strlen(pszCodePage), 1, fpCPG );
|
||||
psHooks->FWrite( (char*) pszCodePage, strnlen(pszCodePage, 127), 1, fpCPG );
|
||||
psHooks->FClose( fpCPG );
|
||||
}
|
||||
}
|
||||
@ -757,8 +757,8 @@ DBFCreateLL( const char * pszFilename, const char * pszCodePage, SAHooks *psHook
|
||||
psDBF->pszCodePage = NULL;
|
||||
if( pszCodePage )
|
||||
{
|
||||
psDBF->pszCodePage = (char * ) malloc( strlen(pszCodePage) + 1 );
|
||||
strcpy( psDBF->pszCodePage, pszCodePage );
|
||||
psDBF->pszCodePage = (char * ) malloc( strnlen(pszCodePage, 127) + 1 );
|
||||
strncpy( psDBF->pszCodePage, pszCodePage, malloc_usable_size(psDBF->pszCodePage));
|
||||
}
|
||||
|
||||
return( psDBF );
|
||||
@ -883,8 +883,8 @@ DBFAddNativeFieldType(DBFHandle psDBF, const char * pszFieldName,
|
||||
for( i = 0; i < 32; i++ )
|
||||
pszFInfo[i] = '\0';
|
||||
|
||||
if( (int) strlen(pszFieldName) < 10 )
|
||||
strncpy( pszFInfo, pszFieldName, strlen(pszFieldName));
|
||||
if( (int) strnlen(pszFieldName, 10) < 10 )
|
||||
strncpy( pszFInfo, pszFieldName, strnlen(pszFieldName, 10));
|
||||
else
|
||||
strncpy( pszFInfo, pszFieldName, 10);
|
||||
|
||||
@ -1147,7 +1147,7 @@ static int DBFIsValueNULL( char chType, const char* pszValue )
|
||||
|
||||
default:
|
||||
/* empty string fields are considered NULL */
|
||||
return strlen(pszValue) == 0;
|
||||
return strnlen(pszValue, 2) == 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1325,16 +1325,16 @@ static int DBFWriteAttribute(DBFHandle psDBF, int hEntity, int iField,
|
||||
if( (int) sizeof(szSField)-2 < nWidth )
|
||||
nWidth = sizeof(szSField)-2;
|
||||
|
||||
sprintf( szFormat, "%%%dd", nWidth );
|
||||
sprintf(szSField, szFormat, (int) *((double *) pValue) );
|
||||
if( (int)strlen(szSField) > psDBF->panFieldSize[iField] )
|
||||
snprintf( szFormat, sizeof(szFormat) -1, "%%%dd", nWidth );
|
||||
snprintf(szSField, sizeof(szSField) - 1, szFormat, (int) *((double *) pValue) );
|
||||
if( (int)strnlen(szSField, sizeof(szSField) - 1) > psDBF->panFieldSize[iField] )
|
||||
{
|
||||
szSField[psDBF->panFieldSize[iField]] = '\0';
|
||||
nRetResult = FALSE;
|
||||
}
|
||||
|
||||
strncpy((char *) (pabyRec+psDBF->panFieldOffset[iField]),
|
||||
szSField, strlen(szSField) );
|
||||
szSField, sizeof(szSField) -1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1343,16 +1343,16 @@ static int DBFWriteAttribute(DBFHandle psDBF, int hEntity, int iField,
|
||||
if( (int) sizeof(szSField)-2 < nWidth )
|
||||
nWidth = sizeof(szSField)-2;
|
||||
|
||||
sprintf( szFormat, "%%%d.%df",
|
||||
nWidth, psDBF->panFieldDecimals[iField] );
|
||||
sprintf(szSField, szFormat, *((double *) pValue) );
|
||||
if( (int) strlen(szSField) > psDBF->panFieldSize[iField] )
|
||||
snprintf( szFormat, nWidth, "%%%d.%df",
|
||||
psDBF->panFieldDecimals[iField] );
|
||||
snprintf(szSField, sizeof(szSField)-1, szFormat, *((double *) pValue) );
|
||||
if( (int) strnlen(szSField, sizeof(szSField)-1) > psDBF->panFieldSize[iField] )
|
||||
{
|
||||
szSField[psDBF->panFieldSize[iField]] = '\0';
|
||||
nRetResult = FALSE;
|
||||
}
|
||||
strncpy((char *) (pabyRec+psDBF->panFieldOffset[iField]),
|
||||
szSField, strlen(szSField) );
|
||||
szSField, sizeof(szSField) -1 );
|
||||
}
|
||||
break;
|
||||
|
||||
@ -1363,7 +1363,7 @@ static int DBFWriteAttribute(DBFHandle psDBF, int hEntity, int iField,
|
||||
break;
|
||||
|
||||
default:
|
||||
if( (int) strlen((char *) pValue) > psDBF->panFieldSize[iField] )
|
||||
if( (int) strnlen((char *) pValue, 128) > psDBF->panFieldSize[iField] )
|
||||
{
|
||||
j = psDBF->panFieldSize[iField];
|
||||
nRetResult = FALSE;
|
||||
@ -1372,7 +1372,7 @@ static int DBFWriteAttribute(DBFHandle psDBF, int hEntity, int iField,
|
||||
{
|
||||
memset( pabyRec+psDBF->panFieldOffset[iField], ' ',
|
||||
psDBF->panFieldSize[iField] );
|
||||
j = strlen((char *) pValue);
|
||||
j = strnlen((char *) pValue, 128);
|
||||
}
|
||||
|
||||
strncpy((char *) (pabyRec+psDBF->panFieldOffset[iField]),
|
||||
@ -1435,13 +1435,13 @@ DBFWriteAttributeDirectly(DBFHandle psDBF, int hEntity, int iField,
|
||||
/* -------------------------------------------------------------------- */
|
||||
/* Assign all the record fields. */
|
||||
/* -------------------------------------------------------------------- */
|
||||
if( (int)strlen((char *) pValue) > psDBF->panFieldSize[iField] )
|
||||
if( (int)strnlen((char *) pValue, 128) > psDBF->panFieldSize[iField] )
|
||||
j = psDBF->panFieldSize[iField];
|
||||
else
|
||||
{
|
||||
memset( pabyRec+psDBF->panFieldOffset[iField], ' ',
|
||||
psDBF->panFieldSize[iField] );
|
||||
j = strlen((char *) pValue);
|
||||
j = strnlen((char *) pValue, 128);
|
||||
}
|
||||
|
||||
strncpy((char *) (pabyRec+psDBF->panFieldOffset[iField]),
|
||||
@ -1664,16 +1664,15 @@ DBFGetNativeFieldType( DBFHandle psDBF, int iField )
|
||||
/* str_to_upper() */
|
||||
/************************************************************************/
|
||||
|
||||
static void str_to_upper (char *string)
|
||||
static void str_to_upper (char *str, int n)
|
||||
{
|
||||
int len;
|
||||
short i = -1;
|
||||
int i = -1;
|
||||
|
||||
len = strlen (string);
|
||||
int len = strnlen (str, n);
|
||||
|
||||
while (++i < len)
|
||||
if (isalpha(string[i]) && islower(string[i]))
|
||||
string[i] = (char) toupper ((int)string[i]);
|
||||
if (isalpha(str[i]) && islower(str[i]))
|
||||
str[i] = (char) toupper ((int)str[i]);
|
||||
}
|
||||
|
||||
/************************************************************************/
|
||||
@ -1693,13 +1692,13 @@ DBFGetFieldIndex(DBFHandle psDBF, const char *pszFieldName)
|
||||
|
||||
strncpy(name1, pszFieldName,11);
|
||||
name1[11] = '\0';
|
||||
str_to_upper(name1);
|
||||
str_to_upper(name1, 11);
|
||||
|
||||
for( i = 0; i < DBFGetFieldCount(psDBF); i++ )
|
||||
{
|
||||
DBFGetFieldInfo( psDBF, i, name, NULL, NULL );
|
||||
strncpy(name2,name,11);
|
||||
str_to_upper(name2);
|
||||
str_to_upper(name2, 11);
|
||||
|
||||
if(!strncmp(name1,name2,10))
|
||||
return(i);
|
||||
@ -2077,8 +2076,8 @@ DBFAlterFieldDefn( DBFHandle psDBF, int iField, const char * pszFieldName,
|
||||
for( i = 0; i < 32; i++ )
|
||||
pszFInfo[i] = '\0';
|
||||
|
||||
if( (int) strlen(pszFieldName) < 10 )
|
||||
strncpy( pszFInfo, pszFieldName, strlen(pszFieldName));
|
||||
if( (int) strnlen(pszFieldName, 127) < 10 )
|
||||
strncpy( pszFInfo, pszFieldName, strnlen(pszFieldName, 127));
|
||||
else
|
||||
strncpy( pszFInfo, pszFieldName, 10);
|
||||
|
||||
|
@ -272,6 +272,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <malloc.h>
|
||||
|
||||
SHP_CVSID("$Id: shpopen.c,v 1.73 2012-01-24 22:33:01 fwarmerdam Exp $")
|
||||
|
||||
@ -504,8 +505,8 @@ SHPOpenLL( const char * pszLayer, const char * pszAccess, SAHooks *psHooks )
|
||||
/* ensure the result string indicates binary to avoid common */
|
||||
/* problems on Windows. */
|
||||
/* -------------------------------------------------------------------- */
|
||||
if( strcmp(pszAccess,"rb+") == 0 || strcmp(pszAccess,"r+b") == 0
|
||||
|| strcmp(pszAccess,"r+") == 0 )
|
||||
if( strncmp(pszAccess,"rb+", 4) == 0 || strncmp(pszAccess,"r+b", 4) == 0
|
||||
|| strncmp(pszAccess,"r+", 4) == 0 )
|
||||
pszAccess = "r+b";
|
||||
else
|
||||
pszAccess = "rb";
|
||||
@ -531,9 +532,9 @@ SHPOpenLL( const char * pszLayer, const char * pszAccess, SAHooks *psHooks )
|
||||
/* Compute the base (layer) name. If there is any extension */
|
||||
/* on the passed in filename we will strip it off. */
|
||||
/* -------------------------------------------------------------------- */
|
||||
pszBasename = (char *) malloc(strlen(pszLayer)+5);
|
||||
strcpy( pszBasename, pszLayer );
|
||||
for( i = strlen(pszBasename)-1;
|
||||
pszBasename = (char *) malloc(strnlen(pszLayer, 128)+5);
|
||||
strncpy( pszBasename, pszLayer, malloc_usable_size(pszBasename) -1 );
|
||||
for( i = strnlen(pszBasename, malloc_usable_size(pszBasename) -1)-1;
|
||||
i > 0 && pszBasename[i] != '.' && pszBasename[i] != '/'
|
||||
&& pszBasename[i] != '\\';
|
||||
i-- ) {}
|
||||
@ -545,19 +546,19 @@ SHPOpenLL( const char * pszLayer, const char * pszAccess, SAHooks *psHooks )
|
||||
/* Open the .shp and .shx files. Note that files pulled from */
|
||||
/* a PC to Unix with upper case filenames won't work! */
|
||||
/* -------------------------------------------------------------------- */
|
||||
pszFullname = (char *) malloc(strlen(pszBasename) + 5);
|
||||
sprintf( pszFullname, "%s.shp", pszBasename ) ;
|
||||
pszFullname = (char *) malloc(strnlen(pszBasename, 128) + 5);
|
||||
snprintf( pszFullname, malloc_usable_size(pszFullname)-1, "%s.shp", pszBasename ) ;
|
||||
psSHP->fpSHP = psSHP->sHooks.FOpen(pszFullname, pszAccess );
|
||||
if( psSHP->fpSHP == NULL )
|
||||
{
|
||||
sprintf( pszFullname, "%s.SHP", pszBasename );
|
||||
snprintf( pszFullname, malloc_usable_size(pszFullname)-1,"%s.SHP", pszBasename );
|
||||
psSHP->fpSHP = psSHP->sHooks.FOpen(pszFullname, pszAccess );
|
||||
}
|
||||
|
||||
if( psSHP->fpSHP == NULL )
|
||||
{
|
||||
char *pszMessage = (char *) malloc(strlen(pszBasename)*2+256);
|
||||
sprintf( pszMessage, "Unable to open %s.shp or %s.SHP.",
|
||||
char *pszMessage = (char *) malloc(strnlen(pszBasename, malloc_usable_size(pszFullname)-1)*2+256);
|
||||
snprintf( pszMessage, malloc_usable_size(pszMessage)-1,"Unable to open %s.shp or %s.SHP.",
|
||||
pszBasename, pszBasename );
|
||||
psHooks->Error( pszMessage );
|
||||
free( pszMessage );
|
||||
@ -569,18 +570,18 @@ SHPOpenLL( const char * pszLayer, const char * pszAccess, SAHooks *psHooks )
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sprintf( pszFullname, "%s.shx", pszBasename );
|
||||
snprintf( pszFullname, malloc_usable_size(pszFullname)-1,"%s.shx", pszBasename );
|
||||
psSHP->fpSHX = psSHP->sHooks.FOpen(pszFullname, pszAccess );
|
||||
if( psSHP->fpSHX == NULL )
|
||||
{
|
||||
sprintf( pszFullname, "%s.SHX", pszBasename );
|
||||
snprintf( pszFullname, malloc_usable_size(pszFullname)-1,"%s.SHX", pszBasename );
|
||||
psSHP->fpSHX = psSHP->sHooks.FOpen(pszFullname, pszAccess );
|
||||
}
|
||||
|
||||
if( psSHP->fpSHX == NULL )
|
||||
{
|
||||
char *pszMessage = (char *) malloc(strlen(pszBasename)*2+256);
|
||||
sprintf( pszMessage, "Unable to open %s.shx or %s.SHX.",
|
||||
char *pszMessage = (char *) malloc(strnlen(pszBasename, malloc_usable_size(pszBasename)-1)*2+256);
|
||||
snprintf( pszMessage,malloc_usable_size(pszMessage)-1, "Unable to open %s.shx or %s.SHX.",
|
||||
pszBasename, pszBasename );
|
||||
psHooks->Error( pszMessage );
|
||||
free( pszMessage );
|
||||
@ -633,7 +634,7 @@ SHPOpenLL( const char * pszLayer, const char * pszAccess, SAHooks *psHooks )
|
||||
{
|
||||
char szError[200];
|
||||
|
||||
sprintf( szError,
|
||||
snprintf( szError, sizeof(szError) -1,
|
||||
"Record count in .shp header is %d, which seems\n"
|
||||
"unreasonable. Assuming header is corrupt.",
|
||||
psSHP->nRecords );
|
||||
@ -701,7 +702,7 @@ SHPOpenLL( const char * pszLayer, const char * pszAccess, SAHooks *psHooks )
|
||||
{
|
||||
char szError[200];
|
||||
|
||||
sprintf(szError,
|
||||
snprintf(szError, sizeof(szError) -1,
|
||||
"Not enough memory to allocate requested memory (nRecords=%d).\n"
|
||||
"Probably broken SHP file",
|
||||
psSHP->nRecords );
|
||||
@ -720,7 +721,7 @@ SHPOpenLL( const char * pszLayer, const char * pszAccess, SAHooks *psHooks )
|
||||
{
|
||||
char szError[200];
|
||||
|
||||
sprintf( szError,
|
||||
snprintf( szError, sizeof(szError)-1,
|
||||
"Failed to read all values for %d records in .shx file.",
|
||||
psSHP->nRecords );
|
||||
psSHP->sHooks.Error( szError );
|
||||
@ -737,7 +738,7 @@ SHPOpenLL( const char * pszLayer, const char * pszAccess, SAHooks *psHooks )
|
||||
}
|
||||
|
||||
/* In read-only mode, we can close the SHX now */
|
||||
if (strcmp(pszAccess, "rb") == 0)
|
||||
if (strncmp(pszAccess, "rb", 3) == 0)
|
||||
{
|
||||
psSHP->sHooks.FClose( psSHP->fpSHX );
|
||||
psSHP->fpSHX = NULL;
|
||||
@ -878,9 +879,9 @@ SHPCreateLL( const char * pszLayer, int nShapeType, SAHooks *psHooks )
|
||||
/* Compute the base (layer) name. If there is any extension */
|
||||
/* on the passed in filename we will strip it off. */
|
||||
/* -------------------------------------------------------------------- */
|
||||
pszBasename = (char *) malloc(strlen(pszLayer)+5);
|
||||
strcpy( pszBasename, pszLayer );
|
||||
for( i = strlen(pszBasename)-1;
|
||||
pszBasename = (char *) malloc(strnlen(pszLayer, 128)+5);
|
||||
strncpy( pszBasename, pszLayer,malloc_usable_size(pszBasename) -1 );
|
||||
for( i = strnlen(pszBasename, malloc_usable_size(pszFullname)-1)-1;
|
||||
i > 0 && pszBasename[i] != '.' && pszBasename[i] != '/'
|
||||
&& pszBasename[i] != '\\';
|
||||
i-- ) {}
|
||||
@ -891,8 +892,8 @@ SHPCreateLL( const char * pszLayer, int nShapeType, SAHooks *psHooks )
|
||||
/* -------------------------------------------------------------------- */
|
||||
/* Open the two files so we can write their headers. */
|
||||
/* -------------------------------------------------------------------- */
|
||||
pszFullname = (char *) malloc(strlen(pszBasename) + 5);
|
||||
sprintf( pszFullname, "%s.shp", pszBasename );
|
||||
pszFullname = (char *) malloc(strnlen(pszBasename, malloc_usable_size(pszBasename)-1) + 5);
|
||||
snprintf( pszFullname, malloc_usable_size(pszFullname)-1, "%s.shp", pszBasename );
|
||||
fpSHP = psHooks->FOpen(pszFullname, "wb" );
|
||||
if( fpSHP == NULL )
|
||||
{
|
||||
@ -900,7 +901,7 @@ SHPCreateLL( const char * pszLayer, int nShapeType, SAHooks *psHooks )
|
||||
goto error;
|
||||
}
|
||||
|
||||
sprintf( pszFullname, "%s.shx", pszBasename );
|
||||
snprintf( pszFullname, malloc_usable_size(pszFullname)-1, "%s.shx", pszBasename );
|
||||
fpSHX = psHooks->FOpen(pszFullname, "wb" );
|
||||
if( fpSHX == NULL )
|
||||
{
|
||||
@ -1471,7 +1472,7 @@ SHPWriteObject(SHPHandle psSHP, int nShapeId, SHPObject * psObject )
|
||||
if( nExpectedSize < psSHP->nFileSize ) // due to unsigned int overflow
|
||||
{
|
||||
char str[128];
|
||||
sprintf( str, "Failed to write shape object. "
|
||||
snprintf( str, sizeof(str)-1, "Failed to write shape object. "
|
||||
"File size cannot reach %u + %u.",
|
||||
psSHP->nFileSize, nRecordSize );
|
||||
psSHP->sHooks.Error( str );
|
||||
@ -1599,7 +1600,7 @@ SHPReadObject( SHPHandle psSHP, int hEntity )
|
||||
/* Reallocate previous successful size for following features */
|
||||
psSHP->pabyRec = (uchar *) malloc(psSHP->nBufSize);
|
||||
|
||||
sprintf( szError,
|
||||
snprintf( szError, sizeof(szError)-1,
|
||||
"Not enough memory to allocate requested memory (nBufSize=%d). "
|
||||
"Probably broken SHP file", psSHP->nBufSize );
|
||||
psSHP->sHooks.Error( szError );
|
||||
@ -1626,7 +1627,7 @@ SHPReadObject( SHPHandle psSHP, int hEntity )
|
||||
* for example to detect if file is truncated.
|
||||
*/
|
||||
char str[128];
|
||||
sprintf( str,
|
||||
snprintf( str, sizeof(str) -1,
|
||||
"Error in fseek() reading object from .shp file at offset %u",
|
||||
psSHP->panRecOffset[hEntity]);
|
||||
|
||||
@ -1641,7 +1642,7 @@ SHPReadObject( SHPHandle psSHP, int hEntity )
|
||||
* for example to detect if file is truncated.
|
||||
*/
|
||||
char str[128];
|
||||
sprintf( str,
|
||||
snprintf( str, sizeof(str)-1,
|
||||
"Error in fread() reading object of size %u at offset %u from .shp file",
|
||||
nEntitySize, psSHP->panRecOffset[hEntity] );
|
||||
|
||||
|
@ -300,15 +300,15 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
|
||||
for (i=1; i<argc; ++i) {
|
||||
if (!strcmp(argv[i], "-n")) {
|
||||
if (!strncmp(argv[i], "-n", 3)) {
|
||||
++i;
|
||||
nodes = atoi(argv[i]);
|
||||
}
|
||||
else if (!strcmp(argv[i], "-a")) {
|
||||
else if (!strncmp(argv[i], "-a", 3)) {
|
||||
++i;
|
||||
author = argv[i];
|
||||
}
|
||||
else if (!strcmp(argv[i], "-l")) {
|
||||
else if (!strncmp(argv[i], "-l", 3)) {
|
||||
++i;
|
||||
letterSpacing = atof(argv[i]);
|
||||
}
|
||||
@ -316,7 +316,7 @@ int main(int argc, char* argv[]) {
|
||||
++i;
|
||||
wordSpacing = atof(argv[i]);
|
||||
}
|
||||
else if (!strcmp(argv[i], "-d")) {
|
||||
else if (!strncmp(argv[i], "-d", 3)) {
|
||||
++i;
|
||||
precision = atoi(argv[i]);
|
||||
}
|
||||
@ -324,11 +324,11 @@ int main(int argc, char* argv[]) {
|
||||
++i;
|
||||
lineSpacingFactor = atof(argv[i]);
|
||||
}
|
||||
else if (!strcmp(argv[i], "-h")) {
|
||||
else if (!strncmp(argv[i], "-h", 3)) {
|
||||
usage(0);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
else if (!strcmp(argv[i], "-L")) {
|
||||
else if (!strncmp(argv[i], "-L", 3)) {
|
||||
++i;
|
||||
license = argv[i];
|
||||
}
|
||||
|
Reference in New Issue
Block a user