Skip to Content.
Sympa Menu

freetds - Re: [freetds] Ongoing work for released version of FreeTDS version0, 64, 0, 6182

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Dann Corbit" <DCorbit AT connx.com>
  • To: "FreeTDS Development Group" <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] Ongoing work for released version of FreeTDS version0, 64, 0, 6182
  • Date: Fri, 18 Jan 2008 11:34:00 -0800

> -----Original Message-----
> From: freetds-bounces AT lists.ibiblio.org [mailto:freetds-
> bounces AT lists.ibiblio.org] On Behalf Of ZIGLIO, Frediano, VF-IT
> Sent: Wednesday, January 16, 2008 1:20 AM
> To: FreeTDS Development Group
> Subject: Re: [freetds] Ongoing work for released version of FreeTDS
> version0, 64, 0, 6182
[snip]
> diff -ub ./convert_tds2sql.c new/convert_tds2sql.c
> --- ./convert_tds2sql.c 2006-02-24 22:14:24.000000000 +0100
> +++ new/convert_tds2sql.c 2008-01-16 09:40:37.938249787 +0100
> @@ -54,6 +54,9 @@
> DATE_STRUCT *dsp;
> TIME_STRUCT *tsp;
> TIMESTAMP_STRUCT *tssp;
> +
> + TIMESTAMP_STRUCT ts;
> +
> SQL_NUMERIC_STRUCT *num;
>
> int ret = TDS_FAIL;
> @@ -140,11 +143,11 @@
>
> tds_datecrack(SYBDATETIME, &(ores.dt), &dr);
>
> - dsp = (DATE_STRUCT *) dest;
> + ts.year = dr.year;
> + ts.month = dr.month + 1;
> + ts.day = dr.day;
>
> - dsp->year = dr.year;
> - dsp->month = dr.month + 1;
> - dsp->day = dr.day;
> + memcpy(dest, &ts, sizeof(DATE_STRUCT));
>
> ret = sizeof(DATE_STRUCT);
> break;
> @@ -157,11 +160,11 @@
>
> tds_datecrack(SYBDATETIME, &(ores.dt), &dr);
>
> - tsp = (TIME_STRUCT *) dest;
> + ts.hour = dr.hour;
> + ts.minute = dr.minute;
> + ts.second = dr.second;
>
> - tsp->hour = dr.hour;
> - tsp->minute = dr.minute;
> - tsp->second = dr.second;
> + memcpy(dest, &ts, sizeof(TIME_STRUCT));
>
> ret = sizeof(TIME_STRUCT);
> break;
> @@ -174,15 +177,15 @@
>
> tds_datecrack(SYBDATETIME, &(ores.dt), &dr);
>
> - tssp = (TIMESTAMP_STRUCT *) dest;
> + ts.year = dr.year;
> + ts.month = dr.month + 1;
> + ts.day = dr.day;
> + ts.hour = dr.hour;
> + ts.minute = dr.minute;
> + ts.second = dr.second;
> + ts.fraction = dr.millisecond * 1000000u;
>
> - tssp->year = dr.year;
> - tssp->month = dr.month + 1;
> - tssp->day = dr.day;
> - tssp->hour = dr.hour;
> - tssp->minute = dr.minute;
> - tssp->second = dr.second;
> - tssp->fraction = dr.millisecond * 1000000u;
> + memcpy(dest, &ts, sizeof(TIMESTAMP_STRUCT));
>
> ret = sizeof(TIMESTAMP_STRUCT);
> break;
> @@ -190,7 +193,7 @@
> #ifdef SQL_C_SBIGINT
> case SQL_C_SBIGINT:
> case SQL_C_UBIGINT:
> - *((TDS_INT8 *) dest) = ores.bi;
> + memcpy(dest, &ores, sizeof(TDS_INT8));
> ret = sizeof(TDS_INT8);
> break;
> #endif
> @@ -198,14 +201,14 @@
> case SQL_C_LONG:
> case SQL_C_SLONG:
> case SQL_C_ULONG:
> - *((TDS_INT *) dest) = ores.i;
> + memcpy(dest, &ores, sizeof(TDS_INT));
> ret = sizeof(TDS_INT);
> break;
>
> case SQL_C_SHORT:
> case SQL_C_SSHORT:
> case SQL_C_USHORT:
> - *((TDS_SMALLINT *) dest) = ores.si;
> + memcpy(dest, &ores, sizeof(TDS_SMALLINT));
> ret = sizeof(TDS_SMALLINT);
> break;
>
> @@ -218,12 +221,12 @@
> break;
>
> case SQL_C_DOUBLE:
> - *((TDS_FLOAT *) dest) = ores.f;
> + memcpy(dest, &ores, sizeof(TDS_FLOAT));
> ret = sizeof(TDS_FLOAT);
> break;
>
> case SQL_C_FLOAT:
> - *((TDS_REAL *) dest) = ores.r;
> + memcpy(dest, &ores, sizeof(TDS_REAL));
> ret = sizeof(TDS_REAL);
> break;
>
>
>
> This code only fixes unaligned binded data. Binded data should be
> aligned so I don't think should be merged. Also code for TIME_STRUCT
> introduce a read of uninitialized data, I don't think is what you
> wanted.

There are no guarantees on the addresses alignments that clients want to
bind to.

Consider:
The client creates a memory buffer with the following properties:
For every field there is a leading character which will be 1 if the
field is null and zero if the field is not null. Every field will also
be stored in the memory buffer using its exact width. Now, suppose that
the first field in the result set is a single character. Then the next
field will start at offset 3. For many CPUs, this will cause a bus
error if the succeeding data is simply assigned to a pointer that wants
alignment to a type and the type does not support character alignment.

The reason that we made the changes above is that we *were* getting bus
errors in running some of our regression tests on some platforms.





Archive powered by MHonArc 2.6.24.

Top of Page