Commit 90e53f0c authored by Michael Meskes's avatar Michael Meskes

Fixed potentially uninitialized memory bug in compatlib.

parent 0637d52d
...@@ -1705,6 +1705,10 @@ Thu Oct 30 11:12:37 CET 2003 ...@@ -1705,6 +1705,10 @@ Thu Oct 30 11:12:37 CET 2003
Fri Oct 31 15:09:22 CET 2003 Fri Oct 31 15:09:22 CET 2003
- If EOF is found inside a string/comment/etc. stop parsing. - If EOF is found inside a string/comment/etc. stop parsing.
Mon Nov 3 15:43:19 CET 2003
- Fixed a potentially uncleared allocation in compatlib.
- Set ecpg version to 3.0.0 - Set ecpg version to 3.0.0
- Set ecpg library to 4.0.0 - Set ecpg library to 4.0.0
- Set pgtypes library to 1.0.0 - Set pgtypes library to 1.0.0
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <errno.h> #include <errno.h>
#include <math.h> #include <math.h>
#include <ctype.h> #include <ctype.h>
#include <limits.h>
#include <ecpgtype.h> #include <ecpgtype.h>
#include <compatlib.h> #include <compatlib.h>
...@@ -11,7 +12,7 @@ ...@@ -11,7 +12,7 @@
#include <pgtypes_numeric.h> #include <pgtypes_numeric.h>
#include <sqltypes.h> #include <sqltypes.h>
char *ECPGalloc(long, int); char *ECPGalloc(long, int);
static int static int
deccall2(decimal * arg1, decimal * arg2, int (*ptr) (numeric *, numeric *)) deccall2(decimal * arg1, decimal * arg2, int (*ptr) (numeric *, numeric *))
...@@ -659,41 +660,50 @@ static struct ...@@ -659,41 +660,50 @@ static struct
} value; } value;
/** /**
* initialize the struct, wich holds the different forms * initialize the struct, which holds the different forms
* of the long value * of the long value
*/ */
static void static void
initValue(long lng_val) initValue (long lng_val)
{ {
int i, int i, j;
div, long l, dig;
dig;
char tmp[2] = " "; /* set some obvious things */
value.val = lng_val >= 0 ? lng_val : lng_val * (-1);
/* set some obvious things */ value.sign = lng_val >= 0 ? '+' : '-';
value.val = lng_val >= 0 ? lng_val : lng_val * (-1); value.maxdigits = log10 (2) * (8 * sizeof (long) - 1);
value.sign = lng_val >= 0 ? '+' : '-';
value.maxdigits = log10(2) * (8 * sizeof(long) - 1); /* determine the number of digits */
i = 0;
/* determine the number of digits */ l = 1;
for (i = 0; i <= value.maxdigits; i++) do
{ {
if ((int) (value.val / pow(10, i)) != 0) i++;
value.digits = i + 1; l *= 10;
} }
value.remaining = value.digits; while ((l - 1) < value.val && l <= LONG_MAX / 10);
/* convert the long to string */ if (l <= LONG_MAX/10)
value.val_string = (char *) malloc(value.digits + 1); {
for (i = value.digits; i > 0; i--) value.digits = i;
{ l /= 10;
div = pow(10, i); }
dig = (value.val % div) / (div / 10); else
tmp[0] = (char) (dig + 48); value.digits = i + 1;
strcat(value.val_string, tmp);
} value.remaining = value.digits;
/* safety-net */
value.val_string[value.digits] = '\0'; /* convert the long to string */
value.val_string = (char *) malloc (value.digits + 1);
dig = value.val;
for (i = value.digits, j = 0; i > 0; i--, j++)
{
value.val_string[j] = dig/l + '0';
dig = dig % l;
l /= 10;
}
value.val_string[value.digits] = '\0';
} }
/* return the position oft the right-most dot in some string */ /* return the position oft the right-most dot in some string */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment