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>
...@@ -659,40 +660,49 @@ static struct ...@@ -659,40 +660,49 @@ 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 */ /* set some obvious things */
value.val = lng_val >= 0 ? lng_val : lng_val * (-1); value.val = lng_val >= 0 ? lng_val : lng_val * (-1);
value.sign = lng_val >= 0 ? '+' : '-'; value.sign = lng_val >= 0 ? '+' : '-';
value.maxdigits = log10(2) * (8 * sizeof(long) - 1); value.maxdigits = log10 (2) * (8 * sizeof (long) - 1);
/* determine the number of digits */ /* determine the number of digits */
for (i = 0; i <= value.maxdigits; i++) i = 0;
l = 1;
do
{ {
if ((int) (value.val / pow(10, i)) != 0) i++;
value.digits = i + 1; l *= 10;
}
while ((l - 1) < value.val && l <= LONG_MAX / 10);
if (l <= LONG_MAX/10)
{
value.digits = i;
l /= 10;
} }
else
value.digits = i + 1;
value.remaining = value.digits; value.remaining = value.digits;
/* convert the long to string */ /* convert the long to string */
value.val_string = (char *) malloc(value.digits + 1); value.val_string = (char *) malloc (value.digits + 1);
for (i = value.digits; i > 0; i--) dig = value.val;
for (i = value.digits, j = 0; i > 0; i--, j++)
{ {
div = pow(10, i); value.val_string[j] = dig/l + '0';
dig = (value.val % div) / (div / 10); dig = dig % l;
tmp[0] = (char) (dig + 48); l /= 10;
strcat(value.val_string, tmp);
} }
/* safety-net */
value.val_string[value.digits] = '\0'; value.val_string[value.digits] = '\0';
} }
......
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