Skip to content

Commit 77edcd0

Browse files
committed
Fix compilation warnings with VS 2015
1 parent 89452c5 commit 77edcd0

File tree

1 file changed

+73
-11
lines changed

1 file changed

+73
-11
lines changed

src/njs/src/njsConnection.cpp

Lines changed: 73 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include "njsIntLob.h"
5454
#include <stdlib.h>
5555
#include <iostream>
56+
#include <limits>
5657
using namespace std;
5758

5859
// persistent Connection class handle
@@ -70,6 +71,12 @@ Persistent<FunctionTemplate> Connection::connectionTemplate_s;
7071
// max byte size for a AL32UTF8 char is 4
7172
#define NJS_CHAR_CONVERSION_RATIO 4
7273

74+
#define NJS_SIZE_T_MAX std::numeric_limits<std::size_t>::max()
75+
76+
#define NJS_IS_SIZE_T_OVERFLOW(maxSize,maxRows) \
77+
( ( ( maxSize != 0 ) && \
78+
( ( ( NJS_SIZE_T_MAX ) / ( (size_t)maxSize ) ) < (maxRows) ) ) ? 1 : 0) \
79+
7380
/*****************************************************************************/
7481
/*
7582
DESCRIPTION
@@ -725,7 +732,7 @@ void Connection::GetInBindParams (Handle<Value> v8val, Bind* bind,
725732
bind->maxSize : *(bind->len);
726733
if(size)
727734
{
728-
bind->value = (char*)malloc(size);
735+
bind->value = (char*)malloc((size_t)size);
729736
if(str.length())
730737
memcpy(bind->value, *str, str.length());
731738
}
@@ -1357,8 +1364,16 @@ void Connection::DoDefines ( eBaton* executeBaton, const dpi::MetaData* meta,
13571364
NJS_MAX_FETCH_AS_STRING_SIZE : sizeof (double);
13581365

13591366
defines[col].maxSize = sizeof(double);
1360-
defines[col].buf = (double *)malloc(defines[col].maxSize*
1361-
executeBaton->maxRows);
1367+
1368+
if ( !NJS_IS_SIZE_T_OVERFLOW ( defines[col].maxSize,
1369+
executeBaton->maxRows ) )
1370+
{
1371+
defines[col].buf = (double *)malloc( (size_t)defines[col].maxSize*
1372+
executeBaton->maxRows );
1373+
}
1374+
else
1375+
defines[col].buf = 0;
1376+
13621377
if(!defines[col].buf)
13631378
{
13641379
executeBaton->error = NJSMessages::getErrorMsg(errInsufficientMemory);
@@ -1377,8 +1392,16 @@ void Connection::DoDefines ( eBaton* executeBaton, const dpi::MetaData* meta,
13771392
*/
13781393

13791394
defines[col].maxSize = (meta[col].dbSize) * NJS_CHAR_CONVERSION_RATIO;
1380-
defines[col].buf = (char *)malloc(defines[col].maxSize*
1381-
executeBaton->maxRows);
1395+
1396+
if ( !NJS_IS_SIZE_T_OVERFLOW ( defines[col].maxSize,
1397+
executeBaton->maxRows ) )
1398+
{
1399+
defines[col].buf = (char *)malloc( (size_t)defines[col].maxSize*
1400+
executeBaton->maxRows );
1401+
}
1402+
else
1403+
defines[col].buf = 0;
1404+
13821405
if(!defines[col].buf)
13831406
{
13841407
executeBaton->error = NJSMessages::getErrorMsg(errInsufficientMemory);
@@ -1417,8 +1440,16 @@ void Connection::DoDefines ( eBaton* executeBaton, const dpi::MetaData* meta,
14171440
{
14181441
/* Fetching DATE/TIMESTAMP values as VARCHAR */
14191442
defines[col].maxSize = NJS_MAX_FETCH_AS_STRING_SIZE ;
1420-
defines[col].buf = (char *)malloc ( defines[col].maxSize *
1421-
executeBaton->maxRows );
1443+
1444+
if ( !NJS_IS_SIZE_T_OVERFLOW ( defines[col].maxSize,
1445+
executeBaton->maxRows ) )
1446+
{
1447+
defines[col].buf = (char *)malloc( (size_t)defines[col].maxSize*
1448+
executeBaton->maxRows );
1449+
}
1450+
else
1451+
defines[col].buf = 0;
1452+
14221453
if(!defines[col].buf)
14231454
{
14241455
executeBaton->error = NJSMessages::getErrorMsg(
@@ -1433,7 +1464,16 @@ void Connection::DoDefines ( eBaton* executeBaton, const dpi::MetaData* meta,
14331464
case dpi::DpiBfile:
14341465
defines[col].fetchType = meta[col].dbType;
14351466
defines[col].maxSize = sizeof(Descriptor *);
1436-
defines[col].buf = malloc(defines[col].maxSize * executeBaton->maxRows);
1467+
1468+
if ( !NJS_IS_SIZE_T_OVERFLOW ( defines[col].maxSize,
1469+
executeBaton->maxRows ) )
1470+
{
1471+
defines[col].buf = malloc( (size_t)defines[col].maxSize*
1472+
executeBaton->maxRows );
1473+
}
1474+
else
1475+
defines[col].buf = 0;
1476+
14371477
if(!defines[col].buf)
14381478
{
14391479
executeBaton->error = NJSMessages::getErrorMsg(errInsufficientMemory);
@@ -1458,8 +1498,16 @@ void Connection::DoDefines ( eBaton* executeBaton, const dpi::MetaData* meta,
14581498
return;
14591499
}
14601500
defines[col].maxSize = NJS_MAX_FETCH_AS_STRING_SIZE;
1461-
defines[col].buf = (char *)malloc (defines[col].maxSize *
1462-
executeBaton->maxRows );
1501+
1502+
if ( !NJS_IS_SIZE_T_OVERFLOW ( defines[col].maxSize,
1503+
executeBaton->maxRows ) )
1504+
{
1505+
defines[col].buf = (char *)malloc( (size_t)defines[col].maxSize*
1506+
executeBaton->maxRows );
1507+
}
1508+
else
1509+
defines[col].buf = 0;
1510+
14631511
if(!defines[col].buf)
14641512
{
14651513
executeBaton->error = NJSMessages::getErrorMsg(
@@ -2730,7 +2778,21 @@ void Connection::cbDynBufferAllocate ( void *ctx, bool dmlReturning,
27302778
{
27312779
case dpi::DpiVarChar:
27322780
/* one extra char for EOS */
2733-
bind->value = (char *)malloc ( ( bind->maxSize + 1) * nRows ) ;
2781+
2782+
if ( !NJS_IS_SIZE_T_OVERFLOW ( (bind->maxSize + 1), nRows) )
2783+
{
2784+
bind->value = (char *)malloc( (size_t)( bind->maxSize + 1) * nRows );
2785+
}
2786+
else
2787+
bind->value = 0;
2788+
2789+
if( !bind->value )
2790+
{
2791+
executeBaton->error = NJSMessages::getErrorMsg(
2792+
errInsufficientMemory);
2793+
return;
2794+
}
2795+
27342796
if ( dmlReturning )
27352797
{
27362798
*(bind->len2) = (unsigned int)bind->maxSize ;

0 commit comments

Comments
 (0)